Tabnine Logo
Table
Code IndexAdd Tabnine to your IDE (free)

How to use
Table
in
com.google.common.collect

Best Java code snippets using com.google.common.collect.Table (Showing top 20 results out of 36,576)

Refine searchRefine arrow

  • ForwardingTable
  • HashBasedTable
  • Nullable
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

 @Override
 protected Map<String, Integer> makePopulatedMap() {
  Table<Character, String, Integer> table = HashBasedTable.create();
  table.put('a', "one", 2);
  table.put('a', "two", 4);
  table.put('a', "three", 6);
  table.put('b', "four", 8);
  return Tables.transformValues(table, DIVIDE_BY_2).row('a');
 }
}
origin: google/guava

@Override
public boolean contains(Object rowKey, Object columnKey) {
 return fromTable.contains(rowKey, columnKey);
}
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

private ArrayTable(Table<R, C, V> table) {
 this(table.rowKeySet(), table.columnKeySet());
 putAll(table);
}
origin: google/jimfs

/**
 * Gets the value of the given attribute in the given view.
 */
@Nullable
public synchronized final Object getAttribute(String view, String attribute) {
 if (attributes == null) {
  return null;
 }
 return attributes.get(view, attribute);
}
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 testIterationOrder() {
 Table<String, String, String> table = HashBasedTable.create();
 for (int i = 0; i < 5; i++) {
  table.put("r" + i, "c" + i, "v" + i);
 }
 assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
 assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
 assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
}
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());
}
origin: google/guava

 public void testRowClearAndPut() {
  if (supportsRemove()) {
   table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
   Map<Integer, Character> row = table.row("foo");
   assertEquals(ImmutableMap.of(1, 'a', 3, 'c'), row);
   table.remove("foo", 3);
   assertEquals(ImmutableMap.of(1, 'a'), row);
   table.remove("foo", 1);
   assertEquals(ImmutableMap.of(), row);
   table.put("foo", 2, 'b');
   assertEquals(ImmutableMap.of(2, 'b'), row);
   row.clear();
   assertEquals(ImmutableMap.of(), row);
   table.put("foo", 5, 'x');
   assertEquals(ImmutableMap.of(5, 'x'), row);
  }
 }
}
origin: google/guava

@Override
protected Table<String, Integer, Character> create(Object... data) {
 Table<String, Integer, String> table = HashBasedTable.create();
 checkArgument(data.length % 3 == 0);
 for (int i = 0; i < data.length; i += 3) {
  String value = (data[i + 2] == null) ? null : (data[i + 2] + "transformed");
  table.put((String) data[i], (Integer) data[i + 1], value);
 }
 return Tables.transformValues(table, FIRST_CHARACTER);
}
origin: google/guava

 @Override
 protected Map<String, Integer> makePopulatedMap() {
  Table<String, Character, Integer> table = HashBasedTable.create();
  table.put("one", 'a', 1);
  table.put("two", 'a', 2);
  table.put("three", 'a', 3);
  table.put("four", 'b', 4);
  return Tables.unmodifiableTable(table).column('a');
 }
}
origin: google/guava

@Override
protected Table<String, Integer, Character> create(Object... data) {
 Table<String, Integer, Character> table = HashBasedTable.create();
 table.put("foo", 4, 'a');
 table.put("cat", 1, 'b');
 table.clear();
 populate(table, data);
 return table;
}
origin: google/guava

@Override
public Set<Cell<String, Integer, Character>> create(Object... elements) {
 Table<String, Integer, Character> table = createTable();
 for (Object element : elements) {
  @SuppressWarnings("unchecked")
  Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
  table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
 }
 return table.cellSet();
}
origin: google/guava

public void testCreateExplicitComparators() {
 table = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString());
 table.put("foo", 3, 'a');
 table.put("foo", 12, 'b');
 table.put("bar", 5, 'c');
 table.put("cat", 8, 'd');
 assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder();
 assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder();
}
origin: google/guava

 @Override
 protected Map<String, Integer> makePopulatedMap() {
  Table<Character, String, Integer> table = makeTable();
  table.put('a', "one", 1);
  table.put('a', "two", 2);
  table.put('a', "three", 3);
  table.put('b', "four", 4);
  return table.row('a');
 }
}
origin: google/guava

 @Override
 protected Map<String, Map<Integer, Character>> makePopulatedMap() {
  Table<Integer, String, Character> table = HashBasedTable.create();
  table.put(1, "foo", 'a');
  table.put(1, "bar", 'b');
  table.put(3, "foo", 'c');
  return Tables.unmodifiableTable(table).columnMap();
 }
}
origin: google/guava

 @Override
 public Set<Cell<String, Integer, Character>> create(Object... elements) {
  Table<String, Integer, Character> table = HashBasedTable.create();
  for (Object element : elements) {
   @SuppressWarnings("unchecked")
   Cell<String, Integer, Character> cell =
     (Cell<String, Integer, Character>) element;
   table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
  }
  return Tables.unmodifiableTable(table).cellSet();
 }
})
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

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));
}
com.google.common.collectTable

Javadoc

A collection that associates an ordered pair of keys, called a row key and a column key, with a single value. A table may be sparse, with only a small fraction of row key / column key pairs possessing a corresponding value.

The mappings corresponding to a given row key may be viewed as a Map whose keys are the columns. The reverse is also available, associating a column with a row key / value map. Note that, in some implementations, data access by column key may have fewer supported operations or worse performance than data access by row key.

The methods returning collections or maps always return views of the underlying table. Updating the table can change the contents of those collections, and updating the collections will change the table.

All methods that modify the table are optional, and the views returned by the table may or may not be modifiable. When modification isn't supported, those methods will throw an UnsupportedOperationException.

See the Guava User Guide article on Table.

Most used methods

  • put
    Associates the specified value with the specified keys. If the table already contained a mapping for
  • get
    Returns the value corresponding to the given row and column keys, or null if no such mapping exists.
  • row
    Returns a view of all mappings that have the given row key. For each row key / column key / value ma
  • contains
    Returns true if the table contains a mapping with the specified row and column keys.
  • rowKeySet
    Returns a set of row keys that have one or more values in the table. Changes to the set will update
  • cellSet
    Returns a set of all row key / column key / value triplets. Changes to the returned set will update
  • remove
    Removes the mapping, if any, associated with the given keys.
  • columnKeySet
    Returns a set of column keys that have one or more values in the table. Changes to the set will upda
  • rowMap
    Returns a view that associates each row key with the corresponding map from column keys to values. C
  • values
    Returns a collection of all values, which may contain duplicates. Changes to the returned collection
  • clear
    Removes all mappings from the table.
  • column
    Returns a view of all mappings that have the given column key. For each row key / column key / value
  • clear,
  • column,
  • size,
  • isEmpty,
  • containsRow,
  • containsColumn,
  • columnMap,
  • putAll,
  • containsValue,
  • equals

Popular in Java

  • Creating JSON documents from java classes using gson
  • onCreateOptionsMenu (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now