Convenience function to add the correct {@link StackedIterator} to the key
range Iterator stack.

This method is used to add a <em>single</em> <em>projected</em> constraint
to the stack.
499795
private static Iterator<MarkerRange.Builder> addProjected(
      Predicate projected, String name,
      Iterator<MarkerRange.Builder> inner) {
    if (projected instanceof In) {
      return new SetIterator((In) projected, name, inner);
    } else if (projected instanceof Range) {
      return new RangeIterator(name, (Range) projected, inner);
    } else {
      return inner;
    }
  }
510984
public static ByteIteratorEx of(final Supplier<? extends ByteIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new ByteIteratorEx() {
            private ByteIterator iter = null;
            private ByteIteratorEx iterEx = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iter.hasNext();
            }

            @Override
            public byte nextByte() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextByte();
            }

            @Override
            public void skip(long n) {
                N.checkArgNotNegative(n, "n");

                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.skip(n);
                } else {
                    super.skip(n);
                }
            }

            @Override
            public long count() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    return iterEx.count();
                } else {
                    return super.count();
                }
            }

            @Override
            public void close() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.close();
                }
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                    iterEx = iter instanceof ByteIteratorEx ? (ByteIteratorEx) iter : null;
                }
            }
        };
    }
1255325
public static final <T,U extends Range<T>> U best(Iterator<U> iterator, Comparator<U> comp)
    {
        List<U> list = new ArrayList<>();
        ListIterator<U> li = list.listIterator();
        if (!iterator.hasNext())
        {
            throw new IllegalArgumentException("empty");
        }
        U prev = iterator.next();
        li.add(prev);
        while (iterator.hasNext())
        {
            U next = iterator.next();
            if (!prev.isOverlapping(next) || CollectionHelp.compare(prev, next, comp) >= 0)
            {
                break;
            }
            prev = next;
            li.add(prev);
        }
        Range<T> top = li.previous();
        while (li.hasPrevious())
        {
            Range<T> p = li.previous();
            if (top.isOverlapping(p))
            {
                li.remove();
            }
            else
            {
                top = p;
            }
        }
        return list.get(0);
    }
408981
public void addDateRangeFilter(String key, DateRange dateRange) {

        JsonObject opObj = new JsonObject();

        if (dateRange.getFromDate() != null) {
            String dateGtString = BoxDateFormat.format(dateRange.getFromDate());
            //workaround replacing + and - 000 at the end with 'Z'
            dateGtString = dateGtString.replaceAll("(\\+|-)(?!-\\|?!\\+)\\d+$", "Z");
            opObj.add("gt", dateGtString);
        }
        if (dateRange.getToDate() != null) {
            String dateLtString = BoxDateFormat.format(dateRange.getToDate());
            //workaround replacing + and - 000 at the end with 'Z'
            dateLtString = dateLtString.replaceAll("(\\+|-)(?!-\\|?!\\+)\\d+$", "Z");
            opObj.add("lt", dateLtString);
        }

        this.filtersList.add(key, opObj);
    }
579903
public static <T> PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator) {
        final PeekingIterator<T> peeking = Iterators.peekingIterator(iterator);
        return new PeekingCloseableIterator<T>() {
            @Override
            public void close() {
                iterator.close();
            }

            @Override
            public T peek() {
                return peeking.peek();
            }

            @Override
            public T next() {
                return peeking.next();
            }

            @Override
            public void remove() {
                peeking.remove();
            }

            @Override
            public boolean hasNext() {
                return peeking.hasNext();
            }
        };
    }
82440
public static <T> Set<T> iteratorToSet(Iterator<T> iterator) {
        Set<T> set = new HashSet<>();
        while (iterator.hasNext()) {
            set.add(iterator.next());
        }
        return set;
    }
1003040
public static <T> Iterator<T> merge(Comparator<T> comp, Iterator<T>... iterators)
    {
        switch (iterators.length)
        {
            case 0:
                throw new IllegalArgumentException("no iterables");
            case 1:
                return iterators[0];
            case 2:
                return new IteratorImpl<>(comp, iterators[0], iterators[1]);
            default:
                return new IteratorImpl<>(comp, iterators[0], merge(comp, Arrays.copyOfRange(iterators, 1, iterators.length)));
        }
    }
80722
public static CharIteratorEx of(final Supplier<? extends CharIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new CharIteratorEx() {
            private CharIterator iter = null;
            private CharIteratorEx iterEx = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iter.hasNext();
            }

            @Override
            public char nextChar() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextChar();
            }

            @Override
            public void skip(long n) {
                N.checkArgNotNegative(n, "n");

                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.skip(n);
                } else {
                    super.skip(n);
                }
            }

            @Override
            public long count() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    return iterEx.count();
                } else {
                    return super.count();
                }
            }

            @Override
            public void close() {
                if (isInitialized == false) {
                    init();
                }

                if (iterEx != null) {
                    iterEx.close();
                }
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                    iterEx = iter instanceof CharIteratorEx ? (CharIteratorEx) iter : null;
                }
            }
        };
    }
210282
public Collection findAll(Iterator it, Constraint constraint) {
		ElementGenerator finder = new IteratorTemplate(it).findAll(constraint);
		final Collection results = new ArrayList();
		finder.run(new Block() {
			protected void handle(Object element) {
				results.add(element);
			}
		});
		return results;
	}
708358
public void addRange(int first, int last) {
        int ele;

        for (ele = first; ele <= last; ele++) {
            add(ele);
        }
    }
1239804
public int addLast(Iterable<? extends KTypeCursor<? extends KType>> iterable) {
    int size = 0;
    for (KTypeCursor<? extends KType> cursor : iterable) {
      addLast(cursor.value);
      size++;
    }
    return size;
  }
280357
public static <T> boolean addAllIterable(Iterable<? extends T> iterable, Collection<T> targetCollection)
    {
        if (iterable == null)
        {
            throw new NullPointerException();
        }
        if (iterable instanceof Collection<?>)
        {
            return targetCollection.addAll((Collection<T>) iterable);
        }
        int oldSize = targetCollection.size();
        Iterate.forEachWith(iterable, Procedures2.<T>addToCollection(), targetCollection);
        return targetCollection.size() != oldSize;
    }
537070
public void add(LCMSRange range) {
    Integer msLevel = range.getMsLevel();
    DoubleRange mzRange = range.getMzRange();
    Range<Integer> scanRange = range.getScanRange();

    if (msLevel == null) {
      // add to the top level range set
      anyLvlSet.add(scanRange);
      // remove from all underlying sets
      for (Map.Entry<Integer, MsLevelRangeSet> lvlMapEntry : lvlMap.entrySet()) {
        MsLevelRangeSet msLevelRangeSet = lvlMapEntry.getValue();
        msLevelRangeSet.removeFromAll(range);
      }
      return;
    }

    TreeRangeSet<Integer> scanRangeLeft = TreeRangeSet.create();
    scanRangeLeft.removeAll(anyLvlSet);
    if (scanRangeLeft.isEmpty()) {
      return; // if there's nothing left in the scan range, just stop
    }

    MsLevelRangeSet msLvlRanges = lvlMap.get(msLevel);
    if (msLvlRanges == null) {
      msLvlRanges = new MsLevelRangeSet();
      lvlMap.put(msLevel, msLvlRanges);
    }
    if (mzRange == null) {
      // add to any-mz-range range set
      msLvlRanges.anyPrecursorSet.addAll(scanRangeLeft);
      // remove from all specific mz-range sets
      msLvlRanges.removeFromSpecific(range);
      return;
    }

    scanRangeLeft.removeAll(msLvlRanges.anyPrecursorSet);
    if (scanRangeLeft.isEmpty()) {
      return;
    }

    RangeSet<Integer> rangeSetForMzRange = msLvlRanges.rngMap.get(mzRange);
    if (rangeSetForMzRange == null) {
      rangeSetForMzRange = TreeRangeSet.create();
      msLvlRanges.rngMap.put(mzRange, rangeSetForMzRange);
    }
    rangeSetForMzRange.addAll(scanRangeLeft);
  }
99929
public void addNumberRangeFilter(String key, SizeRange sizeRange) {
        JsonObject opObj = new JsonObject();

        if (sizeRange.getLowerBoundBytes() != 0) {
            opObj.add("gt", sizeRange.getLowerBoundBytes());
        }
        if (sizeRange.getUpperBoundBytes() != 0) {
            opObj.add("lt", sizeRange.getUpperBoundBytes());
        }

        this.filtersList.add(key, opObj);
    }
825778
@Override
    public DoubleColumn fillWith(final DoubleIterator iterator) {
        for (int r = 0; r < size(); r++) {
            if (!iterator.hasNext()) {
                break;
            }
            set(r, iterator.nextDouble());
        }
        return this;
    }
299306
static <E> boolean addAllImpl(Multiset<E> self, Collection<? extends E> elements) {
    if (elements.isEmpty()) {
      return false;
    }
    if (elements instanceof Multiset) {
      Multiset<? extends E> that = cast(elements);
      for (Entry<? extends E> entry : that.entrySet()) {
        self.add(entry.getElement(), entry.getCount());
      }
    } else {
      Iterators.addAll(self, elements.iterator());
    }
    return true;
  }
1200442
@SequentialOnly
    public BiIterator<K, V> iterator() {
        final ObjIterator<Entry<K, V>> iter = s.iterator();

        final BooleanSupplier hasNext = new BooleanSupplier() {
            @Override
            public boolean getAsBoolean() {
                return iter.hasNext();
            }
        };

        final Consumer<Pair<K, V>> output = new Consumer<Pair<K, V>>() {
            private Entry<K, V> entry = null;

            @Override
            public void accept(Pair<K, V> t) {
                entry = iter.next();
                t.set(entry.getKey(), entry.getValue());
            }
        };

        return BiIterator.generate(hasNext, output);
    }