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

/**
 * This method returns a new ArrayList which is the intersection of the two List parameters, based on {@link Object#equals(Object) equality}
 * of their elements.// w  ww.  jav  a  2 s . c  o m
 * The intersection list will contain elements in the order they have in list1 and any references in the resultant list will be
 * to elements within list1 also.
 * 
 * @return a new ArrayList whose values represent the intersection of the two Lists.
 */
public static <T> List<T> intersect(List<? extends T> list1, List<? extends T> list2) {
    if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty()) {
        return Collections.emptyList();
    }

    List<T> result = new ArrayList<T>();
    result.addAll(list1);

    result.retainAll(list2);

    return result;
}

From source file:curly.commons.web.hateoas.PageProcessor.java

public static <T> Page<T> toPage(PagedResources<T> res) {
    Assert.notNull(res, "Resources content must be not null");
    PageMetadata metadata = res.getMetadata();
    if (res.getContent().isEmpty())
        return new PageImpl<T>(Collections.emptyList());
    return new PageImpl<>(new ArrayList<>(res.getContent()),
            new PageRequest((int) metadata.getNumber(), (int) metadata.getSize()), metadata.getTotalElements());
}

From source file:com.laxser.blitz.web.impl.mapping.MappingFactory.java

public static List<Mapping> parse(String path) {

    ///* w  ww.  j a  va2  s  .com*/
    if (path.equals("/")) {
        path = "";
    } else if (path.length() > 0 && path.charAt(0) != '/') {
        path = "/" + path;
    }
    if (path.length() > 1 && path.endsWith("/")) {
        if (path.endsWith("//")) {
            throw new IllegalArgumentException(
                    "invalid path '" + path + "' : don't end with more than one '/'");
        }
        path = path.substring(0, path.length() - 1);
    }

    if (path.length() == 0) {
        return Collections.emptyList();
    }

    List<Mapping> mappings = new ArrayList<Mapping>(8);

    //

    char[] chars = new char[path.length()];
    path.getChars(0, path.length(), chars, 0);
    int paramBegin = -1;
    int paramNameEnd = -1;
    int constantBegin = -1;
    int bracketDeep = 0; // > 0 ?{}?
    boolean startsWithBracket = true;
    for (int i = 0; i < chars.length; i++) {
        switch (chars[i]) {
        case '$':
            if (i + 1 >= chars.length) {
                throw new IllegalArgumentException(//
                        "invalid string '" + path + "', don't end with '$'");
            }
            // constains$name"constains"
            if (constantBegin >= 0) {
                mappings.add(createConstantMapping(path, constantBegin, i));
                constantBegin = -1;
            }
            // $name$xyz"$name"
            if (paramBegin >= 0) {
                mappings.add(createRegexMapping(path, paramBegin, paramNameEnd, i));
                paramBegin = -1;
                paramNameEnd = -1;
            }
            if (chars[i + 1] != '{') {
                paramBegin = i + 1;
                bracketDeep = 1;
                startsWithBracket = false;
            }
            break;
        case '{':
            if (bracketDeep++ > 0) { //++?
                break;
            }
            if (paramBegin < 0) {
                paramBegin = i + 1;
            }
            // $name{xyz}"$name"
            else {
                mappings.add(createRegexMapping(path, paramBegin, paramNameEnd, i));
                paramBegin = -1;
                paramNameEnd = -1;
            }
            // constains{name}"constains"
            if (constantBegin >= 0) {
                mappings.add(createConstantMapping(path, constantBegin, i));
                constantBegin = -1;
            }
            break;
        case ':':
            if (paramBegin < 0) {
                throw new IllegalArgumentException(//
                        "invalid string '" + path + "', wrong ':' at position " + i);
            } else if (paramNameEnd > 0) {
                throw new IllegalArgumentException(//
                        "invalid string '" + path + "', duplicated ':' at position " + i);
            } else {
                paramNameEnd = i;
            }
            break;
        case '}':
            if (--bracketDeep > 0) { // --?
                break;
            }
            if (paramBegin < 0) {
                throw new IllegalArgumentException(//
                        "invalid string '" + path + "', wrong '}' at position " + i);
            } else {
                mappings.add(createRegexMapping(path, paramBegin, paramNameEnd, i));
                paramBegin = -1;
                paramNameEnd = -1;
            }
            break;
        case '/':
            if (paramBegin < 0) {
                if (constantBegin >= 0) {
                    mappings.add(createConstantMapping(path, constantBegin, i));
                }
                constantBegin = i;
                break;
            } else if (bracketDeep == 0 || (bracketDeep == 1 && !startsWithBracket)) {
                mappings.add(createRegexMapping(path, paramBegin, paramNameEnd, i));
                paramBegin = -1;
                constantBegin = i;
                paramNameEnd = -1;
                bracketDeep = 0;
                break;
            }

        default:
            if (constantBegin == -1 && paramBegin == -1) {
                constantBegin = i;
            }
            break;
        }
    }
    if (constantBegin >= 0) {
        mappings.add(createConstantMapping(path, constantBegin, chars.length));
        constantBegin = -1;
    }
    if (paramBegin >= 0) {
        mappings.add(createRegexMapping(path, paramBegin, paramNameEnd, chars.length));
        paramBegin = -1;
        paramNameEnd = -1;
    }
    return mappings;
}

From source file:Main.java

/**
 * Returns the child nodes of the passed node where the type of the child node is in the passed array of type codes
 * @param node The node to return the child nodes of
 * @param types The short codes for the node types
 * @return a [possibly empty] list of nodes
 *//*from  w  w w.j a  v  a2  s. com*/
public static List<Node> getChildNodes(final Node node, short... types) {
    if (node == null)
        return Collections.emptyList();
    if (types == null || types.length == 0)
        return Collections.emptyList();
    final List<Node> nodes = new ArrayList<Node>();
    for (Node n : nodeListToList(node.getChildNodes())) {
        if (Arrays.binarySearch(types, n.getNodeType()) >= 0) {
            nodes.add(n);
        }
    }
    return nodes;
}

From source file:com.headissue.pigeon.util.JPAUtils.java

/**
 * Returns a list of entities. Note: it returns always a list, never null.
 *//* w w w .  ja  va 2 s .c o m*/
public static <T> List<T> getResultList(TypedQuery<T> q) {
    try {
        return q.getResultList();
    } catch (Exception e) {
        LogUtils.trace(log, e, "access to a list of entities is failed");
        return Collections.emptyList();
    }
}

From source file:com.namelessdev.mpdroid.cover.MusicBrainzCover.java

private static Collection<String> extractImageUrls(final String covertArchiveResponse) {
    final JSONObject jsonRootObject;
    final JSONArray jsonArray;
    String coverUrl;/*from ww  w .  j  a v  a  2s  .  c o  m*/
    JSONObject jsonObject;
    final Collection<String> coverUrls = new ArrayList<>();

    if (covertArchiveResponse == null || covertArchiveResponse.isEmpty()) {
        return Collections.emptyList();
    }

    try {
        jsonRootObject = new JSONObject(covertArchiveResponse);
        if (jsonRootObject.has("images")) {

            jsonArray = jsonRootObject.getJSONArray("images");
            for (int i = 0; i < jsonArray.length(); i++) {
                jsonObject = jsonArray.getJSONObject(i);
                if (jsonObject.has("image")) {
                    coverUrl = jsonObject.getString("image");
                    if (coverUrl != null) {
                        coverUrls.add(coverUrl);
                    }
                }
            }
        }
    } catch (final Exception e) {
        Log.e(TAG, "No cover in CovertArchive.", e);
    }

    return coverUrls;

}

From source file:com.trenako.results.PaginatedLists.java

private static <T> Page<T> failbackPage() {
    List<T> empty = Collections.emptyList();
    return new PageImpl<>(empty);
}

From source file:me.ferrybig.javacoding.webmapper.test.session.DefaultDataStorageTest.java

@Test
public void setAndGetDataTest() {
    data.setData(Collections.emptyList());
    assertEquals(0, data.getData().size());
    data.setData(Collections.singleton(new Object()));
    assertEquals(1, data.getData().size());
}

From source file:com.greglturnquist.EmployeeRepository.java

public List<Employee> findAll() {
    return Collections.emptyList();
}

From source file:fi.jumi.core.config.SuiteConfiguration.java

public SuiteConfiguration() {
    classpath = Collections.emptyList();
    jvmOptions = Collections.emptyList();
    workingDirectory = Paths.get(".").normalize().toUri();
    includedTestsPattern = "glob:**Test.class";
    excludedTestsPattern = "glob:**$*.class";
}