Java 类org.apache.commons.collections.map.UnmodifiableMap 实例源码

项目:storm-dynamic-spout    文件:Tools.java   
/**
 * 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);
}
项目:metron    文件:DefaultStellarShellExecutor.java   
@Override
public Map<String, VariableResult> getState() {
  return UnmodifiableMap.decorate(variables);
}