@Override public <S, R> SmartMap<S, R> map( final UnaryFunction<KeyValuePair<S, R>, java.util.Map.Entry<K, V>> function) { SmartMap<S, R> resultMap = createNewInstance(new HashMap<S, R>()); for (Map.Entry<K, V> entry : internalMap.entrySet()) { KeyValuePair<S, R> mappedEntry = function.apply(entry); resultMap.put(mappedEntry.getKey(), mappedEntry.getValue()); } return resultMap; }
@Override public SmartMap<V, K> swap() { if (!isBijective()) { throw new UnsupportedOperationException("Map is not bijective!"); } SmartMap<V, K> swappedMap = createNewInstance(new HashMap<V, K>()); for (Map.Entry<K, V> entry : internalMap.entrySet()) { swappedMap.put(entry.getValue(), entry.getKey()); } return swappedMap; }