Yields nth (1-based) element of the iterator if found or nothing.

@param <E> the iterator element type
@param count the element cardinality
@param iterator the iterator that will be consumed
@return just the element or nothing
432321
public static <E> Optional<E> maybeNth(long count, Iterator<E> iterator) {
        final Iterator<E> filtered = new FilteringIterator<E>(iterator, new Nth<E>(count));
        return new MaybeFirstElement<E>().apply(filtered);
    }
297648
@SafeVarargs
    public static <T> ElementIterator<T> compositeIterator(Iterator<T>... iterators) {
        Require.nonNull(iterators, "iterators");
        final Iterator<T> result;
        if (iterators.length == 0) {
            result = Collections.emptyIterator();
        } else if (iterators.length == 1) {
            if (iterators[0] instanceof ElementIterator<?>) {
                return (ElementIterator<T>) iterators[0];
            }
            result = iterators[0];
        } else {
            result = new CompoundIterator<>(iterators);
        }
        return ElementIterator.wrap(result);

    }
1127542
public T min() {
        TObjectLongIterator<T> iter = counts.iterator();
        long minCount = Long.MAX_VALUE;
        T min = null;
        while (iter.hasNext()) {
            iter.advance();
            long count = iter.value();
            if (count < minCount) {
                min = iter.key();
                minCount = count;
            }
        }
        return min;
    }
1163488
public synchronized Iterator iterator()
   {
		if (tc.isEntryEnabled()) SibTr.entry(this, tc, "iterator");
      Iterator returnValue = idToConvTable.values().iterator();
		if (tc.isEntryEnabled()) SibTr.exit(this, tc, "iterator", returnValue);
   	return returnValue;
   }
1249606
public static <T> Iterator<T> singleIterator(T t) {
        Require.nonNull(t, "t");
        return Collections.singleton(t).iterator();
    }
906530
public static int count(Iterable seq) {
        if (seq instanceof Collection) {
            return ((Collection) seq).size();
        }
        int c = 0;
        Iterator it = seq.iterator();
        while (it.hasNext()) {
            c++;
            it.next();
        }
        return c;
    }
641233
public static <T> T pickRandom (Iterator<T> iter, int count)
    {
        return pickRandom(iter, count, rand);
    }
282326
public static <E> ImmutableIterator<E> makeImmutable(final Iterator<E> iterator) {
        return new ImmutableIterator<E>() {
            @Override
            public boolean hasNext() {
                return iterator.hasNext();
            }

            @Override
            public E next() {
                return iterator.next();
            }
        };
    }
57520
def count(cls, iterable):
    

    iterable = iter(iterable)
    count = 0
    while True:
      try:
        next(iterable)
      except StopIteration:
        break
      count += 1
    return count
202560
public Iterator<T> iterator() {
        return new Iterator<T>() {
            private int currentPosition = start;
            private boolean hasNext = true;

            public boolean hasNext() {
                return hasNext;
            }

            @SuppressWarnings("unchecked")
            public T next() {
                if (end == -1)
                    hasNext = !sequence.getItem(currentPosition).getClass().equals(SequenceTerminal.class);
                else
                    hasNext = currentPosition < getEnd() - 1;
                return (T) sequence.getItem(currentPosition++);
            }

            public void remove() {
                throw new UnsupportedOperationException(
                    "The remove method is not supported.");
            }
        };
    }
680980
@Override
    public IntIterator iterator() {

        return new IntIterator() {

            private int i = 0;

            @Override
            public int nextInt() {
                return i++;
            }

            @Override
            public int skip(int k) {
                return i + k;
            }

            @Override
            public boolean hasNext() {
                return i < rowCount();
            }
        };
    }
1040216
public static @Nonnull <T> Iterable<T> enumerationToIterable(@Nullable Enumeration<T> enumeration) {
        if (enumeration == null) {
            return Collections.emptyList();
        }

        return () -> new Iterator<T>() {
            @Override
            public boolean hasNext() {
                return enumeration.hasMoreElements();
            }

            @Override
            public T next() {
                return enumeration.nextElement();
            }
        };
    }
522891
public static <T> int count(Iterable<T> iterable) {
        int count = 0;

        if (iterable != null) {
            Iterator<T> iter = iterable.iterator();
            while (iter.hasNext()) {
                iter.next();
                count++;
            }
        }

        return count;
    }
51114
public static <T> Iterator<T> cycle(Iterator<T> itr, int times) {
        // if we repeat 0, then it is as if the itr were empty, so don't take the items
        final List<T> items = (times != 0) ? Lists.newLinkedList(iterable(itr)) : Collections.emptyList();
        
        return new Iterator<T>() {
            
            private Iterator<T> currentItr = Collections.emptyIterator();
            private int ncalls = 0;
            
            private Iterator<T> getItr() {
                // if this is the first call or we've gotten to the end of a round
                if (!currentItr.hasNext() && ncalls < times) {
                    currentItr = items.iterator();
                    ncalls++;
                }
                return currentItr;
            }
            
            @Override
            public boolean hasNext() {
                return getItr().hasNext();
            }

            @Override
            public T next() {
                return getItr().next();
            }
            
        };
    }
797744
public IntSet.IntIterator iterator()
  {
    if (isEmpty()) {
      return new IntSet.IntIterator()
      {
        @Override
        public void skipAllBefore(int element) {/*empty*/}

        @Override
        public boolean hasNext() {return false;}

        @Override
        public int next() {throw new NoSuchElementException();}

        @Override
        public void remove() {throw new UnsupportedOperationException();}

        @Override
        public IntSet.IntIterator clone() {throw new UnsupportedOperationException();}
      };
    }
    return new BitIterator();
  }
1087581
@Override
  public T next() {
    Assert.isTrue(hasNext(), new NoSuchElementException("The iteration has no more elements!"));
    T nextValue = iteratorList.get(currentIteratorIndex).next();
    currentIteratorIndex = (++currentIteratorIndex % iteratorList.size());
    nextCalled.set(true);
    return nextValue;
  }
578048
public static <E> E first(Iterator<E> iterator) {
        return new FirstElement<E>().apply(iterator);
    }