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:
- Storage system:
Map<String, String>from cell key to raw content. - 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.
A1is 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.
normalizeCellprotects your storage layer.numberValueisolates conversion logic.evaluateisolates formula rules.
That separation keeps bugs local and fixable.
Debugging Strategy
When output looks wrong, inspect in this order:
- normalized cell key
- raw stored value
- evaluated tokens
- 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.”