Returns a new Iterator over every {@link ResidueNumber} in the list of ResidueRanges.
Stores the contents of {@code map} until the iterator is finished, so calling code should set the iterator to {@code null} if it did not finish.
437764
public static Iterator<ResidueNumber> multiIterator(final AtomPositionMap map, final ResidueRange... rrs) {
		return new Iterator<ResidueNumber>() {
			private int r = 0;
			private Iterator<ResidueNumber> internal;
			@Override
			public boolean hasNext() {
				if (r == rrs.length - 1) {
					init();
					return internal.hasNext();
				}
				return true;
			}
			private void init() {
				if (internal == null) {
					internal = rrs[r].iterator(map);
				}
			}
			@Override
			public ResidueNumber next() {
				if (rrs.length == 0) throw new NoSuchElementException();
				init();
				if (!hasNext()) throw new NoSuchElementException();
				if (!internal.hasNext()) {
					r++;
					internal = rrs[r].iterator(map);
				}
				return internal.next();
			}
			@Override
			public void remove() {
				throw new UnsupportedOperationException("Not modifiable");
			}
		};
	}
255418
public static Map makeMap(Mapper mapper, Iterator i, boolean includeNull) {
        HashMap h = new HashMap();
        for (; i.hasNext();) {
            Object k = i.next();
            Object v = mapper.map(k);
            if (includeNull || v != null) {
                h.put(k, v);
            }
        }
        return h;
    }
827026
public static <T, R> Iterator<R> map(final Iterator<T> iterator, final IFunction<T, R> mapper) {
        return new Iterator<R>() {
            @Override
            public boolean hasNext() {
                return iterator.hasNext();
            }

            @Override
            public R next() {
                return mapper.apply(iterator.next());
            }

            @Override
            public void remove() {
                iterator.remove();
            }
        };
    }
334539
@Override
	public Iterator<Entry<K, V>> iterator() {
		return new Iterator<Entry<K, V>>() {

			private final Entry<K, V>[] tab = KeyMap.this.table;

			private Entry<K, V> nextEntry;

			private int nextPos = 0;

			@Override
			public boolean hasNext() {
				if (nextEntry != null) {
					return true;
				}
				else {
					while (nextPos < tab.length) {
						Entry<K, V> e = tab[nextPos++];
						if (e != null) {
							nextEntry = e;
							return true;
						}
					}
					return false;
				}
			}

			@Override
			public Entry<K, V> next() {
				if (nextEntry != null || hasNext()) {
					Entry<K, V> e = nextEntry;
					nextEntry = nextEntry.next;
					return e;
				}
				else {
					throw new NoSuchElementException();
				}
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}
886981
public java.util.Iterator iterator() {
        // TODO Bug in remove from a concurrentSet/Map iterator, it does not actually do the remove!
        java.util.Set combinedSet = new java.util.HashSet();
        if (subSets != null) {
            for (int i = 0; i < subSets.length; i++) {
                synchronized (subSets[i]) {
                    combinedSet.addAll(subSets[i]);
                } // synchronized (subSet).
            }
        }
        return combinedSet.iterator();
    }
951584
@Override
    public Iterator<T> iterator() {
        
        /*
         * We make a copy of the allResults list to iterate over in order to
         * avoid ConcurrentModificationExceptions caused by other methods
         * loading more results into the list while someone iterates over it.
         * This is a more severe problem than it might seem, because even
         * innocuous-seeming operations such as contains() can modify the
         * underlying result set.
         */
        final List<T> allResultsCopy = new ArrayList<T>();
        allResultsCopy.addAll(allResults);        
        final Iterator<T> iter = allResultsCopy.iterator();
        
        return new Iterator<T>() {
    
            Iterator<T> iterator = iter;
            int pos = 0;
            
            @Override
            public boolean hasNext() {
                return iterator.hasNext() || nextResultsAvailable();
            }
    
            @Override
            public T next() {
                if ( !iterator.hasNext() ) {
                    /*
                     * Our private copy of the result list may be out of date
                     * with the full one. If it is, we just need to update our
                     * private copy to get more results. If it's not, we need to
                     * fetch more results from the service.
                     */
                    if ( allResults.size() == allResultsCopy.size() ) {
                        if ( !nextResultsAvailable() ) {
                            throw new NoSuchElementException();
                        }
                        moveNextResults();
                    } 
                    
                    if ( allResults.size() > allResultsCopy.size() )
                        allResultsCopy.addAll(allResults.subList(allResultsCopy.size(), allResults.size()));
                    
                    iterator = allResultsCopy.listIterator(pos);
                }
                
                pos++;
                return iterator.next();
            }
            
            @Override
            public void remove() {
                throw new UnsupportedOperationException(UNMODIFIABLE_MESSAGE);
            }            
        };
    }
1204585
public Iterable<V> values() {
    return new Iterable<V>() {
      @Override
      public Iterator<V> iterator() {
        return new Iterator<V>() {
          final Iterator<List<V>> valuesIterator = map.values().iterator();
          Iterator<V> current;

          {
            if (valuesIterator.hasNext())
              current = valuesIterator.next().iterator();
          }

          @Override
          public boolean hasNext() {
            return current != null && current.hasNext();
          }

          @Override
          public V next() {
            V value = current.next();
            while (!current.hasNext() && valuesIterator.hasNext())
              current = valuesIterator.next().iterator();
            return value;
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException();
          }
        };
      }
    };
  }
509305
public static <T> Iterator<T> nullToEmpty(final Iterator<T> iter) {
        return iter == null ? N.<T> emptyIterator() : iter;
    }
1046299
@Override
   public Iterator<R> iterator() {
      log.tracef("Distributed iterator invoked with rehash: %s", rehashAware);
      if (!rehashAware) {
         // Non rehash doesn't care about lost segments or completed ones
         CloseableIterator<R> closeableIterator = nonRehashRemoteIterator(dm.getReadConsistentHash(), segmentsToFilter,
               null, IdentityPublisherDecorator.getInstance(), intermediateOperations);
         onClose(closeableIterator::close);
         return closeableIterator;
      } else {
         Iterable<IntermediateOperation> ops = iteratorOperation.prepareForIteration(intermediateOperations,
               (Function) nonNullKeyFunction());
         CloseableIterator<R> closeableIterator;
         if (segmentCompletionListener != null && iteratorOperation != IteratorOperation.FLAT_MAP) {
            closeableIterator = new CompletionListenerRehashIterator<>(ops, segmentCompletionListener);
         } else {
            closeableIterator = new RehashIterator<>(ops);
         }
         onClose(closeableIterator::close);
         // This cast messes up generic checking, but that is okay
         Function<R, R> function = iteratorOperation.getFunction();
         if (function != null) {
            return new IteratorMapper<>(closeableIterator, function);
         } else {
            return closeableIterator;
         }
      }
   }
1069899
@SuppressWarnings("unchecked")
	public static <K, V> Map<K, V> fieldValueMap(Iterator<V> iter, String fieldName) {
		final Map<K, V> result = new HashMap<>();
		if (null != iter) {
			V value;
			while (iter.hasNext()) {
				value = iter.next();
				result.put((K) ReflectUtil.getFieldValue(value, fieldName), value);
			}
		}
		return result;
	}
569854
private static Iterator<ImmutableRoaringBitmap> selectRangeWithoutCopy(
      final Iterator<? extends ImmutableRoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd) {
    Iterator<ImmutableRoaringBitmap> bitmapsIterator;
    bitmapsIterator = new Iterator<ImmutableRoaringBitmap>() {
      @Override
      public boolean hasNext() {
        return bitmaps.hasNext();
      }

      @Override
      public ImmutableRoaringBitmap next() {
        ImmutableRoaringBitmap next = bitmaps.next();
        return selectRangeWithoutCopy(next, rangeStart, rangeEnd);
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException("Remove not supported");
      }
    };
    return bitmapsIterator;
  }
465462
public static <T> Iterator<T> iteratorOverIterables(
        Iterable<? extends T> iterable0, Iterable<? extends T> iterable1)
    {
        Objects.requireNonNull(iterable0, "The iterable0 is null");
        Objects.requireNonNull(iterable1, "The iterable1 is null");
        List<Iterable<? extends T>> iterables =
            new ArrayList<Iterable<? extends T>>(2);
        iterables.add(iterable0);
        iterables.add(iterable1);
        return iteratorOverIterables(iterables.iterator());
    }
492374
@SuppressWarnings("NullableProblems")
  @Override
  public Iterator<T> iterator() {
    return new Iterator<T>() {
      private int index = 0;

      @Override
      public boolean hasNext() {
        return this.index < size();
      }

      @Override
      public T next() {
        if (this.index >= size()) {
          throw new NoSuchElementException(this.index + ">=" + size());
        }
        return getElementAt(this.index++);
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException("Removing is unsupported here");
      }

    };
  }
364195
public synchronized ManageableCacheValue getNextCacheValue() {
        //changes to the map are reflected on the keySet. And its iterator is weakly consistent. so will never
        //throw concurrent modification exception.
        if (iterator.hasNext()) {
            return hashMap.get(iterator.next().getKey());
        } else {
            resetIterator();
            return null;
        }
    }
48402
@Override
   public Iterator<String> iterator() {
      Iterator<String> it = new Iterator<String>() {

         private Set<Entry<String, String>> entries     = modName_ModOption.entrySet();
         Iterator<Entry<String, String>>    iteratorSet = entries.iterator();

         @Override
         public boolean hasNext() {
            return iteratorSet.hasNext();

         }

         @Override
         public String next() {
            return iteratorSet.next().getKey();

         }

         @Override
         public void remove() {

         }
      };
      return it;
   }
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();
            }
        };
    }
1183753
@Override
  public Iterator<Entry<String, Fetch>> iterator() {
    return Collections.unmodifiableMap(attrFetchMap).entrySet().iterator();
  }