When creating an ImmutableTable using a row and/or column comparator, Map views returned by the row and column methods do not use the given comparator to find a row/column by key, and also return ImmutableMaps that do not rely on the specified row/column comparator for finding entries. This is true whether the map is created directly via ImmutableTable.copyOf or ImmutableTable.Builder.
Specifically, it doesn't seem possible to create an ImmutableTable copy of a RowSortedTable crafted to use case-insensitive row and column keys in such a way as to preserve the case-insensitive behaviour in the copy (which works fine in the mutable original).
Test:
@Test
void testImmutableTableWithComparators() {
var testTarget = ImmutableTable.<String, String, String>builder()
.orderRowsBy(String.CASE_INSENSITIVE_ORDER)
.orderColumnsBy(String.CASE_INSENSITIVE_ORDER)
.put("a", "b", "c")
.build();
var rowA = testTarget.row("A");
assertThat("rowA is " + rowA, rowA.containsKey("B"));
}
Result:
java.lang.AssertionError: rowA is {}
Similarly, changing the penultimate line to
var rowA = testTarget.row("a");
leads to
java.lang.AssertionError: rowA is {b=c}
When creating an ImmutableTable using a row and/or column comparator, Map views returned by the row and column methods do not use the given comparator to find a row/column by key, and also return ImmutableMaps that do not rely on the specified row/column comparator for finding entries. This is true whether the map is created directly via ImmutableTable.copyOf or ImmutableTable.Builder.
Specifically, it doesn't seem possible to create an ImmutableTable copy of a RowSortedTable crafted to use case-insensitive row and column keys in such a way as to preserve the case-insensitive behaviour in the copy (which works fine in the mutable original).
Test:
Result:
Similarly, changing the penultimate line to
leads to