Mental Model: TUI Spreadsheet in Java

Spreadsheets feel mysterious until you stop thinking in grids and start thinking in cell keys + evaluation rules.

The Core Model

This spreadsheet is really two systems:

  1. Storage system: Map<String, String> from cell key to raw content.
  2. Evaluation system: turn raw content into display value.

Raw might be 42 or =A1+B1. Value is what users see.

Why Key-Value Beats 2D Arrays Here

For beginners, sparse storage is easier.

  • Only store cells the user set.
  • A1 is just a normalized string key.
  • No need to pre-create giant tables.

In Java, HashMap is a perfect fit for this mental model.

Formula Thinking

Formula evaluation is a small parser problem.

  • Strip spaces.
  • Split on +.
  • Resolve each token as number or cell reference.
  • Return error markers when invalid.

You’re not building Excel. You’re building one clean rule at a time.

Java-Specific Insight

Java pushes explicit validation, which is good here.

  • normalizeCell protects your storage layer.
  • numberValue isolates conversion logic.
  • evaluate isolates formula rules.

That separation keeps bugs local and fixable.

Debugging Strategy

When output looks wrong, inspect in this order:

  1. normalized cell key
  2. raw stored value
  3. evaluated tokens
  4. final computed result

Most spreadsheet bugs are just one bad step in that chain.

Extension Path

Good next features:

  • subtraction and multiplication
  • circular reference detection
  • CSV import/export

Add one feature, then re-run your model: “store raw, evaluate safely, show value.”