Skip to content

Commit

Permalink
Merge pull request #5153 from mP1/feature/SpreadsheetComparatorNameLi…
Browse files Browse the repository at this point in the history
…st-empty

SpreadsheetComparatorNameList.EMPTY
  • Loading branch information
mP1 committed Sep 21, 2024
2 parents b32445f + ac82ec8 commit ddc4887
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public final class SpreadsheetComparatorNameList extends AbstractList<Spreadshee
implements ImmutableListDefaults<SpreadsheetComparatorNameList, SpreadsheetComparatorName>,
HasText {

/**
* An empty {@link SpreadsheetComparatorNameList}.
*/
public final static SpreadsheetComparatorNameList EMPTY = SpreadsheetComparatorNameList.with(
Lists.empty()
);

/**
* Parses a CSV string of {@link SpreadsheetComparatorName names} into a {@link SpreadsheetComparatorNameList}.
*/
Expand All @@ -57,11 +64,26 @@ public static SpreadsheetComparatorNameList with(final List<SpreadsheetComparato

return names instanceof SpreadsheetComparatorNameList ?
(SpreadsheetComparatorNameList) names :
new SpreadsheetComparatorNameList(
with0(
Lists.immutable(names)
);
}

private static SpreadsheetComparatorNameList with0(final List<SpreadsheetComparatorName> names) {
final SpreadsheetComparatorNameList list;

switch(names.size()) {
case 0:
list = EMPTY;
break;
default:
list = new SpreadsheetComparatorNameList(names);
break;
}

return list;
}

private SpreadsheetComparatorNameList(final List<SpreadsheetComparatorName> names) {
this.names = names;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public void testWithDoesntDoubleWrap() {
);
}

@Test
public void testWithEmpty() {
assertSame(
SpreadsheetComparatorNameList.EMPTY,
SpreadsheetComparatorNameList.with(
Lists.empty()
)
);
}

// list.............................................................................................................

@Test
public void testGet() {
this.getAndCheck(
Expand Down

0 comments on commit ddc4887

Please sign in to comment.