@Test public void testImmutableOrEmptyList() throws Exception { List<String> nullInput = null; List<String> input = Arrays.asList("name1", "name2"); List<String> emptyOutput = CollectionUtils.immutableOrEmptyList(nullInput); List<String> output = CollectionUtils.immutableOrEmptyList(input); assertThat(emptyOutput, hasSize(0)); assertThat(output.size(), equalTo(input.size())); assertThat(output, not(sameInstance(input))); attemptModifyListAndExpectFailure(output, "nope"); }
public static <T> List<T> immutableOrEmptyList(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(Collections::unmodifiableList).orElse(Collections.emptyList()); }
CollectionUtils { public static <T> List<T> immutableOrEmptyList(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(Collections::unmodifiableList).orElse(Collections.emptyList()); } }
CollectionUtils { public static <T> List<T> immutableOrEmptyList(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(Collections::unmodifiableList).orElse(Collections.emptyList()); } private  CollectionUtils(); }
CollectionUtils { public static <T> List<T> immutableOrEmptyList(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(Collections::unmodifiableList).orElse(Collections.emptyList()); } 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 <T> List<T> immutableOrEmptyList(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(Collections::unmodifiableList).orElse(Collections.emptyList()); } 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);  }