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

public static <V> List<V> getOddIndexedValuesFrom(Collection<V> arg) {
    if (null == arg || arg.isEmpty()) {
        return Collections.EMPTY_LIST;
    }/*from   w w  w . j a v  a2 s .  c om*/
    return getIndexedValuesFrom(arg, 1);
}

From source file:Main.java

public static <A> List<A> reverse(List<A> as) {
    return reverse(as, Collections.EMPTY_LIST);
}

From source file:Main.java

public static <A> List<A> reverseWithFoldl(List<A> as) {
    return foldl(as, Collections.EMPTY_LIST, acc -> a -> cons(a, acc));
}

From source file:Main.java

/**
 * Returns an iterator on a collection even null.
 * @param collection Collection//from  www  . j a v a  2  s .co  m
 * @return Iterator
 */
public static Iterator iterator(Collection collection) {
    if (collection == null) {
        return Collections.EMPTY_LIST.iterator();
    } else {
        return collection.iterator();
    }
}

From source file:Main.java

private static <V> List<V> getIndexedValuesFrom(Collection<V> arg, int initial) {
    if (null == arg || arg.isEmpty()) {
        return Collections.EMPTY_LIST;
    }/*from  w w  w . j  a  va2  s.  c  o  m*/

    List<V> indexed = new ArrayList<V>();

    for (V each : arg) {
        initial++;
        if (initial % 2 == 0) {
            continue;
        }
        indexed.add(each);
    }
    return indexed;
}

From source file:Main.java

/**
 * Returns a collection with fast contains() implementation. The collection
 * is intended to be reusable, a single use will not be efficient. Most
 * efficient with primitive objects (String, Integer...)
 */// ww  w .j  a  va2  s  .  c o  m
@SuppressWarnings("unchecked")
public static <T> Collection<T> fastSearchCollection(T... arr) {
    final int size = arr.length;
    if (size == 0)
        return Collections.EMPTY_LIST;

    if (size == 1)
        Collections.singletonList(arr[0]);

    // optimization for short list, avoid hash
    if (size <= 8) {
        return Arrays.asList(arr);
    }
    // big lists, use hash (constant time)
    return new HashSet<T>(Arrays.asList(arr));
}

From source file:Main.java

/**
 * As long as the predicate is happy, grind and append results to result list
 *
 * @param seed - initial input to predicate (and to grinder)
 * @param grinder - grinder(seed) gets appended to result
 * @param predicate - predicate(seed) tells whether to keep grinding
 * @return result list/*from   w  w w  .  ja  v  a2  s  . co  m*/
 */
public static <A> List<A> unfold(A seed, Function<A, A> grinder, Function<A, Boolean> predicate) {
    List<A> result = Collections.EMPTY_LIST;
    A counter = seed;
    while (predicate.apply(counter)) {
        result = append(counter, result);
        counter = grinder.apply(counter);
    }
    return Collections.unmodifiableList(result);
}

From source file:Main.java

public static List<String> getElementTextList(final Element eElement, final String name) {
    NodeList nodeList = eElement.getElementsByTagName(name);
    if (nodeList != null && nodeList.getLength() > 0) {
        int length = nodeList.getLength();
        List<String> nodeItems = new ArrayList<String>();
        for (int index = 0; index < length; ++index) {
            nodeItems.add(nodeList.item(index).getTextContent().trim());
        }//ww w. j  a v a  2s  .co m
        return nodeItems;
    }

    return Collections.EMPTY_LIST;
}

From source file:com.yoncabt.abys.core.util.Util.java

public static List<Integer> parseSequence(String sequence, int maxCount) {
    if (StringUtils.isBlank(sequence)) {
        return Collections.EMPTY_LIST;
    }//from w  ww  .j av a  2 s  .c o m
    List<Integer> ret = new ArrayList<>();
    for (String item : sequence.split(",")) {
        if (item.contains("-")) {
            String[] split = item.split("-");
            int start = Integer.parseInt(split[0]);
            int end = Integer.parseInt(split[1]);
            for (int i = start; start < end && i <= end; i++) {
                ret.add(i);
                if (ret.size() > maxCount) {
                    throw new IllegalArgumentException(sequence);
                }
            }
        } else {
            ret.add(Integer.parseInt(item));
            if (ret.size() > maxCount) {
                throw new IllegalArgumentException(sequence);
            }
        }
    }
    return ret;
}

From source file:Main.java

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