/** * Creates a shallow copy of a map and wraps it in an UnmodifiableMap. * * @param sourceMap map we want to shallow clone and make immutable. * @param <K> key of the map. * @param <V> value of the map. * @return sshallow cloned map that is immutable. */ public static <K,V> Map<K,V> immutableCopy(Map<K,V> sourceMap) { // If we're already dealing with an UnmodifiableMap if (sourceMap instanceof UnmodifiableMap) { // just return it. return sourceMap; } // Create a new map and add all entries from the source map Map<K,V> copy = Maps.newHashMap(); copy.putAll(sourceMap); // Wrap it in an unmodifiable map. return Collections.unmodifiableMap(copy); }
@Override public Map<String, VariableResult> getState() { return UnmodifiableMap.decorate(variables); }