Example usage for java.util Collections emptyList

List of usage examples for java.util Collections emptyList

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public static final <T> List<T> emptyList() 

Source Link

Document

Returns an empty list (immutable).

Usage

From source file:Main.java

public static <T> List<T> list(final T... entries) {
    switch (entries.length) {
    case 0: {//from  ww  w .  jav  a2s  .c  o  m
        return Collections.emptyList();
    }
    case 1: {
        return Collections.singletonList(entries[0]);
    }
    default: {
        final List<T> result = new ArrayList<T>();

        for (T entry : entries) {
            result.add(entry);
        }

        return result;
    }
    }
}

From source file:Main.java

@NonNull
public static <T> List<T> getNonNull(List<T> value) {
    return value == null ? Collections.emptyList() : value;
}

From source file:Main.java

public static <T> List<T> minius(Collection<T> c1, Set<T> s1) {

    if (c1 == null) {
        return Collections.emptyList();
    }/*from w w w.  ja  v  a 2 s .  c  o  m*/

    if (s1 == null || s1.size() == 0) {
        return new ArrayList<T>(c1);
    }
    List<T> list = new ArrayList<T>();
    for (T t : c1) {
        if (!s1.contains(t)) {
            list.add(t);
        }
    }
    return list;
}

From source file:Main.java

public static <T> List<T> newList(T... values) {
    if (values == null) {
        return Collections.emptyList();
    }//from w w w.ja  va2  s .  c om

    return new ArrayList<T>(Arrays.asList(values));
}

From source file:Main.java

public static <T> List<T> safe(List<T> collection) {
    return collection == null ? Collections.emptyList() : collection;
}

From source file:Main.java

public static <T> List<T> asList(T... args) {
    if (args != null) {
        return Arrays.asList(args);
    }/*from  w w  w.j a  v a2 s.  c  o  m*/
    return Collections.emptyList();
}

From source file:Main.java

public static <T> List<T> asList(T... args) {
    if (args == null || args.length == 0) {
        return Collections.emptyList();
    } else {/* w  w  w.j a  va  2  s.c  om*/
        return Arrays.asList(args);
    }
}

From source file:Main.java

/**
 * Returns a {@link List} containing the elements of the given {@link List} from offset and only the given amount.
 * If there aren't enough elements in the given {@link List} for the requested amount the rest of the {@link List}
 * will returned. Returns null if the given {@link List} is null.
 *
 * @param list the {@link List} to get a sublist from.
 * @param offset start of elements to return
 * @param amount amount of elements to return
 * @return the sublist or null./* w  ww .jav  a 2s  .  c  om*/
 */
public static <T> List<T> subList(final List<T> list, final int offset, final int amount) {
    if (list == null) {
        return null;
    }

    if (offset >= list.size()) {
        return Collections.emptyList();
    }

    int toPos = offset + amount;
    if (toPos >= list.size()) {
        toPos = list.size();
    }

    return list.subList(offset, toPos);
}

From source file:Main.java

public static <T> Collection<T> ofNullableCollection(Collection<T> nullable) {
    return nullable == null ? Collections.emptyList() : nullable;
}

From source file:Main.java

public static List<Element> elements(Element element, String tagName) {
    if (element == null || !element.hasChildNodes()) {
        return Collections.emptyList();
    }/*from w  w  w.ja v  a  2 s.c  om*/

    List<Element> elements = new ArrayList<Element>();
    for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) child;
            String childTagName = childElement.getNodeName();
            if (tagName.equals(childTagName))
                elements.add(childElement);
        }
    }
    return elements;
}