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:org.richfaces.ui.core.UITransient.java

@Override
public Iterator<UIComponent> getFacetsAndChildren() {
    return Iterators.emptyIterator();
}

From source file:com.opengamma.financial.analytics.timeseries.HistoricalTimeSeriesBundle.java

/**
 * Gets an iterator for the time-series stored under the given field name. This iterates over the time-series in the
 * same order as they were added./*  ww  w  . ja v  a2s  .  c  o m*/
 * 
 * @param field  the data field, not null
 * @return an iterator, not null
 */
public Iterator<HistoricalTimeSeries> iterator(final String field) {
    ArgumentChecker.notNull(field, "field");
    final Entry e = _data.get(field);
    if (e == null) {
        return Iterators.emptyIterator();
    }
    return e.iterator();
}

From source file:org.summer.dsl.xbase.lib.IteratorExtensions.java

/**
 * Returns a view on this iterator that provides at most the first <code>count</code> entries.
 * //from  w  ww.  ja  v a2s  .  co  m
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param count
 *            the number of elements that should be returned at most.
 * @return an iterator with <code>count</code> elements. Never <code>null</code>.
 * @throws IllegalArgumentException
 *             if <code>count</code> is negative.
 */
@Pure
public static <T> Iterator<T> take(final Iterator<T> iterator, final int count) {
    if (iterator == null)
        throw new NullPointerException("iterator");
    if (count < 0)
        throw new IllegalArgumentException(
                "Cannot take a negative number of elements. Argument 'count' was: " + count);
    if (count == 0)
        return Iterators.emptyIterator();
    return new AbstractIterator<T>() {

        private int remaining = count;

        @Override
        protected T computeNext() {
            if (remaining <= 0)
                return endOfData();
            if (!iterator.hasNext())
                return endOfData();
            remaining--;
            return iterator.next();
        }
    };
}

From source file:com.android.tools.idea.gradle.compiler.PostProjectBuildTasksExecutor.java

public void onBuildCompletion(@NotNull GradleInvocationResult result) {
    Iterator<String> errors = Iterators.emptyIterator();
    List<Message> errorMessages = result.getCompilerMessages(Message.Kind.ERROR);
    if (!errorMessages.isEmpty()) {
        errors = new MessageIterator(errorMessages);
    }//w ww .ja  v a  2s .c  om
    //noinspection TestOnlyProblems
    onBuildCompletion(errors, errorMessages.size());
}

From source file:de.cosmocode.collections.tree.iterator.AbstractTreeIterator.java

/**
 * <p> This method goes to the parent node of the current node.
 * The level is reduced by one after a call to this method.
 * The data of the parent element is returned as by {@link #currentData()}.
 * </p>//from w w  w  .  j  a  v  a  2s  .c  o m
 * 
 * @return the parent element's data
 * @throws NoSuchElementException if this method is called on the root node
 */
protected E parent() {
    if (isRoot()) {
        throw new NoSuchElementException("can not go to parent of root");
    }

    this.currentNode = this.currentNode.getParent();
    --this.currentLevel;

    if (isRoot()) {
        this.siblingIterator = Iterators.emptyIterator();
    } else {
        this.siblingIterator = this.currentNode.getParent().getChildren().iterator();
        if (currentIndex() >= 0) {
            Iterators.get(this.siblingIterator, currentIndex());
        }
    }

    return currentData();
}

From source file:org.splevo.diffing.match.HierarchicalMatchEngine.java

/**
 * This will be used to match the given {@link ResourceSet}s. This default implementation will
 * query the comparison scope for these resource sets children, then delegate to an
 * {@link IResourceMatcher} to determine the resource mappings.
 *
 * The content of the matched resources is then pushed into the resource specific match method.<br>
 *
 * <b>Note:</b><br>/* w ww .  j ava 2 s.c  om*/
 * In contrast to the DefaultMatchEngine, the match for eObjects recursively iterates through
 * sub elements of the models. As a result, only the root elements of the resources are matched
 * and not the plain list of all all contained elements.
 *
 * @param comparison
 *            The comparison to which will be added detected matches.
 * @param scope
 *            The comparison scope that should be used by this engine to determine the objects
 *            to match.
 * @param left
 *            The left {@link ResourceSet}.
 * @param right
 *            The right {@link ResourceSet}.
 * @param monitor
 *            The monitor to report progress or to check for cancellation
 */
protected void match(Comparison comparison, IComparisonScope scope, ResourceSet left, ResourceSet right,
        Monitor monitor) {
    final Iterator<? extends Resource> leftChildren = scope.getCoveredResources(left);
    final Iterator<? extends Resource> rightChildren = scope.getCoveredResources(right);
    final Iterator<? extends Resource> originChildren = Iterators.emptyIterator();

    final IResourceMatcher matcher = createResourceMatcher();
    final Iterable<MatchResource> mappings = matcher.createMappings(leftChildren, rightChildren,
            originChildren);

    for (MatchResource mapping : mappings) {
        comparison.getMatchedResources().add(mapping);

        final Resource leftRes = mapping.getLeft();
        final Resource rightRes = mapping.getRight();

        match(comparison, leftRes, rightRes, monitor);

    }
}

From source file:com.palantir.common.collect.IteratorUtils.java

/**
 * This will take 2 iterators sorted by the given ordering and will return an iterator that
 * visits every element in the first one not in the second one.
 *
 * @param a must be sorted by ordering./*ww  w.  j a  v  a 2 s .co m*/
 * @param b must be sorted by ordering.
 * @param ordering
 */
public static <T> Iterator<T> iteratorDifference(final Iterator<? extends T> a, final Iterator<? extends T> b,
        final Comparator<? super T> ordering) {
    Preconditions.checkNotNull(ordering);
    if (!a.hasNext()) {
        return Iterators.emptyIterator();
    }
    if (!b.hasNext()) {
        return IteratorUtils.wrap(a);
    }
    return new AbstractIterator<T>() {
        T currentB = b.next();

        @Override
        protected T computeNext() {
            while (a.hasNext()) {
                T possibleNext = a.next();

                // Search for a new currentB that is >= possibleNext
                while (b.hasNext() && ordering.compare(possibleNext, currentB) > 0) {
                    currentB = b.next();
                }

                if (ordering.compare(possibleNext, currentB) != 0) {
                    return possibleNext;
                }
            }
            return endOfData();
        }
    };
}

From source file:org.richfaces.component.AbstractTab.java

/**
 * If the VisitContext is not the RenderExtendedVisitContext, return the usual FacetsAndChildren iterator.
 * Otherwise return only the Facet iterator when a child visit is not required.
 *
 * This is useful to not render the tab contents when an item is not visible, while still visiting the header facets.
 *
 * @param visitContext The VisitContext of the component tree visit.
 *///from ww w  .  j av  a 2  s  . c om
public static Iterator<UIComponent> getVisitableChildren(UIComponent component, VisitContext visitContext) {
    Iterator<UIComponent> kids;
    if (ExtendedRenderVisitContext.isExtendedRenderVisitContext(visitContext)
            && component instanceof VisitChildrenRejectable
            && !((VisitChildrenRejectable) component).shouldVisitChildren()) {
        if (component.getFacetCount() > 0) {
            kids = component.getFacets().values().iterator();
        } else {
            kids = Iterators.emptyIterator();
        }
    } else {
        kids = component.getFacetsAndChildren();
    }
    return kids;
}

From source file:org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate.java

@Nonnull
public Iterator<VersionDelegate> getAllLinearVersions() throws RepositoryException {
    String id = getVersionableIdentifier();
    NodeDelegate versionable = sessionDelegate.getNodeByIdentifier(id);
    if (versionable == null || versionable.getPropertyOrNull(JCR_BASEVERSION) == null) {
        return Iterators.emptyIterator();
    }/*from w  w w . j  av  a 2s  . c  o  m*/
    Deque<VersionDelegate> linearVersions = new ArrayDeque<VersionDelegate>();
    VersionManagerDelegate vMgr = VersionManagerDelegate.create(sessionDelegate);
    VersionDelegate version = vMgr.getVersionByIdentifier(versionable.getProperty(JCR_BASEVERSION).getString());
    while (version != null) {
        linearVersions.add(version);
        version = version.getLinearPredecessor();
    }
    return linearVersions.descendingIterator();
}

From source file:org.elasticsearch.action.termvectors.TermVectorsResponse.java

public Fields getFields() throws IOException {
    if (hasTermVectors() && isExists()) {
        if (!sourceCopied) { // make the bytes safe
            headerRef = headerRef.copyBytesArray();
            termVectors = termVectors.copyBytesArray();
        }/*w  w w  .  j a v a  2s  .c om*/
        TermVectorsFields termVectorsFields = new TermVectorsFields(headerRef, termVectors);
        hasScores = termVectorsFields.hasScores;
        return termVectorsFields;
    } else {
        return new Fields() {
            @Override
            public Iterator<String> iterator() {
                return Iterators.emptyIterator();
            }

            @Override
            public Terms terms(String field) throws IOException {
                return null;
            }

            @Override
            public int size() {
                return 0;
            }
        };
    }
}