Java Code Examples for com.google.common.collect.ForwardingIterator

The following are top voted examples for showing how to use com.google.common.collect.ForwardingIterator. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boxes   File: CollectionBox.java   View source code 6 votes vote down vote up
@Override
public Iterator<E> iterator() {
    final Iterator<E> valueIterator = value.iterator();
    return new ForwardingIterator<E>() {

        @Override
        protected Iterator<E> delegate() {
            return valueIterator;
        }

        @Override
        public void remove() {
            super.remove();
            change();
        }
    };
}
 
Example 2
Project: boxes   File: BoxFamily.java   View source code 6 votes vote down vote up
@Override
public Iterator<E> iterator() {
    final Iterator<E> delegateIterator = delegate().iterator();
    return new ForwardingIterator<E>() {

        @Override
        protected Iterator<E> delegate() {
            return delegateIterator;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example 3
Project: multiway-pool   File: EliminationStack.java   View source code 5 votes vote down vote up
@Override
public Iterator<E> iterator() {
  final class ReadOnlyIterator extends AbstractIterator<E> {
    Node<E> current = top.get();

    @Override
    protected E computeNext() {
      for (;;) {
        if (current == null) {
          return endOfData();
        }
        E e = current.get();
        current = current.next;
        if (e != null) {
          return e;
        }
      }
    }
  };
  return new ForwardingIterator<E>() {
    final ReadOnlyIterator delegate = new ReadOnlyIterator();

    @Override
    public void remove() {
      checkState(delegate.current != null);
      delegate.current.lazySet(null);
    }

    @Override
    protected Iterator<E> delegate() {
      return delegate;
    }
  };
}