@Test public void testMutableListCopyOrNull() throws Exception { List<String> nullInput = null; List<String> input = Arrays.asList("name1", "name2"); List<String> nullOutput = CollectionUtils.mutableListCopyOrNull(nullInput); List<String> output = CollectionUtils.mutableListCopyOrNull(input); assertThat(nullOutput, nullValue()); assertThat(output.size(), equalTo(input.size())); assertThat(output, not(sameInstance(input))); attemptModifyListAndExpectSuccess(output, "yup"); }
public static <T> List<T> mutableListCopyOrNull(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(l -> (List<T>)l).orElse(null); }
CollectionUtils { public static <T> List<T> mutableListCopyOrNull(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(l -> (List<T>)l).orElse(null); } }
CollectionUtils { public static <T> List<T> mutableListCopyOrNull(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(l -> (List<T>)l).orElse(null); } private  CollectionUtils(); }
CollectionUtils { public static <T> List<T> mutableListCopyOrNull(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(l -> (List<T>)l).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 <T> List<T> mutableListCopyOrNull(List<T> input) { return Optional.ofNullable(input).map(ArrayList::new).map(l -> (List<T>)l).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);  }