public static < T > Collection < T > immutableCollectionCopy ( Collection < T > collection ) { if ( collection == null ) return null ; if ( collection . isEmpty ( ) ) return Collections . emptySet ( ) ; if ( collection . size ( ) == 1 ) return Collections . singleton ( collection . iterator ( ) . next ( ) ) ; Collection < ? extends T > copy = ObjectDuplicator . duplicateCollection ( collection ) ; if ( copy == null ) copy = attemptCopyConstructor ( collection , Collection . class ) ; if ( copy == null ) copy = new ArrayList <> ( collection ) ; return new ImmutableCollectionWrapper <> ( copy ) ; }
Creates a new immutable copy of the specified Collection .