int getLoadedReplicants(SegmentId segmentId, String tier) { Integer retVal = segmentsInCluster.get(segmentId, tier); return (retVal == null) ? 0 : retVal; }
@Override public V2 get(Object rowKey, Object columnKey) { // The function is passed a null input only when the table contains a null // value. return contains(rowKey, columnKey) ? function.apply(fromTable.get(rowKey, columnKey)) : null; }
@Override public V get(Object rowKey, Object columnKey) { return delegate().get(rowKey, columnKey); }
void put(R row, C column, V value, BinaryOperator<V> merger) { MutableCell<R, C, V> oldCell = table.get(row, column); if (oldCell == null) { MutableCell<R, C, V> cell = new MutableCell<>(row, column, value); insertionOrder.add(cell); table.put(row, column, cell); } else { oldCell.merge(value, merger); } }
private static <R, C, V> void merge( Table<R, C, V> table, R row, C column, V value, BinaryOperator<V> mergeFunction) { checkNotNull(value); V oldValue = table.get(row, column); if (oldValue == null) { table.put(row, column, value); } else { V newValue = mergeFunction.apply(oldValue, value); if (newValue == null) { table.remove(row, column); } else { table.put(row, column, newValue); } } }
@Override public V get(Object rowKey, Object columnKey) { assertTrue(Thread.holdsLock(mutex)); return delegate.get(rowKey, columnKey); }
@Override public V get(@Nullable Object rowKey, @Nullable Object columnKey) { return original.get(columnKey, rowKey); }
@Override public V get(@Nullable Object rowKey, @Nullable Object columnKey) { synchronized (mutex) { return delegate().get(rowKey, columnKey); } }
public void testGet() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); assertEquals((Character) 'a', table.get("foo", 1)); assertEquals((Character) 'b', table.get("bar", 1)); assertEquals((Character) 'c', table.get("foo", 3)); assertNull(table.get("foo", 2)); assertNull(table.get("bar", 3)); assertNull(table.get("cat", 1)); assertNull(table.get("foo", null)); assertNull(table.get(null, 1)); assertNull(table.get(null, null)); }
public void testPutAllTable() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Table<String, Integer, Character> other = HashBasedTable.create(); other.put("foo", 1, 'd'); other.put("bar", 2, 'e'); other.put("cat", 2, 'f'); table.putAll(other); assertEquals((Character) 'd', table.get("foo", 1)); assertEquals((Character) 'b', table.get("bar", 1)); assertEquals((Character) 'c', table.get("foo", 3)); assertEquals((Character) 'e', table.get("bar", 2)); assertEquals((Character) 'f', table.get("cat", 2)); assertSize(5); }
public void testCreateWithValidSizes() { Table<String, Integer, Character> table1 = HashBasedTable.create(100, 20); table1.put("foo", 1, 'a'); assertEquals((Character) 'a', table1.get("foo", 1)); Table<String, Integer, Character> table2 = HashBasedTable.create(100, 0); table2.put("foo", 1, 'a'); assertEquals((Character) 'a', table2.get("foo", 1)); Table<String, Integer, Character> table3 = HashBasedTable.create(0, 20); table3.put("foo", 1, 'a'); assertEquals((Character) 'a', table3.get("foo", 1)); Table<String, Integer, Character> table4 = HashBasedTable.create(0, 0); table4.put("foo", 1, 'a'); assertEquals((Character) 'a', table4.get("foo", 1)); }
public void testPut() { assertNull(table.put("foo", 1, 'a')); assertNull(table.put("bar", 1, 'b')); assertNull(table.put("foo", 3, 'c')); assertEquals((Character) 'a', table.put("foo", 1, 'd')); assertEquals((Character) 'd', table.get("foo", 1)); assertEquals((Character) 'b', table.get("bar", 1)); assertSize(3); assertEquals((Character) 'd', table.put("foo", 1, 'd')); assertEquals((Character) 'd', table.get("foo", 1)); assertSize(3); }
public void testPutOriginalModifiesTranspose() { Table<Integer, String, Character> original = HashBasedTable.create(); Table<String, Integer, Character> transpose = Tables.transpose(original); original.put(1, "foo", 'a'); assertEquals((Character) 'a', transpose.get("foo", 1)); }
public void testPutTransposeModifiesOriginal() { Table<Integer, String, Character> original = HashBasedTable.create(); Table<String, Integer, Character> transpose = Tables.transpose(original); transpose.put("foo", 1, 'a'); assertEquals((Character) 'a', original.get(1, "foo")); }
public void testCreateCopyHashBasedTable() { Table<String, Integer, Character> original = HashBasedTable.create(); original.put("foo", 1, 'a'); original.put("bar", 1, 'b'); original.put("foo", 3, 'c'); Table<String, Integer, Character> copy = ArrayTable.create(original); assertEquals(4, copy.size()); assertEquals((Character) 'a', copy.get("foo", 1)); assertEquals((Character) 'b', copy.get("bar", 1)); assertEquals((Character) 'c', copy.get("foo", 3)); assertNull(copy.get("bar", 3)); original.put("foo", 1, 'd'); assertEquals((Character) 'd', original.get("foo", 1)); assertEquals((Character) 'a', copy.get("foo", 1)); assertEquals(copy.rowKeySet(), ImmutableSet.of("foo", "bar")); assertEquals(copy.columnKeySet(), ImmutableSet.of(1, 3)); }
@Override public void testPutAllTable() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Table<String, Integer, Character> other = HashBasedTable.create(); other.put("foo", 1, 'd'); other.put("bar", 2, 'e'); other.put("cat", 2, 'f'); try { table.putAll(other); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } assertEquals((Character) 'a', table.get("foo", 1)); assertEquals((Character) 'b', table.get("bar", 1)); assertEquals((Character) 'c', table.get("foo", 3)); assertSize(3); }
public void testPutNullReplace() { table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); if (supportsNullValues()) { assertEquals((Character) 'b', table.put("bar", 1, null)); assertNull(table.get("bar", 1)); } else { try { table.put("bar", 1, null); fail(); } catch (NullPointerException expected) { } } }
public void testCreateCopy() { Table<String, Integer, Character> original = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Table<String, Integer, Character> copy = HashBasedTable.create(original); assertEquals(original, copy); assertEquals((Character) 'a', copy.get("foo", 1)); }
public void testCreateCopyArrayTable() { Table<String, Integer, Character> original = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c'); Table<String, Integer, Character> copy = ArrayTable.create(original); assertEquals(original, copy); original.put("foo", 1, 'd'); assertEquals((Character) 'd', original.get("foo", 1)); assertEquals((Character) 'a', copy.get("foo", 1)); assertEquals(copy.rowKeySet(), original.rowKeySet()); assertEquals(copy.columnKeySet(), original.columnKeySet()); }