public static void main(String[] args) { Map<String, String> map1 = Generics.newHashMap(); map1.put("a", "1"); map1.put("b", "2"); map1.put("c", "2"); map1.put("d", "4"); Map<String, String> map2 = Generics.newHashMap(); map2.put("1", "x"); map2.put("2", "y"); map2.put("3", "z"); System.out.println("map1: " + map1); System.out.println("invert(map1): " + Maps.invert(map1)); System.out.println("invertSet(map1): " + Maps.invertSet(map1)); System.out.println("map2: " + map2); System.out.println("compose(map1,map2): " + Maps.compose(map1, map2)); Map<String, Set<String>> setValues = Generics.newHashMap(); Map<String, List<String>> listValues = Generics.newHashMap(); Maps.putIntoValueArrayList(listValues, "a", "1"); Maps.putIntoValueArrayList(listValues, "a", "1"); Maps.putIntoValueArrayList(listValues, "a", "2"); Maps.putIntoValueHashSet(setValues, "a", "1"); Maps.putIntoValueHashSet(setValues, "a", "1"); Maps.putIntoValueHashSet(setValues, "a", "2"); System.out.println("listValues: " + listValues); System.out.println("setValues: " + setValues); }
/** * Compose two maps map1:x->y and map2:y->z to get a map x->z * * @return The composed map */ public static <X, Y, Z> Map<X, Z> compose(Map<X, Y> map1, Map<Y, Z> map2) { Map<X, Z> composedMap = Generics.newHashMap(); for (Entry<X, Y> xyEntry : map1.entrySet()) { composedMap.put(xyEntry.getKey(), map2.get(xyEntry.getValue())); } return composedMap; }
/** * Inverts a map x->y to a map y->pow(x) not assuming unique preimages. * * @return The inverted set */ public static <X, Y> Map<Y, Set<X>> invertSet(Map<X, Y> map) { Map<Y, Set<X>> invertedMap = Generics.newHashMap(); for (Map.Entry<X, Y> entry : map.entrySet()) { X key = entry.getKey(); Y value = entry.getValue(); putIntoValueHashSet(invertedMap, value, key); } return invertedMap; }
/** * Inverts a map x->y to a map y->x assuming unique preimages. If they are not unique, you * get an arbitrary ones as the values in the inverted map. * * @return The inverted map */ public static <X, Y> Map<Y, X> invert(Map<X, Y> map) { Map<Y, X> invertedMap = Generics.newHashMap(); for (Map.Entry<X, Y> entry : map.entrySet()) { X key = entry.getKey(); Y value = entry.getValue(); invertedMap.put(value, key); } return invertedMap; }
public ThreeDimensionalMap() { this.map = Generics.newHashMap(); }
/** * Creates a new Index. * * @param capacity Initial capacity of Index. */ public HashIndex(int capacity) { super(); objects = new ArrayList<E>(capacity); indexes = Generics.newHashMap(capacity); }
/** Creates a new Index. */ public HashIndex() { super(); objects = new ArrayList<E>(); indexes = Generics.newHashMap(); }
@Override public <K1, V1> Map<K1, V1> setMap(Map<K1, V1> map, int initCapacity) { map = Generics.newHashMap(initCapacity); return map; }
@Override public <K1, V1> Map<K1, V1> setMap(Map<K1, V1> map) { map = Generics.newHashMap(); return map; }
@Override public Map<K, V> newMap(int initCapacity) { return Generics.newHashMap(initCapacity); }
@Override public Map<K, V> newMap() { return Generics.newHashMap(); }