public static < K , V > Map < K , V > immutableMapCopy ( Map < K , V > map ) { if ( map == null ) return null ; if ( map . isEmpty ( ) ) return Collections . emptyMap ( ) ; if ( map . size ( ) == 1 ) { Map . Entry < K , V > me = map . entrySet ( ) . iterator ( ) . next ( ) ; return Collections . singletonMap ( me . getKey ( ) , me . getValue ( ) ) ; } Map < ? extends K , ? extends V > copy = ObjectDuplicator . duplicateMap ( map ) ; if ( copy == null ) copy = attemptCopyConstructor ( map , Map . class ) ; if ( copy == null ) copy = new HashMap <> ( map ) ; return new ImmutableMapWrapper <> ( copy ) ; }
Creates an immutable copy of the specified map .