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

/**
 * Return list of content Strings of all child elements with given tag name.
 * @param elem/*from   ww w .  ja  v  a  2s.  c  o  m*/
 * @param childTagName
 * @return List 
 */
public static List getChildTextList(Element elem, String childTagName) {
    NodeList nodeList = elem.getElementsByTagName(childTagName);
    int len = nodeList.getLength();
    if (len == 0) {
        return Collections.EMPTY_LIST;
    } else {
        List list = new ArrayList(len);
        for (int i = 0; i < len; i++) {
            list.add(getElementText((Element) nodeList.item(i)));
        }
        return list;
    }
}

From source file:Main.java

/**
 * Return list of content Strings of all child elements with given tag name.
 * @param elem//from w w  w  .  j  a va 2  s .  co m
 * @param childTagName
 * @return List 
 */
public static List getChildTextList(Element elem, String childTagName) {
    NodeList nodeList = elem.getElementsByTagName(childTagName);
    int len = nodeList.getLength();
    if (len == 0) {
        return Collections.EMPTY_LIST;
    }

    List list = new ArrayList(len);
    for (int i = 0; i < len; i++) {
        list.add(getElementText((Element) nodeList.item(i)));
    }
    return list;

}

From source file:Main.java

protected static List<Type> getGenericParameterList(Type type) {
    if (ParameterizedType.class.isInstance(type)) {
        final ParameterizedType paramType = ParameterizedType.class.cast(type);
        return Arrays.asList(paramType.getActualTypeArguments());
    }//  w w  w . j  a v a 2 s  . c o m
    if (GenericArrayType.class.isInstance(type)) {
        final GenericArrayType arrayType = GenericArrayType.class.cast(type);
        return getGenericParameterList(arrayType.getGenericComponentType());
    }
    @SuppressWarnings("unchecked")
    List<Type> emptyList = Collections.EMPTY_LIST;
    return emptyList;
}

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 as it
 * allocates memory for the new collection.
 * /*w w  w  . j a v a2  s . c  o  m*/
 * Most efficient with primitive objects (String, Integer...)
 */
@SuppressWarnings("unchecked")
public static <T> Collection<T> fastSearchCollection(List<T> list) {
    final int size = list.size();
    if (size == 0)
        return Collections.EMPTY_LIST;

    if (size == 1)
        Collections.singletonList(list.get(0));

    // optimization for short list, avoid hash
    if (size <= 8) {
        if (list instanceof ArrayList)
            // ArrayList similar to Arrays for short lists, save some
            // memory.
            return (ArrayList<T>) list;

        // not ArrayList, play safe with final array type list
        T[] s = (T[]) list.toArray();
        return Arrays.asList(s);
    }
    // big lists, use hash (constant time)
    return new HashSet<T>(list);
}

From source file:com.manisha.allmybooksarepacked.utility.JSONUtils.java

@SuppressWarnings("unchecked")
public static <T> List<T> JSONToObjectList(String json, Class<T> elementClass) throws IOException {
    if (StringUtils.isBlank(json))
        return (List<T>) Collections.EMPTY_LIST;
    return mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, elementClass));
}

From source file:com.xwiki.authentication.guanxi.StringUtils.java

/**
 *  Turn a long string into a list split by our delimeter
 *
 *  @param String comma separated list// w  w w .  j a v  a 2  s. c o  m
 *  @return List a list of strings
 */
public static List toListDelimitedByComma(String s) {
    if (s == null)
        return Collections.EMPTY_LIST;

    List results = new ArrayList();

    String[] terms = s.split(DELIMETER);

    for (int i = 0; i < terms.length; i++) {
        String term = terms[i].trim();
        if (term.length() > 0) {
            results.add(term);
        }
    }
    return results;
}

From source file:io.lightlink.utils.ClasspathScanUtils.java

private static List<String> getResourcesFromWebInf(String packageName, ServletContext servletContext) {

    if (servletContext == null)
        return Collections.EMPTY_LIST;

    List<String> res = new ArrayList<String>();

    findFromServletContext(servletContext, "/WEB-INF/" + packageName.replace('.', '/') + "/", "", res);

    return res;/* ww w .j  a va2s.  co m*/
}

From source file:com.baifendian.swordfish.common.utils.CommonUtil.java

/**
 * sql ?, ?, ?? ";"//from   www . j ava  2s  .c  o m
 */
public static List<String> sqlSplit(String sql) {
    if (StringUtils.isEmpty(sql)) {
        return Collections.EMPTY_LIST;
    }

    List<String> r = new ArrayList<>();

    Status status = Status.START;
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < sql.length(); ++i) {
        char c = sql.charAt(i);
        char nextChar = ((i + 1) < sql.length()) ? sql.charAt(i + 1) : ' '; // add at 2017/1/6

        boolean skip = false;

        switch (status) {
        case START: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            }
        }
            break;
        case BLANK: {
            if (c == ';') {
                status = Status.END;
                skip = true; //  ;
            } else if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (!Character.isWhitespace(c)) {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case END: {
            if (c == '"') {
                status = Status.QUOTE;
            } else if (c == '\'') {
                status = Status.SINGLE_QUOTE;
            } else if (Character.isWhitespace(c)) {
                status = Status.BLANK;
            } else if (c == '-' && nextChar == '-') { // add at 2017/1/6)
                status = Status.COMMENT;
                ++i; // add at 2017/1/6
                skip = true;
            } else if (c != ';') {
                status = Status.START;
            } else {
                skip = true;
            }
        }
            break;
        case QUOTE: {
            if (c == '"') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_QUOTE;
            }
        }
            break;
        case SINGLE_QUOTE: {
            if (c == '\'') {
                status = Status.START;
            } else if (c == '\\') {
                status = Status.BACKSLASH_FOR_SINGLE_QUOTE;
            }
        }
            break;
        case BACKSLASH_FOR_QUOTE: {
            status = Status.QUOTE;
        }
            break;
        case BACKSLASH_FOR_SINGLE_QUOTE: {
            status = Status.SINGLE_QUOTE;
        }
            break;
        case COMMENT: {
            if (c != '\r' && c != '\n') {
                status = Status.COMMENT;
                skip = true;
            } else {
                status = Status.START;
            }
        }
            break;
        }

        if (!skip) {
            //  white space ??
            if (Character.isWhitespace(c)) {
                buffer.append(' ');
            } else {
                buffer.append(c);
            }
        }

        if (status == Status.END) {
            String sub = buffer.toString();
            if (!StringUtils.isWhitespace(sub)) {
                r.add(sub.trim());
            }
            buffer = new StringBuffer();
        }
    }

    String sub = buffer.toString();
    if (!StringUtils.isWhitespace(sub)) {
        r.add(sub.trim());
    }

    return r;
}

From source file:com.yahoo.druid.brokerui.DruidUIModule.java

@Override
public List<? extends Module> getJacksonModules() {
    return Collections.EMPTY_LIST;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.EmptyReifier.java

@Override
public ExtendedIterator<Node> allNodes() {
    return WrappedIterator.create(Collections.EMPTY_LIST.iterator());
}