@Test public void testImmutableMapOrNull() throws Exception { Map<String, String> nullInput = null; Map<String, String> input = Collections.singletonMap("key", "val"); Map<String, String> nullOutput = CollectionUtils.immutableMapOrNull(nullInput); Map<String, String> output = CollectionUtils.immutableMapOrNull(input); assertThat(nullOutput, nullValue()); assertThat(output.size(), equalTo(input.size())); assertThat(output, not(sameInstance(input))); attemptModifyMapAndExpectFailure(output, "key2", "val2"); }
public static <K, V> Map<K, V> immutableMapOrNull(Map<K, V> input) { return Optional.ofNullable(input).map(HashMap::new).map(Collections::unmodifiableMap).orElse(null); }
CollectionUtils { public static <K, V> Map<K, V> immutableMapOrNull(Map<K, V> input) { return Optional.ofNullable(input).map(HashMap::new).map(Collections::unmodifiableMap).orElse(null); } }
CollectionUtils { public static <K, V> Map<K, V> immutableMapOrNull(Map<K, V> input) { return Optional.ofNullable(input).map(HashMap::new).map(Collections::unmodifiableMap).orElse(null); } private  CollectionUtils(); }
CollectionUtils { public static <K, V> Map<K, V> immutableMapOrNull(Map<K, V> input) { return Optional.ofNullable(input).map(HashMap::new).map(Collections::unmodifiableMap).orElse(null); } private  CollectionUtils(); static T[] nullableArrayCopy(T[] input); static double[] nullableArrayCopy(double... input); static long[] nullableArrayCopy(long... input); static byte[] nullableArrayCopy(byte... input); static void nullOutByteArray(byte... input); static List<T> immutableOrEmptyList(List<T> input); static List<T> immutableListOrNull(List<T> input); static List<T> mutableListCopyOrNull(List<T> input); static Map<K, V> immutableOrEmptyMap(Map<K, V> input); static Map<K, V> immutableMapOrNull(Map<K, V> input); static SortedMap<K, V> immutableSortedOrEmptyMap(SortedMap<K, V> input); static SortedMap<K, V> immutableSortedMapOrNull(SortedMap<K, V> input); static Set<T> immutableOrEmptySet(Set<T> input); static Set<T> immutableSetOrNull(Set<T> input); }
CollectionUtils { public static <K, V> Map<K, V> immutableMapOrNull(Map<K, V> input) { return Optional.ofNullable(input).map(HashMap::new).map(Collections::unmodifiableMap).orElse(null); } private  CollectionUtils(); static T[] nullableArrayCopy(T[] input); static double[] nullableArrayCopy(double... input); static long[] nullableArrayCopy(long... input); static byte[] nullableArrayCopy(byte... input); static void nullOutByteArray(byte... input); static List<T> immutableOrEmptyList(List<T> input); static List<T> immutableListOrNull(List<T> input); static List<T> mutableListCopyOrNull(List<T> input); static Map<K, V> immutableOrEmptyMap(Map<K, V> input); static Map<K, V> immutableMapOrNull(Map<K, V> input); static SortedMap<K, V> immutableSortedOrEmptyMap(SortedMap<K, V> input); static SortedMap<K, V> immutableSortedMapOrNull(SortedMap<K, V> input); static Set<T> immutableOrEmptySet(Set<T> input); static Set<T> immutableSetOrNull(Set<T> input);  }