Skip to content

Commit 6bbff4e

Browse files
committed
HasSpreadsheetReference.toSpreadsheetSelection
1 parent 0130b51 commit 6bbff4e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/java/walkingkooka/spreadsheet/reference/HasSpreadsheetReference.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ static <H extends HasSpreadsheetReference<R>, R extends Comparable<R>> Comparato
3232
return (l, r) -> l.reference().compareTo(r.reference());
3333
}
3434

35+
/**
36+
* Helper that attempts to cast the {@link walkingkooka.tree.expression.ExpressionReference} to
37+
* {@link SpreadsheetSelection} if possible or throwing a {@link IllegalArgumentException}.
38+
*/
39+
default SpreadsheetSelection toSpreadsheetSelection() {
40+
final R reference = this.reference();
41+
if(reference instanceof SpreadsheetSelection) {
42+
return (SpreadsheetSelection) reference;
43+
}
44+
45+
throw new IllegalArgumentException("Not a " + SpreadsheetSelection.class.getSimpleName() + ": " + reference);
46+
}
47+
3548
/**
3649
* Returns the reference for the spreadsheet unit.
3750
*/

src/test/java/walkingkooka/spreadsheet/formula/parser/TemplateValueNameSpreadsheetFormulaParserTokenTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,9 @@ public void testReference() {
126126
this.value()
127127
);
128128
}
129+
130+
@Override
131+
public void testPropertiesNeverReturnNull() {
132+
throw new UnsupportedOperationException();
133+
}
129134
}

0 commit comments

Comments
 (0)