Java 8 Iterator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Iterator class.

This code example shows how to use the following methods:hasNext, next, remove
 
    @Override 
    public E poll() 
    { 
        Iterator<E> iterator = delegate.iterator();
        if (!iterator.hasNext()) {
            return null; 
        } 
        E element = iterator.next();
        iterator.remove();
        return element;
    } 
 
    @Override 
    public E peek() 
    { 
        Iterator<E> iterator = delegate.iterator();
        if (!iterator.hasNext()) {
            return null; 
        } 
9
CodeRank
This code example shows how to use the following methods:hasNext, next, remove
 
  @Override 
  public boolean remove(@Nullable Object o) {
    Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate();
    for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext();) {
      Map.Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();
        return true; 
      } 
    } 
    return false; 
  } 
 
  @Override 
  public boolean removeAll(Collection<?> c) {
    return Iterables.removeIf(multimap.unfiltered().entries(),
        // explicit <Entry<K, V>> is required to build with JDK6 
        Predicates.<Entry<K, V>>and(multimap.entryPredicate(),
9
CodeRank
This code example shows how to use the following methods:hasNext, next, remove
This code example shows how to use the following methods:hasNext, next, remove
    } 
 
    public void forwardSuccess(List<Response.ResponseListener> listeners, Response response)
    { 
        notifyBegin(listeners, response);
        for (Iterator<HttpField> iterator = response.getHeaders().iterator(); iterator.hasNext();)
        { 
            HttpField field = iterator.next();
            if (!notifyHeader(listeners, response, field))
                iterator.remove();
        } 
        notifyHeaders(listeners, response);
        if (response instanceof ContentResponse)
            notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), Callback.NOOP);
        notifySuccess(listeners, response);
    } 
 
    public void forwardSuccessComplete(List<Response.ResponseListener> listeners, Request request, Response response)
    { 
        forwardSuccess(listeners, response);
9
CodeRank
This code example shows how to use the following methods:hasNext, next
        return !iterator.hasNext();
    } 
 
    public synchronized E poll() 
    { 
        if (!iterator.hasNext()) {
            return null; 
        } 
        return iterator.next();
    } 
} 
9
CodeRank
This code example shows how to use the following methods:hasNext, next
 
    @Override 
    public Value reduce(Key key, Iterator<Value> iter)
    { 
        Value min = null;
        while (iter.hasNext()) {
            Value test = iter.next();
            if (min == null) {
                min = new Value(test.get());
            } 
            else if (comparator.compare(test.get(), min.get()) < 0) {
                min.set(test.get());
            } 
        } 
        return min;
    } 
} 
9
CodeRank
This code example shows how to use the following methods:hasNext, next, remove
  } 
 
  @Override 
  public Entry<E> pollFirstEntry() { 
    Iterator<Entry<E>> entryIterator = entryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
      entryIterator.remove();
      return result;
    } 
    return null; 
  } 
 
  @Override 
  public Entry<E> pollLastEntry() { 
    Iterator<Entry<E>> entryIterator = descendingEntryIterator();
    if (entryIterator.hasNext()) {
      Entry<E> result = entryIterator.next();
      result = Multisets.immutableEntry(result.getElement(), result.getCount());
9
CodeRank
This code example shows how to use the following methods:hasNext, next, remove
This code example shows how to use the following methods:hasNext, next
    } 
 
    @Override 
    public boolean hasNext() 
    { 
        return count < limit && iterator.hasNext();
    } 
 
    @Override 
    public T next() 
    { 
        if (!hasNext()) { 
            throw new NoSuchElementException();
        } 
 
        count++;
        return iterator.next();
    } 
} 

9
CodeRank
This code example shows how to use the following methods:hasNext
    protected AdaptedIterator(Iterable<? extends T> core) {
        this(core.iterator());
    } 
 
    public boolean hasNext() { 
        return core.hasNext();
    } 
 
    public U next() { 
        return adapt(core.next());
    } 
 
    protected abstract U adapt(T item);
 
    public void remove() { 
        core.remove();
    } 
} 
8
CodeRank

Related Java 8 Iterator Questions & Answers:

See Code Examples for Java 8 Iterator Methods: