Example usage for java.util Collections unmodifiableList

List of usage examples for java.util Collections unmodifiableList

Introduction

In this page you can find the example usage for java.util Collections unmodifiableList.

Prototype

public static <T> List<T> unmodifiableList(List<? extends T> list) 

Source Link

Document

Returns an unmodifiable view of the specified list.

Usage

From source file:Main.java

public static <T> List<T> nullTolerantUnmodifiableList(List<? extends T> l) {
    return l == null ? Collections.<T>emptyList() : Collections.unmodifiableList(l);
}

From source file:Main.java

/**
 * Make a list map immutable.//from   w  w  w.  j a v  a 2 s  .  c o m
 *
 * @param listMap
 *            the list map in input.
 * @return the immutable list map.
 */
public static <C, E> Map<C, List<E>> makeListMapImmutable(Map<C, List<E>> listMap) {
    for (C key : listMap.keySet()) {
        listMap.put(key, Collections.unmodifiableList(listMap.get(key)));
    }

    return Collections.unmodifiableMap(listMap);
}

From source file:com.omnigon.aem.common.utils.PojoUtils.java

public static <T> List<T> safeUnmodifiableList(List<T> list) {
    return CollectionUtils.isNotEmpty(list) ? Collections.unmodifiableList(list) : Collections.<T>emptyList();
}

From source file:com.iblsoft.iwxxm.webservice.ws.TestUtils.java

public static List<String> loadTestResources(String[] resourcePaths) throws Exception {
    List<String> messages = new ArrayList<>(resourcePaths.length);
    for (String resourceName : resourcePaths) {
        messages.add(loadTestResource(resourceName));
    }/*from  w w  w . j  a v  a 2 s  .  c o  m*/
    return Collections.unmodifiableList(messages);
}

From source file:Main.java

public static <T> List<T> toUnmodifiableList(Iterable<? extends T> i) {
    ArrayList<T> result = toArrayList(i);
    result.trimToSize();//from  w  w  w .j  a  va  2s .  co  m
    return Collections.unmodifiableList(result);
}

From source file:Main.java

/**
 * @return an <b>UNMODIFIABLE</b> List&lt;T&gt;
 *//*from  w  w  w .ja v a2 s. c om*/
public static <T> List<T> unmodifiableList(final List<? extends T> l) {
    return (l == null) ? Collections.<T>emptyList() : Collections.unmodifiableList(l);
}

From source file:com.trenako.utility.Utils.java

/**
 * Creates an immutable {@code ArrayList} filled with
 * the {@code Iterable} elements./*  w ww  .j  a  va2 s .c  o  m*/
 *
 * @param elements the elements to be added
 * @return the {@code ArrayList}
 */
public static <E> List<E> newList(final Iterable<E> elements) {
    List<E> list = new ArrayList<>();
    for (E el : elements) {
        list.add(el);
    }
    return Collections.unmodifiableList(list);
}

From source file:Main.java

/**
 * Returns a read-only list. The list is backed by the original so no copy is made.
 *
 * @param <T> The type of the list
 * @param list The list or null./*  w w  w .  j  a va2 s  .c  om*/
 * @return A read-only proxy on the original list.
 */
public static <T> List<T> asReadOnlyList(List<T> list) {
    if (list == null) {
        list = new ArrayList<>();
    }
    return Collections.unmodifiableList(list);
}

From source file:Main.java

public static <E> Collection<List<E>> selectUpTo(List<E> original, int nb) {
    final List<List<E>> result = new ArrayList<List<E>>();
    for (int i = 1; i <= nb; i++) {
        result.addAll(selectExactly(original, i));
    }/*from   w w  w .j a v a2  s .c  om*/
    return Collections.unmodifiableList(result);
}

From source file:Main.java

/**
 * Wraps a List with the {@code Collections.unmodifiableList}, but only once.
 *
 * <p>Checks the {@link List} passed to ensure that it is not already a {@code Collections.unmodifiableLisy}.
 * If the parameter is a null or empty, then it returns {@code Collections.emptyList}.
 *
 * @param list {@link List} to wrap with {@code Collections.unmodifiableList}
 * @param <V>  Value type//w w w  . ja v  a 2  s.c o m
 * @return An unmodifiable List.
 */
public static <V> List<V> unmodifiableList(final List<V> list) {
    if (isNotEmpty(list)) {
        if (!(exampleUnmodifiableList.getClass().equals(list.getClass()))) {
            return Collections.unmodifiableList(list);
        }
        return list;
    }
    return Collections.emptyList();
}