修复Table#contains空指针问题

This commit is contained in:
Looly
2023-06-06 22:25:15 +08:00
parent 37ca7779ca
commit 332fd5c346
3 changed files with 13 additions and 1 deletions

View File

@@ -31,7 +31,8 @@ public interface Table<R, C, V> extends Iterable<Table.Cell<R, C, V>> {
* @return 是否包含映射
*/
default boolean contains(R rowKey, C columnKey) {
return Opt.ofNullable(getRow(rowKey)).map((map) -> map.containsKey(columnKey)).get();
return Opt.ofNullable(getRow(rowKey)).map((map) -> map.containsKey(columnKey))
.orElse(false);
}
//region Row

View File

@@ -36,4 +36,14 @@ public class RowKeyTableTest {
Assert.assertEquals(1, column.size());
Assert.assertEquals(new Integer(4), column.get(1));
}
@Test
public void issue3135Test() {
final Table<Integer, Integer, Integer> table = new RowKeyTable<>();
table.put(1, 2, 3);
table.put(1, 6, 4);
Assert.assertNull(table.getRow(2));
Assert.assertFalse(table.contains(2, 3));
}
}