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

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

本文整理了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

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

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

@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;
}

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

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

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

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);
 }
}

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

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);
  }
 }
}

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

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

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

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

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

@Override
public V get(@Nullable Object rowKey, @Nullable Object columnKey) {
 synchronized (mutex) {
  return delegate().get(rowKey, columnKey);
 }
}

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

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));
}

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

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

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

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);
}

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

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));
}

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

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);
}

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

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));
}

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

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"));
}

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

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));
}

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

@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);
}

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

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) {
  }
 }
}

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

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));
}

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

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());
}

相关文章