Example usage for org.apache.commons.collections IteratorUtils toList

List of usage examples for org.apache.commons.collections IteratorUtils toList

Introduction

In this page you can find the example usage for org.apache.commons.collections IteratorUtils toList.

Prototype

public static List toList(Iterator iterator) 

Source Link

Document

Gets a list based on an iterator.

Usage

From source file:nl.tricode.magnolia.news.templates.NewsRenderableDefinition.java

/**
 * Get total number of news for current state.
 * (Performs additional JCR-SQL2 query to obtain count!)
 *
 * @param path Start node path in hierarchy
 * @return long Number of news/*from  w  w w . j a  v a  2s  .  c om*/
 */
public int getNewsCount(String path) throws RepositoryException {
    final String sqlNewsItems = buildQuery(path, NEWS_NODE_TYPE);
    return IteratorUtils.toList(QueryUtil.search(NewsWorkspaceUtil.COLLABORATION, sqlNewsItems, Query.JCR_SQL2,
            NewsNodeTypes.News.NAME)).size();
}

From source file:org.adaptto.rookie.demo.models.Discussion.java

@SuppressWarnings("unchecked")
public Discussion(Resource resource) {
    Resource commentsParent = resource.getChild("discussion");
    if (commentsParent != null) {
        this.comments = IteratorUtils.toList(commentsParent.listChildren());
    }//from  ww  w . java2  s.  c om
}

From source file:org.adaptto.rookie.demo.models.TagSearchController.java

@SuppressWarnings("unchecked")
public TagSearchController(SlingHttpServletRequest request) {
    Resource resource = request.getResource();
    ResourceResolver resolver = request.getResourceResolver();

    // get tag name to search for form suffix
    String suffix = request.getRequestPathInfo().getSuffix();
    this.tag = StringUtils.substringAfter(suffix, "/");

    // execute JCR query via Sling API
    String xpathQuery = "/jcr:root" + resource.getPath() + "//*[tags='" + this.tag + "']";
    this.result = IteratorUtils.toList(resolver.findResources(xpathQuery, "xpath"));
}

From source file:org.amanzi.awe.explorer.ui.provider.ExplorerContentProvider.java

@SuppressWarnings("unchecked")
@Override/*  w  ww .j  a v a 2s .c o m*/
public Object[] getElements(final Object inputElement) {
    final List<ITreeWrapper> wrappers = new ArrayList<ITreeWrapper>();

    final Iterator<ITreeWrapper> items = projectWrapperFactory.getWrappers(inputElement);
    if (items != null) {
        wrappers.addAll(IteratorUtils.toList(items));
    }

    return toObject(wrappers);
}

From source file:org.amanzi.awe.ui.tree.provider.AWETreeContentProvider.java

@SuppressWarnings("unchecked")
protected Object[] getElementsInternal(final Object inputElement) {
    treeWrappers.clear();//from   ww w.jav a 2 s .  c  o m

    for (final ITreeWrapperFactory factory : factories) {
        final Iterator<ITreeWrapper> items = factory.getWrappers(inputElement);
        if (items != null) {
            treeWrappers.addAll(IteratorUtils.toList(items));
        }
    }

    return toObject(treeWrappers);
}

From source file:org.amanzi.neo.services.impl.NodeServiceIntegrationTest.java

@Test
public void testCheckGetAllNodes() throws Exception {
    Node parent = createNode();/*from  w w  w  .  j a  va 2s .  co m*/
    createChildren(NodeService.NodeServiceRelationshipType.CHILD, TestNodeType.TEST_NODE_TYPE1, parent);

    Iterator<Node> result = nodeService.getChildren(parent, TestNodeType.TEST_NODE_TYPE1);

    assertNotNull(RESULT_OF_SEARCH_SHOULD_NOT_BE_NULL, result);

    @SuppressWarnings("unchecked")
    List<Node> resultList = IteratorUtils.toList(result);

    assertEquals("Unexpected size of children", CHILDREN_NAMES.length, resultList.size());

    for (Node node : resultList) {
        String name = (String) node.getProperty(GENERAL_NODE_PROPERTIES.getNodeNameProperty());

        assertTrue("name should exists in original children names", ArrayUtils.contains(CHILDREN_NAMES, name));
    }
}

From source file:org.amanzi.neo.services.impl.NodeServiceIntegrationTest.java

@Test
public void testCheckGetAllNodesWithMixedRelTypes() throws Exception {
    Node parent = createNode();// w  ww .j  a  v  a  2 s .c  o  m
    createChildren(NodeService.NodeServiceRelationshipType.CHILD, TestNodeType.TEST_NODE_TYPE1, parent);
    createChildren(TestRelatinshipType.TEST_REL, TestNodeType.TEST_NODE_TYPE1, parent);

    Iterator<Node> result = nodeService.getChildren(parent, TestNodeType.TEST_NODE_TYPE1);

    assertNotNull(RESULT_OF_SEARCH_SHOULD_NOT_BE_NULL, result);

    @SuppressWarnings("unchecked")
    List<Node> resultList = IteratorUtils.toList(result);

    assertEquals("Unexpected size of childrent", CHILDREN_NAMES.length, resultList.size());

    for (Node node : resultList) {
        String name = (String) node.getProperty(GENERAL_NODE_PROPERTIES.getNodeNameProperty());

        assertTrue("name should exists in original children names", ArrayUtils.contains(CHILDREN_NAMES, name));
    }
}

From source file:org.amanzi.neo.services.impl.NodeServiceIntegrationTest.java

@Test
public void testCheckGetAllNodesWithMixedNodeTypes() throws Exception {
    Node parent = createNode();/*from ww w  .  j  av  a 2 s  .  c om*/
    createChildren(NodeService.NodeServiceRelationshipType.CHILD, TestNodeType.TEST_NODE_TYPE1, parent);
    createChildren(NodeService.NodeServiceRelationshipType.CHILD, TestNodeType.TEST_NODE_TYPE2, parent);

    Iterator<Node> result = nodeService.getChildren(parent, TestNodeType.TEST_NODE_TYPE1);

    assertNotNull(RESULT_OF_SEARCH_SHOULD_NOT_BE_NULL, result);

    @SuppressWarnings("unchecked")
    List<Node> resultList = IteratorUtils.toList(result);

    assertEquals("Unexpected size of childrent", CHILDREN_NAMES.length, resultList.size());

    for (Node node : resultList) {
        String name = (String) node.getProperty(GENERAL_NODE_PROPERTIES.getNodeNameProperty());

        assertTrue("name should exists in original children names", ArrayUtils.contains(CHILDREN_NAMES, name));
    }
}

From source file:org.apache.brooklyn.launcher.BrooklynLauncherRebindCatalogTest.java

private static <T> boolean compareIterablesWithoutOrderMatters(Iterable<T> a, Iterable<T> b) {
    List<T> aList = IteratorUtils.toList(a.iterator());
    List<T> bList = IteratorUtils.toList(b.iterator());

    return aList.containsAll(bList) && bList.containsAll(aList);
}

From source file:org.apache.drill.exec.server.options.SystemOptionManager.java

@Override
public OptionList getOptionList() {
    return (OptionList) IteratorUtils.toList(iterator());
}