コード例 #1
0
 /** Converts a {@link Map} of integers to a {@link TargetMapping}. */
 public static TargetMapping target(Map<Integer, Integer> map, int sourceCount, int targetCount) {
   final PartialFunctionImpl mapping =
       new PartialFunctionImpl(sourceCount, targetCount, MappingType.FUNCTION);
   for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
     mapping.set(entry.getKey(), entry.getValue());
   }
   return mapping;
 }
コード例 #2
0
 @SuppressWarnings("unchecked")
 private static <K, V> HashMap<K, V> copy(Map<K, V> map) {
   HashMap<K, V> copy = new HashMap<K, V>();
   for (Iterator<Map.Entry<K, V>> i = map.entrySet().iterator(); i.hasNext(); ) {
     Map.Entry<K, V> e = i.next();
     if (e.getValue() instanceof Set) {
       copy.put(e.getKey(), (V) copy((Set) e.getValue()));
     } else {
       copy.put(e.getKey(), e.getValue());
     }
   }
   return copy;
 }