List of usage examples for java.util Collections unmodifiableList
public static <T> List<T> unmodifiableList(List<? extends T> list)
From source file:Main.java
public static <T> List<T> toImmutableList(List<T> list) { switch (list.size()) { case 0:// ww w . ja va2s.c o m return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: return Collections.unmodifiableList(list); } }
From source file:Main.java
/** * /* w w w . j av a 2 s . co m*/ * Returns an unmodifiable view of the specified list. This method makes use * of the method unmodifiableList of java.util.Collections and returns an * empty list if the provided list is null. * * @param list * @return * @see java.util.Collections.unmodifiableList */ public static <T> List<T> unmodifiableList(List<? extends T> list) { if (list == null) { return Collections.emptyList(); } else { return Collections.unmodifiableList(list); } }
From source file:Main.java
public static <T> List<T> list(List<T> ts) { return Collections.unmodifiableList(new ArrayList<>(ts)); }
From source file:Main.java
public static <A> List<A> cons(A a, List<A> as) { List result = new ArrayList<>(as); result.add(0, a);/*from w w w.j av a2 s .co m*/ return Collections.unmodifiableList(result); }
From source file:Main.java
public static <T> List<T> toUnmodifiableCopy(Collection<T> collection) { return Collections.unmodifiableList(new ArrayList<T>(collection)); }
From source file:Main.java
private static List<String> list(String... values) { return Collections.unmodifiableList(Arrays.asList(values)); }
From source file:Main.java
public static <T> List<T> immutableList(List<T> list) { return Collections.unmodifiableList(new ArrayList<>(list)); }
From source file:Main.java
/** Returns an immutable copy of {@code list}. */ public static <T> List<T> immutableList(List<T> list) { return Collections.unmodifiableList(new ArrayList<T>(list)); }
From source file:Main.java
@SafeVarargs public static <T> List<T> makeUnmodifiableList(T... items) { ArrayList<T> list = new ArrayList<>(items.length); Collections.addAll(list, items); return Collections.unmodifiableList(list); }
From source file:Main.java
@SafeVarargs public static <T> List<T> list(T... t) { return Collections.unmodifiableList(Arrays.asList(Arrays.copyOf(t, t.length))); }