Build a simple spreadsheet data model with rows and columns. Each cell can hold text plus style (font, size, bold, italic). Support inserting rows/columns anywhere and getting/setting cell contents deterministically in a single-threaded environment.
Initialization
- At the start, the sheet has 5 rows and 5 columns.
- Both rows and columns are 0-based.
- All cells are initially empty (no text, no style).
Methods
1) void addRow(int index)
- Insert a new empty row at
index
.
Existing rows atindex, index+1, …
shift down by 1. - Validity:
0 ≤ index ≤ currentRows
.
- If
currentRows = 5
,addRow(5)
appends at the end. addRow(0)
makes the former row0
become row1
, etc.
2) void addColumn(int index)
- Insert a new empty column at
index
.
Existing columns atindex, index+1, …
shift right by 1. - Validity:
0 ≤ index ≤ currentCols
.
- If
currentCols = 5
,addColumn(5)
appends at the end. addColumn(2)
makes former col2
become col3
, etc.
3) void addEntry(int row, int column, String text, String fontName, int fontSize, boolean isBold, boolean isItalic)
- Create or replace the entry at
(row, column)
with the given text and style. - Validity:
0 ≤ row < currentRows
and0 ≤ column < currentCols
. - Input constraints:
text
contains no hyphen-
.fontName
will only contain lowercase characters from 'a' to 'z'8 ≤ fontSize ≤ 72
.
4) String getEntry(int row, int column)
- Return the serialized content+style for the cell at
(row, column)
. - Format:
text-fontName-fontSize[-b][-i]
- Include
-b
only ifisBold = true
. - Include
-i
only ifisItalic = true
.
- Include
- Examples:
- "some text example-tahoma-24-b"
- "another text example-algerian-14-i"
- "what are you waiting for-calibri-28-b-i"
- "another day another dawn-pixar-21"
- Empty cell: return
""
. - Validity:
0 ≤ row < currentRows
,0 ≤ column < currentCols
.
Examples
Assume initial state is a 5×5 empty sheet (rows = 5, cols = 5).
- Insert a row at the end and add an entry
addRow(5)
→ rows become6
(new row index5
, all empty).addEntry(5, 0, "hello", "tahoma", 24, true, false)
getEntry(5, 0)
→"hello-tahoma-24-b"
- Insert a column in the middle and verify shifting
addColumn(2)
→ cols become6
(new empty column at index2
).addEntry(0, 1, "x", "calibri", 10, false, true)
getEntry(0, 1)
→"x-calibri-10-i"
- After
addColumn(1)
, the prior(0,1)
shifts to(0,2)
:getEntry(0, 2)
→"x-calibri-10-i"
getEntry(0, 1)
→""
- Replace existing entry
addEntry(5, 0, "greetings", "tahoma", 24, false, false)
getEntry(5, 0)
→"greetings-tahoma-24"
- Bold/Italic flags
addEntry(1, 3, "note", "algerian", 14, true, true)
getEntry(1, 3)
→"note-algerian-14-b-i"
- Empty cell check
getEntry(2, 2)
→""