Skip to content

Instantly share code, notes, and snippets.

@alalwww
Last active December 17, 2015 13:59
Show Gist options
  • Save alalwww/5621491 to your computer and use it in GitHub Desktop.
Save alalwww/5621491 to your computer and use it in GitHub Desktop.
public class Main {
public static main(String... args) {
Map<Integer, Map<Position, Box>> backingMap = Maps.newHashMap();
Supplier<Map<Position, Box>> factory = newMapFactory();
Table<Integer, Position, Box> table = Tables.newCustomTable(backingMap, factory);
Integer rowKey = 0;
Position columnKey = getPosition();
Box value = new Box();
// put
table.put(rowKey, columnKey, value);
// get
Box box = table.get(rowKey, columnKey);
}
static <C, V> Supplier<Map<C, V>> newMapFactory() {
return new MapFactory<C, V>();
}
static final class MapFactory<C, V> implements Supplier<Map<C, V>> {
public Map<C, V> get() {
return Maps.newHashMap();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment