/** * Create a modifiable list from the {@link Collection} provided. The return * value is backed by an {@link ArrayList}. */ public static <T> List<T> newList(Collection<? extends T> c) { return new ArrayList<>(CollectionUtil.nullAsEmpty(c)); }
/** * Creates a set that can be modified from the {@link Collection} provided. */ public static <T> Set<T> newSet(Collection<T> c) { return new HashSet<T>(CollectionUtil.nullAsEmpty(c)); }
/** * Creates a set that can be modified from the {@link Collection} provided. */ public static <T> Set<T> newSet(Collection<T> c) { return new HashSet<>(CollectionUtil.nullAsEmpty(c)); }
/** * Create a modifiable list from the {@link Collection} provided. The return * value is backed by an {@link ArrayList}. */ public static <T> List<T> newList(Collection<? extends T> c) { return new ArrayList<T>(CollectionUtil.nullAsEmpty(c)); }
/** * Create a modifiable list from the {@link Collection} provided. The return * value is backed by an {@link ArrayList}. */ public static <T> List<T> newList(Collection<? extends T> c) { return new ArrayList<>(CollectionUtil.nullAsEmpty(c)); }
/** * Creates a set that can be modified from the {@link Collection} provided. */ public static <T> Set<T> newSet(Collection<T> c) { return new HashSet<>(CollectionUtil.nullAsEmpty(c)); }
public static <T, K> Map<T, K> asReadOnlyMap(Map<T, K> map) { if ( map instanceof SortedMap ) { @SuppressWarnings("unchecked") SortedMap<T,K> sortedMap = (SortedMap)map; return Collections.unmodifiableSortedMap(sortedMap); } else { return Collections.unmodifiableMap(nullAsEmpty(map)); } }
/** * Create an unmodifiable {@link List} based on the {@link List} passed in * checks for null and returns an empty list if null is passed in. This one * insures that the order is maintained between lists. */ public static <T> List<T> newReadOnlyList(final List<? extends T> list) { List<T> l = new ArrayList<T>(nullAsEmpty(list)); return Collections.unmodifiableList(l); }
public static <T, K> Map<T, K> asReadOnlyMap(Map<T, K> map) { if (map instanceof SortedMap) { @SuppressWarnings("unchecked") SortedMap<T, K> sortedMap = (SortedMap) map; return Collections.unmodifiableSortedMap(sortedMap); } else { return Collections.unmodifiableMap(nullAsEmpty(map)); } }
/** * Create an unmodifiable {@link List} based on the {@link List} passed in * checks for null and returns an empty list if null is passed in. This one * insures that the order is maintained between lists. */ public static <T> List<T> newReadOnlyList(final List<? extends T> list) { List<T> l = new ArrayList<>(nullAsEmpty(list)); return Collections.unmodifiableList(l); }
public static <T, K> Map<T, K> asReadOnlyMap(Map<T, K> map) { if (map instanceof SortedMap) { @SuppressWarnings("unchecked") SortedMap<T, K> sortedMap = (SortedMap) map; return Collections.unmodifiableSortedMap(sortedMap); } else { return Collections.unmodifiableMap(nullAsEmpty(map)); } }
/** * Create an unmodifiable {@link List} based on the {@link List} passed in * checks for null and returns an empty list if null is passed in. This one * insures that the order is maintained between lists. */ public static <T> List<T> newReadOnlyList(final List<? extends T> list) { List<T> l = new ArrayList<>(nullAsEmpty(list)); return Collections.unmodifiableList(l); }
public static <T, K> Map<T, K> newReadOnlyMap(Map<T, K> map) { return Collections.unmodifiableMap(new HashMap<>(nullAsEmpty(map))); }
public static <T, K> Map<T, K> newReadOnlyMap(Map<T, K> map) { return Collections.unmodifiableMap(new HashMap<T, K>(nullAsEmpty(map))); }
public Object execute(Map<String, Object> arguments) throws Exception { Map<String, Object> args = CollectionUtil.nullAsEmpty(arguments); for (Map.Entry<String, Object> entry : args.entrySet()) { _groovyScript.setProperty(entry.getKey(), entry.getValue()); } return _groovyScript.run(); } }
@Override public Object execute(Map<String, Object> arguments) throws Exception { Map<String, Object> args = CollectionUtil.nullAsEmpty(arguments); groovyScript.setBinding(new Binding(args)); return groovyScript.run(); } }
@Override public Object execute(Map<String, Object> arguments) throws Exception { Map<String, Object> args = CollectionUtil.nullAsEmpty(arguments); groovyScript.setBinding(new Binding(args)); return groovyScript.run(); } }
@Test public void testNullAsEmptySet() { // test w/ null Set<String> l = CollectionUtil.nullAsEmpty((Set<String>) null); assertNotNull(l); assertEquals(l.size(), 0); // test w/ regular l.add(" adf"); Set<String> t = CollectionUtil.nullAsEmpty(l); assertEquals(l, t); }
@Test public void testNullAsEmptyMap() { // test w/ null Map<String, String> m = CollectionUtil.nullAsEmpty((Map<String, String>) null); assertNotNull(m); assertEquals(m.size(), 0); // test w/ regular m.put(" adf", "fdf"); Map<String, String> t = CollectionUtil.nullAsEmpty(m); assertEquals(m, t); }
@Test public void testNullAsEmptyList() { // test w/ null List<String> l = CollectionUtil.nullAsEmpty((List<String>) null); assertNotNull(l); assertEquals(l.size(), 0); // test w/ regular l.add(" adf"); List<String> t = CollectionUtil.nullAsEmpty(l); assertEquals(l, t); }