Example usage for java.util Collections EMPTY_LIST

List of usage examples for java.util Collections EMPTY_LIST

Introduction

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

Prototype

List EMPTY_LIST

To view the source code for java.util Collections EMPTY_LIST.

Click Source Link

Document

The empty list (immutable).

Usage

From source file:Main.java

/**
 * Build a List from the entry set of a map.
 * //from   w w w.  j ava  2 s  .c o m
 *  <p>
 * NOTE: This should not be necessary but there are bugs
 * when you iterate using map.entrySet().iterator().
 * </p>
 * 
 * @param map the map to use as the source
 * @param sortedByValue whether or not to sort the values
 * of the created list
 * @return a list containing all values of the given
 * map
 */
public static List mapToEntryList(Map map, boolean sortedByValue) {
    List retList = new ArrayList();
    if (map.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    Iterator it = map.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        Object obj = map.get(key);
        retList.add(obj);
    }

    // Sort
    if (sortedByValue)
        Collections.sort(retList);
    return retList;
}

From source file:com.epam.training.storefront.controllers.util.CartHelper.java

public static List<OrderEntryData> removeEmptyEntries(final List<OrderEntryData> allEntries) {
    if (CollectionUtils.isEmpty(allEntries)) {
        return Collections.EMPTY_LIST;
    }//from w  w w. j  a v a  2 s. com

    final List<OrderEntryData> realEntries = new ArrayList<OrderEntryData>();
    for (final OrderEntryData entry : allEntries) {
        if (entry.getProduct() != null) {
            realEntries.add(entry);
        }
    }

    if (CollectionUtils.isEmpty(realEntries)) {
        return Collections.EMPTY_LIST;
    } else {
        return realEntries;
    }
}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static List subviews(Object o) {

    try {/*from  w  ww .  j  a va2 s. c  o  m*/
        Method getChild = o.getClass().getMethod("getChildAt", int.class);
        getChild.setAccessible(true);
        Method getChildCount = o.getClass().getMethod("getChildCount");
        getChildCount.setAccessible(true);
        List result = new ArrayList(8);
        int childCount = (Integer) getChildCount.invoke(o);
        for (int i = 0; i < childCount; i++) {
            result.add(getChild.invoke(o, i));
        }
        return result;

    } catch (NoSuchMethodException e) {
        return Collections.EMPTY_LIST;
    } catch (IllegalArgumentException e) {
        return Collections.EMPTY_LIST;
    } catch (IllegalAccessException e) {
        return Collections.EMPTY_LIST;
    } catch (InvocationTargetException e) {
        return Collections.EMPTY_LIST;
    }

}

From source file:Main.java

/** @return a new {@link ArrayList} from given collection 
 * (a null collection is considered as if it's an empty one). */
public static <E> ArrayList<E> createArrayList(Collection<? extends E> collection) {
    return new ArrayList<E>(collection == null ? Collections.EMPTY_LIST : collection);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> List<T> emptyList(Class<T> type) {
    return Collections.EMPTY_LIST;
}

From source file:Main.java

@SuppressWarnings({ "unchecked" })
public static <E> List<E> asList(E... elements) {
    if (elements == null || elements.length == 0) {
        return Collections.EMPTY_LIST;
    }//from  w ww  .jav  a  2  s. co m
    // Avoid integer overflow when a large array is passed in
    int capacity = computeListCapacity(elements.length);
    ArrayList<E> list = new ArrayList<E>(capacity);
    Collections.addAll(list, elements);
    return list;
}

From source file:Main.java

/** @return given list if it's non-null, an empty List otherwise.
 * The returned list cannot be modified. */
public static <E> List<E> nullToEmpty(List<E> list) {
    return list == null ? Collections.EMPTY_LIST : list;
}

From source file:Main.java

/**
 * /*from  www .ja  va  2 s . c om*/
 * 
 */
@SuppressWarnings("unchecked")
public static <T> Collection<T> emptyCollection() {
    return Collections.EMPTY_LIST;
}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static List parents(Object o) {
    try {//w w  w  . j  a va 2 s .co  m

        Method getParent = o.getClass().getMethod("getParent");
        getParent.setAccessible(true);

        List result = new ArrayList(8);
        try {
            while (true) {
                Object parent = getParent.invoke(o);
                if (parent == null) {
                    return result;
                } else {
                    result.add(parent);
                }
                o = parent;
            }
        } catch (IllegalArgumentException e) {
            return result;
        } catch (IllegalAccessException e) {
            return result;
        } catch (InvocationTargetException e) {
            return result;
        }

    } catch (NoSuchMethodException e) {
        return Collections.EMPTY_LIST;
    }

}

From source file:Main.java

/**
 * Splits list into several sub-lists according to predicate.
 * @param <T>/*from  w w  w .  j a  v a  2  s .co  m*/
 * @param list
 * @param predicate
 * @return 
 */
public static final <T> List<List<T>> split(List<T> list, Predicate<T> predicate) {
    if (list.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    List<List<T>> lists = new ArrayList<>();
    boolean b = predicate.test(list.get(0));
    int len = list.size();
    int start = 0;
    for (int ii = 1; ii < len; ii++) {
        boolean t = predicate.test(list.get(ii));
        if (b != t) {
            lists.add(list.subList(start, ii));
            start = ii;
            b = t;
        }
    }
    lists.add(list.subList(start, len));
    return lists;
}