Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 /**
  * Compose two maps map1:x-&gt;y and map2:y-&gt;z to get a map x-&gt;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;
 }
Ejemplo n.º 3
0
 /**
  * Inverts a map x-&gt;y to a map y-&gt;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;
 }
Ejemplo n.º 4
0
 /**
  * Inverts a map x-&gt;y to a map y-&gt;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;
 }
Ejemplo n.º 5
0
 public ThreeDimensionalMap() {
   this.map = Generics.newHashMap();
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Index.
  *
  * @param capacity Initial capacity of Index.
  */
 public HashIndex(int capacity) {
   super();
   objects = new ArrayList<E>(capacity);
   indexes = Generics.newHashMap(capacity);
 }
Ejemplo n.º 7
0
 /** Creates a new Index. */
 public HashIndex() {
   super();
   objects = new ArrayList<E>();
   indexes = Generics.newHashMap();
 }
Ejemplo n.º 8
0
 @Override
 public <K1, V1> Map<K1, V1> setMap(Map<K1, V1> map, int initCapacity) {
   map = Generics.newHashMap(initCapacity);
   return map;
 }
Ejemplo n.º 9
0
 @Override
 public <K1, V1> Map<K1, V1> setMap(Map<K1, V1> map) {
   map = Generics.newHashMap();
   return map;
 }
Ejemplo n.º 10
0
 @Override
 public Map<K, V> newMap(int initCapacity) {
   return Generics.newHashMap(initCapacity);
 }
Ejemplo n.º 11
0
 @Override
 public Map<K, V> newMap() {
   return Generics.newHashMap();
 }