Example usage for com.google.common.collect Iterators emptyIterator

List of usage examples for com.google.common.collect Iterators emptyIterator

Introduction

In this page you can find the example usage for com.google.common.collect Iterators emptyIterator.

Prototype

@Deprecated
public static <T> UnmodifiableIterator<T> emptyIterator() 

Source Link

Document

Returns the empty iterator.

Usage

From source file:presto.android.gui.FixpointSolver.java

public Iterator<NOpNode> findProducers(NNode objectNode) {
    Set<NOpNode> set = viewProducers.get(objectNode);
    if (set == null || set.isEmpty()) {
        return Iterators.emptyIterator();
    } else {/*from  w w w . ja  va  2s .  c om*/
        return set.iterator();
    }
}

From source file:org.apache.phoenix.util.ScanUtil.java

public static Iterator<Filter> getFilterIterator(Scan scan) {
    Iterator<Filter> filterIterator;
    Filter topLevelFilter = scan.getFilter();
    if (topLevelFilter == null) {
        filterIterator = Iterators.emptyIterator();
    } else if (topLevelFilter instanceof FilterList) {
        filterIterator = ((FilterList) topLevelFilter).getFilters().iterator();
    } else {/*from w w  w  .  j  av a 2  s. c o  m*/
        filterIterator = Iterators.singletonIterator(topLevelFilter);
    }
    return filterIterator;
}

From source file:org.apache.marmotta.commons.sesame.repository.ResourceUtils.java

/**
 * List outgoing edges from this resource to other resources, using the property label passed
 * as argument. If limit is bigger than 0, then a maximum of limit triples will be returned.
 * Otherwise, all triples will be returned.
 * <p/>//w  w  w  .  j  a va  2 s .c o m
 * The parameter propLabel is in the form of a SeRQL or SPARQL id. It can take one of the following
 * values:
 * <ul>
 * <li>a URI enclosed in &lt; &gt, e.g. &lt;http://www.example.com/myProp&gt;</li>
 * <li>a uri prefix, followed by a colon and the property name, e.g. ex:myProp</li>
 * <li>the value "null", in which case all outgoing edges are listed regardless of their label
 * (wildcard)</li>
 * </ul>
 * The result will be an iterable that allows to iterate over Statements. The underlying ClosableIteration will be closed when the last element has
 * been consumed.
 *
 * @param propLabel the label of the property to be queried, or null for wildcard
 * @param context   outgoing triples just for the given space
 * @return an iterable over the Statements that are outgoing edges of this resource
 */
public static Iterable<? extends Statement> listOutgoing(final RepositoryConnection con, final Resource r,
        final String propLabel, final URI context) throws RepositoryException {
    final URI property;
    if (propLabel != null) {
        String prop_uri = resolvePropLabel(con, propLabel);
        if (prop_uri == null) {
            return Collections.emptySet();
        } else {
            property = con.getValueFactory().createURI(prop_uri);
        }
    } else {
        property = null;
    }

    final Resource[] contexts;
    if (context != null) {
        contexts = new Resource[] { context };
    } else {
        contexts = new Resource[0];
    }

    return new Iterable<Statement>() {
        @Override
        public Iterator<Statement> iterator() {
            try {
                return ResultUtils.unwrap(con.getStatements(r, property, null, true, contexts));
            } catch (RepositoryException ex) {
                ExceptionUtils.handleRepositoryException(ex, ResourceUtils.class);
                return Iterators.emptyIterator();
            }
        }
    };
}

From source file:org.apache.marmotta.commons.sesame.repository.ResourceUtils.java

/**
 * List incoming edges from other resources to this resource, using the property label passed
 * as argument. If limit is bigger than 0, then a maximum of limit triples will be returned.
 * Otherwise, all triples will be returned.
 * <p/>/*  w w w  .  j  av  a  2 s.  com*/
 * The parameter propLabel is in the form of a SeRQL or SPARQL id. It can take one of the following
 * values:
 * <ul>
 * <li>a URI enclosed in &lt; &gt, e.g. &lt;http://www.example.com/myProp&gt;</li>
 * <li>a uri prefix, followed by a colon and the property name, e.g. ex:myProp</li>
 * <li>the value "null", in which case all outgoing edges are listed regardless of their label
 * (wildcard)</li>
 * </ul>
 * The result will be an iterable that allows to iterate over Statements.
 *
 * @param propLabel the label of the property to be queried, or null for wildcard
 * @param r         the maximum number of triples to retrieve
 * @param context   incoming resources just for the given context/space
 * @return an iterable over the Statements that are incoming edges of this resource
 */
public static Iterable<? extends Statement> listIncoming(final RepositoryConnection con, final Resource r,
        final String propLabel, final URI context) throws RepositoryException {
    final URI property;
    if (propLabel != null) {
        String prop_uri = resolvePropLabel(con, propLabel);
        if (prop_uri == null) {
            return Collections.emptySet();
        } else {
            property = con.getValueFactory().createURI(prop_uri);
        }
    } else {
        property = null;
    }

    final Resource[] contexts;
    if (context != null) {
        contexts = new Resource[] { context };
    } else {
        contexts = new Resource[0];
    }

    return new Iterable<Statement>() {
        @Override
        public Iterator<Statement> iterator() {
            try {
                return ResultUtils.unwrap(con.getStatements(null, property, r, true, contexts));
            } catch (RepositoryException ex) {
                ExceptionUtils.handleRepositoryException(ex, ResourceUtils.class);
                return Iterators.emptyIterator();
            }
        }
    };
}

From source file:org.apache.jackrabbit.oak.jcr.session.NodeImpl.java

@Nonnull
private Iterator<String> getMixinTypeNames(@Nonnull Tree tree) throws RepositoryException {
    Iterator<String> mixinNames = Iterators.emptyIterator();
    if (tree.hasProperty(JcrConstants.JCR_MIXINTYPES) || canReadProperty(tree, JcrConstants.JCR_MIXINTYPES)) {
        mixinNames = TreeUtil.getNames(tree, JcrConstants.JCR_MIXINTYPES).iterator();
    } else if (tree.getStatus() != Status.NEW) {
        // OAK-2441: for backwards compatibility with Jackrabbit 2.x try to
        // read the primary type from the underlying node state.
        mixinNames = TreeUtil//from  ww  w  .j a  v a  2 s  . c om
                .getNames(RootFactory.createReadOnlyRoot(sessionDelegate.getRoot()).getTree(tree.getPath()),
                        JcrConstants.JCR_MIXINTYPES)
                .iterator();
    }
    return mixinNames;
}

From source file:org.apache.marmotta.commons.sesame.repository.ResourceUtils.java

/**
 * Return the list of types as Resources that are associated with this resource using the
 * rdf:type RDF property./*from w ww.  ja v  a 2  s  . com*/
 *
 * @return an iterable of Resource instances that represent the RDF types of this resource
 */
public static Iterable<? extends Resource> getTypes(final RepositoryConnection con, final Resource r,
        Resource context) throws RepositoryException {
    final URI rdf_type = con.getValueFactory().createURI(Namespaces.NS_RDF + "type");

    if (rdf_type != null) {
        final Resource[] contexts;
        if (context != null) {
            contexts = new Resource[] { context };
        } else {
            contexts = new Resource[0];
        }

        return Iterables.transform(Iterables.filter(new Iterable<Statement>() {
            @Override
            public Iterator<Statement> iterator() {
                try {
                    return ResultUtils.unwrap(con.getStatements(r, rdf_type, null, true, contexts));
                } catch (RepositoryException e) {
                    ExceptionUtils.handleRepositoryException(e, ResourceUtils.class);
                    return Iterators.emptyIterator();
                }
            }
        }, new Predicate<Statement>() {
            @Override
            public boolean apply(Statement input) {
                return input.getObject() instanceof Resource;
            }
        }), new Function<Statement, Resource>() {
            @Override
            public Resource apply(Statement input) {
                return (Resource) input.getObject();
            }
        });
    } else {
        return Collections.emptyList();
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.NodeDocument.java

@Nonnull
Iterator<NodeDocument> getAllPreviousDocs() {
    if (getPreviousRanges().isEmpty()) {
        return Iterators.emptyIterator();
    }//from w w w .  j  a  v a 2 s .c  o m
    //Currently this method would fire one query per previous doc
    //If that poses a problem we can try to find all prev doc by relying
    //on property that all prevDoc id would starts <depth+2>:p/path/to/node
    return new AbstractIterator<NodeDocument>() {
        private Queue<Map.Entry<Revision, Range>> previousRanges = Queues
                .newArrayDeque(getPreviousRanges().entrySet());

        @Override
        protected NodeDocument computeNext() {
            if (!previousRanges.isEmpty()) {
                Map.Entry<Revision, Range> e = previousRanges.remove();
                NodeDocument prev = getPreviousDoc(e.getKey(), e.getValue());
                if (prev != null) {
                    previousRanges.addAll(prev.getPreviousRanges().entrySet());
                    return prev;
                }
            }
            return endOfData();
        }
    };
}

From source file:org.apache.jackrabbit.oak.plugins.document.NodeDocument.java

/**
 * Returns previous leaf documents. Those are the previous documents with
 * a type {@code !=} {@link SplitDocType#INTERMEDIATE}. The documents are
 * returned in descending order based on the most recent change recorded
 * in the previous document. A change is defined as an entry in either the
 * {@link #REVISIONS} or {@link #COMMIT_ROOT} map.
 *
 * @return the leaf documents in descending order.
 *//*from   w  ww  .ja  va2  s . com*/
@Nonnull
Iterator<NodeDocument> getPreviousDocLeaves() {
    if (getPreviousRanges().isEmpty()) {
        return Iterators.emptyIterator();
    }
    // create a mutable copy
    final NavigableMap<Revision, Range> ranges = Maps.newTreeMap(getPreviousRanges());
    return new AbstractIterator<NodeDocument>() {
        @Override
        protected NodeDocument computeNext() {
            NodeDocument next;
            for (;;) {
                Map.Entry<Revision, Range> topEntry = ranges.pollFirstEntry();
                if (topEntry == null) {
                    // no more ranges
                    next = endOfData();
                    break;
                }
                NodeDocument prev = getPreviousDoc(topEntry.getKey(), topEntry.getValue());
                if (prev == null) {
                    // move on to next range
                    continue;
                }
                if (topEntry.getValue().getHeight() == 0) {
                    // this is a leaf
                    next = prev;
                    break;
                } else {
                    // replace intermediate entry with its previous ranges
                    ranges.putAll(prev.getPreviousRanges());
                }
            }
            return next;
        }
    };
}

From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger.java

/**
 * Returns an iterator over the all gerrit projects configured for the trigger.
 *
 * @return an iterator over the all gerrit projects configured for the trigger.
 *///  w  ww .  j  a  v a 2s.co m
private Iterator<GerritProject> getAllGerritProjectsIterator() {
    if (gerritProjects != null && dynamicGerritProjects != null) {
        return Iterators.concat(gerritProjects.iterator(), dynamicGerritProjects.iterator());
    }

    if (gerritProjects == null && dynamicGerritProjects != null) {
        return dynamicGerritProjects.iterator();
    }

    if (gerritProjects != null) {
        return gerritProjects.iterator();
    }

    return Iterators.emptyIterator();
}

From source file:org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.java

/**
 * Returns <code>true</code> if the given edge is displayed in another
 * specific layer configuration.//w w w  . j ava2s  . co m
 * 
 * @param edgeCandidate
 *            the edge to check.
 * @param mappingsToEdgeTargets
 *            mapping to edges, it contains nodes that are actually
 *            displayed (with the actual layer configuration).
 * @return <code>true</code> if the given edge is displayed in a specific
 *         layer configuration.
 */
private boolean isDefinedInAnotherLayer(final DEdgeCandidate edgeCandidate,
        final Map<DiagramElementMapping, Collection<EdgeTarget>> mappingsToEdgeTargets) {
    if (edgeCandidate.getEdge() == null) {
        return false;
    }
    final DEdge edge = edgeCandidate.getEdge();
    final EdgeTarget source = edge.getSourceNode();
    final EdgeTarget target = edge.getTargetNode();
    /*
     * If the source of target is not a DDiagramElement then i don't know
     * how to manage it. I expect that the behavior is managed by another
     * component.
     */
    final boolean sourceIsValid = source != null && (!(source instanceof DDiagramElement)
            || ((DDiagramElement) source).getParentDiagram() == this.diagram);
    final boolean targetIsValid = target != null && (!(target instanceof DDiagramElement)
            || ((DDiagramElement) target).getParentDiagram() == this.diagram);
    /*
     * If the source and the target are valid then we need to check that
     * there are not displayed on the diagram (it means that the edge is not
     * displayed).
     */
    final Option<EdgeMapping> actualMapping = new IEdgeMappingQuery(edge.getActualMapping()).getEdgeMapping();

    final Iterator<DiagramElementMapping> sourceMappings;
    final Iterator<DiagramElementMapping> targetMappings;

    if (actualMapping.some()) {
        sourceMappings = actualMapping.get().getSourceMapping().iterator();
        targetMappings = actualMapping.get().getTargetMapping().iterator();
    } else {
        sourceMappings = Iterators.emptyIterator();
        targetMappings = Iterators.emptyIterator();
    }

    final boolean sourceIsNotDisplayed = nodeIsNotDisplayed(sourceMappings, source, mappingsToEdgeTargets);
    final boolean targetIsNotDisplayed = nodeIsNotDisplayed(targetMappings, target, mappingsToEdgeTargets);

    return sourceIsValid && targetIsValid && (sourceIsNotDisplayed || targetIsNotDisplayed);
}