/** 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; }
@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; }