使用示例:http: //www.leveluplunch.com/java/examples/guava-table-example/
@Test
public void guava_table_example () {
Random r = new Random(3000);
Table<Integer, String, Workout> table = HashBasedTable.create();
table.put(1, "Filthy 50", new Workout(r.nextLong()));
table.put(1, "Fran", new Workout(r.nextLong()));
table.put(1, "The Seven", new Workout(r.nextLong()));
table.put(1, "Murph", new Workout(r.nextLong()));
table.put(1, "The Ryan", new Workout(r.nextLong()));
table.put(1, "King Kong", new Workout(r.nextLong()));
table.put(2, "Filthy 50", new Workout(r.nextLong()));
table.put(2, "Fran", new Workout(r.nextLong()));
table.put(2, "The Seven", new Workout(r.nextLong()));
table.put(2, "Murph", new Workout(r.nextLong()));
table.put(2, "The Ryan", new Workout(r.nextLong()));
table.put(2, "King Kong", new Workout(r.nextLong()));
// for each row key
for (Integer key : table.rowKeySet()) {
logger.info("Person: " + key);
for (Entry<String, Workout> row : table.row(key).entrySet()) {
logger.info("Workout name: " + row.getKey() + " for elapsed time of " + row.getValue().getElapsedTime());
}
}
}