com.google.common.collect.Table.get()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(412)

本文整理了Java中com.google.common.collect.Table.get()方法的一些代码示例,展示了Table.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.get()方法的具体详情如下:
包路径:com.google.common.collect.Table
类名称:Table
方法名:get

Table.get介绍

[英]Returns the value corresponding to the given row and column keys, or null if no such mapping exists.
[中]返回与给定行键和列键对应的值,如果不存在此类映射,则返回null。

代码示例

代码示例来源:origin: apache/incubator-druid

  1. int getLoadedReplicants(SegmentId segmentId, String tier)
  2. {
  3. Integer retVal = segmentsInCluster.get(segmentId, tier);
  4. return (retVal == null) ? 0 : retVal;
  5. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V2 get(Object rowKey, Object columnKey) {
  3. // The function is passed a null input only when the table contains a null
  4. // value.
  5. return contains(rowKey, columnKey) ? function.apply(fromTable.get(rowKey, columnKey)) : null;
  6. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V get(Object rowKey, Object columnKey) {
  3. return delegate().get(rowKey, columnKey);
  4. }

代码示例来源:origin: google/guava

  1. void put(R row, C column, V value, BinaryOperator<V> merger) {
  2. MutableCell<R, C, V> oldCell = table.get(row, column);
  3. if (oldCell == null) {
  4. MutableCell<R, C, V> cell = new MutableCell<>(row, column, value);
  5. insertionOrder.add(cell);
  6. table.put(row, column, cell);
  7. } else {
  8. oldCell.merge(value, merger);
  9. }
  10. }

代码示例来源:origin: google/guava

  1. private static <R, C, V> void merge(
  2. Table<R, C, V> table, R row, C column, V value, BinaryOperator<V> mergeFunction) {
  3. checkNotNull(value);
  4. V oldValue = table.get(row, column);
  5. if (oldValue == null) {
  6. table.put(row, column, value);
  7. } else {
  8. V newValue = mergeFunction.apply(oldValue, value);
  9. if (newValue == null) {
  10. table.remove(row, column);
  11. } else {
  12. table.put(row, column, newValue);
  13. }
  14. }
  15. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V get(Object rowKey, Object columnKey) {
  3. assertTrue(Thread.holdsLock(mutex));
  4. return delegate.get(rowKey, columnKey);
  5. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V get(@Nullable Object rowKey, @Nullable Object columnKey) {
  3. return original.get(columnKey, rowKey);
  4. }

代码示例来源:origin: google/guava

  1. @Override
  2. public V get(@Nullable Object rowKey, @Nullable Object columnKey) {
  3. synchronized (mutex) {
  4. return delegate().get(rowKey, columnKey);
  5. }
  6. }

代码示例来源:origin: google/guava

  1. public void testGet() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. assertEquals((Character) 'a', table.get("foo", 1));
  4. assertEquals((Character) 'b', table.get("bar", 1));
  5. assertEquals((Character) 'c', table.get("foo", 3));
  6. assertNull(table.get("foo", 2));
  7. assertNull(table.get("bar", 3));
  8. assertNull(table.get("cat", 1));
  9. assertNull(table.get("foo", null));
  10. assertNull(table.get(null, 1));
  11. assertNull(table.get(null, null));
  12. }

代码示例来源:origin: google/guava

  1. public void testGetMissingKeys() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. assertNull(table.get("dog", 1));
  4. assertNull(table.get("foo", 4));
  5. }

代码示例来源:origin: google/guava

  1. public void testPutAllTable() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. Table<String, Integer, Character> other = HashBasedTable.create();
  4. other.put("foo", 1, 'd');
  5. other.put("bar", 2, 'e');
  6. other.put("cat", 2, 'f');
  7. table.putAll(other);
  8. assertEquals((Character) 'd', table.get("foo", 1));
  9. assertEquals((Character) 'b', table.get("bar", 1));
  10. assertEquals((Character) 'c', table.get("foo", 3));
  11. assertEquals((Character) 'e', table.get("bar", 2));
  12. assertEquals((Character) 'f', table.get("cat", 2));
  13. assertSize(5);
  14. }

代码示例来源:origin: google/guava

  1. public void testCreateWithValidSizes() {
  2. Table<String, Integer, Character> table1 = HashBasedTable.create(100, 20);
  3. table1.put("foo", 1, 'a');
  4. assertEquals((Character) 'a', table1.get("foo", 1));
  5. Table<String, Integer, Character> table2 = HashBasedTable.create(100, 0);
  6. table2.put("foo", 1, 'a');
  7. assertEquals((Character) 'a', table2.get("foo", 1));
  8. Table<String, Integer, Character> table3 = HashBasedTable.create(0, 20);
  9. table3.put("foo", 1, 'a');
  10. assertEquals((Character) 'a', table3.get("foo", 1));
  11. Table<String, Integer, Character> table4 = HashBasedTable.create(0, 0);
  12. table4.put("foo", 1, 'a');
  13. assertEquals((Character) 'a', table4.get("foo", 1));
  14. }

代码示例来源:origin: google/guava

  1. public void testPut() {
  2. assertNull(table.put("foo", 1, 'a'));
  3. assertNull(table.put("bar", 1, 'b'));
  4. assertNull(table.put("foo", 3, 'c'));
  5. assertEquals((Character) 'a', table.put("foo", 1, 'd'));
  6. assertEquals((Character) 'd', table.get("foo", 1));
  7. assertEquals((Character) 'b', table.get("bar", 1));
  8. assertSize(3);
  9. assertEquals((Character) 'd', table.put("foo", 1, 'd'));
  10. assertEquals((Character) 'd', table.get("foo", 1));
  11. assertSize(3);
  12. }

代码示例来源:origin: google/guava

  1. public void testPutOriginalModifiesTranspose() {
  2. Table<Integer, String, Character> original = HashBasedTable.create();
  3. Table<String, Integer, Character> transpose = Tables.transpose(original);
  4. original.put(1, "foo", 'a');
  5. assertEquals((Character) 'a', transpose.get("foo", 1));
  6. }

代码示例来源:origin: google/guava

  1. public void testPutTransposeModifiesOriginal() {
  2. Table<Integer, String, Character> original = HashBasedTable.create();
  3. Table<String, Integer, Character> transpose = Tables.transpose(original);
  4. transpose.put("foo", 1, 'a');
  5. assertEquals((Character) 'a', original.get(1, "foo"));
  6. }

代码示例来源:origin: google/guava

  1. public void testCreateCopyHashBasedTable() {
  2. Table<String, Integer, Character> original = HashBasedTable.create();
  3. original.put("foo", 1, 'a');
  4. original.put("bar", 1, 'b');
  5. original.put("foo", 3, 'c');
  6. Table<String, Integer, Character> copy = ArrayTable.create(original);
  7. assertEquals(4, copy.size());
  8. assertEquals((Character) 'a', copy.get("foo", 1));
  9. assertEquals((Character) 'b', copy.get("bar", 1));
  10. assertEquals((Character) 'c', copy.get("foo", 3));
  11. assertNull(copy.get("bar", 3));
  12. original.put("foo", 1, 'd');
  13. assertEquals((Character) 'd', original.get("foo", 1));
  14. assertEquals((Character) 'a', copy.get("foo", 1));
  15. assertEquals(copy.rowKeySet(), ImmutableSet.of("foo", "bar"));
  16. assertEquals(copy.columnKeySet(), ImmutableSet.of(1, 3));
  17. }

代码示例来源:origin: google/guava

  1. @Override
  2. public void testPutAllTable() {
  3. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  4. Table<String, Integer, Character> other = HashBasedTable.create();
  5. other.put("foo", 1, 'd');
  6. other.put("bar", 2, 'e');
  7. other.put("cat", 2, 'f');
  8. try {
  9. table.putAll(other);
  10. fail("Expected UnsupportedOperationException");
  11. } catch (UnsupportedOperationException expected) {
  12. }
  13. assertEquals((Character) 'a', table.get("foo", 1));
  14. assertEquals((Character) 'b', table.get("bar", 1));
  15. assertEquals((Character) 'c', table.get("foo", 3));
  16. assertSize(3);
  17. }

代码示例来源:origin: google/guava

  1. public void testPutNullReplace() {
  2. table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  3. if (supportsNullValues()) {
  4. assertEquals((Character) 'b', table.put("bar", 1, null));
  5. assertNull(table.get("bar", 1));
  6. } else {
  7. try {
  8. table.put("bar", 1, null);
  9. fail();
  10. } catch (NullPointerException expected) {
  11. }
  12. }
  13. }

代码示例来源:origin: google/guava

  1. public void testCreateCopy() {
  2. Table<String, Integer, Character> original =
  3. create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  4. Table<String, Integer, Character> copy = HashBasedTable.create(original);
  5. assertEquals(original, copy);
  6. assertEquals((Character) 'a', copy.get("foo", 1));
  7. }

代码示例来源:origin: google/guava

  1. public void testCreateCopyArrayTable() {
  2. Table<String, Integer, Character> original =
  3. create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
  4. Table<String, Integer, Character> copy = ArrayTable.create(original);
  5. assertEquals(original, copy);
  6. original.put("foo", 1, 'd');
  7. assertEquals((Character) 'd', original.get("foo", 1));
  8. assertEquals((Character) 'a', copy.get("foo", 1));
  9. assertEquals(copy.rowKeySet(), original.rowKeySet());
  10. assertEquals(copy.columnKeySet(), original.columnKeySet());
  11. }

相关文章