Table代表一個特殊的映射,其中兩個鍵可以在組合的方式被指定為單個值。它類似于創(chuàng)建映射的映射。
以下是 com.google.common.collect.Table<R,C,V> 接口的聲明:
@GwtCompatible public interface Table<R,C,V>
S.N. | 方法 & 描述 |
---|---|
1 |
Set<Table.Cell<R,C,V>> cellSet() 返回集合中的所有行鍵/列鍵/值三元組。 |
2 |
void clear() 從表中刪除所有映射。 |
3 |
Map<R,V> column(C columnKey) 返回在給定列鍵的所有映射的視圖。 |
4 |
Set<C> columnKeySet() 返回一組具有表中的一個或多個值的列鍵。 |
5 |
Map<C,Map<R,V>> columnMap() 返回關(guān)聯(lián)的每一列鍵與行鍵對應(yīng)的映射值的視圖。 |
6 |
boolean contains(Object rowKey, Object columnKey) 返回true,如果表中包含與指定的行和列鍵的映射。 |
7 |
boolean containsColumn(Object columnKey) 返回true,如果表中包含與指定列的映射。 |
8 |
boolean containsRow(Object rowKey) 返回true,如果表中包含與指定的行鍵的映射關(guān)系。 |
9 |
boolean containsValue(Object value) 返回true,如果表中包含具有指定值的映射。 |
10 |
boolean equals(Object obj) 比較指定對象與此表是否相等。 |
11 |
V get(Object rowKey, Object columnKey) 返回對應(yīng)于給定的行和列鍵,如果沒有這樣的映射存在值,返回null。 |
12 |
int hashCode() 返回此表中的哈希碼。 |
13 |
boolean isEmpty() 返回true,如果表中沒有映射。 |
14 |
V put(R rowKey, C columnKey, V value) 關(guān)聯(lián)指定值與指定鍵。 |
15 |
void putAll(Table<? extends R,? extends C,? extends V> table) 復(fù)制從指定的表中的所有映射到這個表。 |
16 |
V remove(Object rowKey, Object columnKey) 如果有的話,使用給定鍵相關(guān)聯(lián)刪除的映射。 |
17 |
Map<C,V> row(R rowKey) 返回包含給定行鍵的所有映射的視圖。 |
18 |
Set<R> rowKeySet() 返回一組行鍵具有在表中的一個或多個值。 |
19 |
Map<R,Map<C,V>> rowMap() 返回關(guān)聯(lián)的每一行按鍵與鍵列對應(yīng)的映射值的視圖。 |
20 |
int size() 返回行鍵/列鍵/表中的值映射關(guān)系的數(shù)量。 |
21 |
Collection<V> values() 返回所有值,其中可能包含重復(fù)的集合。 |
選擇使用任何編輯器創(chuàng)建以下java程序在 C:/> Guava
GuavaTester.javaimport java.util.Map; import java.util.Set; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; public class GuavaTester { public static void main(String args[]){ //Table<R,C,V> == Map<R,Map<C,V>> /* * Company: IBM, Microsoft, TCS * IBM -> {101:Mahesh, 102:Ramesh, 103:Suresh} * Microsoft -> {101:Sohan, 102:Mohan, 103:Rohan } * TCS -> {101:Ram, 102: Shyam, 103: Sunil } * * */ //create a table Table<String, String, String> employeeTable = HashBasedTable.create(); //initialize the table with employee details employeeTable.put("IBM", "101","Mahesh"); employeeTable.put("IBM", "102","Ramesh"); employeeTable.put("IBM", "103","Suresh"); employeeTable.put("Microsoft", "111","Sohan"); employeeTable.put("Microsoft", "112","Mohan"); employeeTable.put("Microsoft", "113","Rohan"); employeeTable.put("TCS", "121","Ram"); employeeTable.put("TCS", "122","Shyam"); employeeTable.put("TCS", "123","Sunil"); //get Map corresponding to IBM Map<String,String> ibmEmployees = employeeTable.row("IBM"); System.out.println("List of IBM Employees"); for(Map.Entry<String, String> entry : ibmEmployees.entrySet()){ System上一篇:Guava Ints類下一篇:Guava Booleans類