@Override public Iterator<Metric> iterator() { return new FilterIterator<>( new Iterator<Metric>() { private int nextIndex; @Override public boolean hasNext() { return nextIndex < values.length; } @Override public Metric next() { Metric ret = new Metric( name, startTimestamp + nextIndex * step, values[nextIndex] ); nextIndex++; return ret; } }, metric -> !Double.isNaN( metric.value() ) ); }
private Iterable<Metric> getMetrics( E environment, String name, Interval interval ) { return new Iterable<Metric>() { @Override public Iterator<Metric> iterator() { return new FilterIterator<>( _getMetrics( environment, name, interval ).iterator(), metric -> interval.contains( metric.timestamp() ) ); } }; }
private Spliterator<TruthVersusEval> getSpliteratorForDrivingVariants() { final Iterator<VariantContext> truthIterator = new FilterIterator<>(truthVariants.iterator(), makeTruthVariantFilter()); final Iterator<VariantContext> evalIterator = new FilterIterator<>(evalVariants.iterator(), makeEvalVariantFilter()); return new ConcordanceIterator(truthIterator, evalIterator).spliterator(); }
@SuppressWarnings({ CompilerWarnings.UNCHECKED }) public static <T, U> FilterIterator<U> instances(Iterator<T> iterator, Class<U> clazz) { return ((FilterIterator<U>) IteratorUtils.filteredIterator(iterator, PredicateUtils.instanceofPredicate(clazz))); }
/** * Gets an iterator that filters another iterator. * <p> * The returned iterator will only return objects that match the specified * filtering predicate. * * @param <E> the element type * @param iterator the iterator to use, not null * @param predicate the predicate to use as a filter, not null * @return a new filtered iterator * @throws NullPointerException if either parameter is null */ public static <E> Iterator<E> filteredIterator(final Iterator<? extends E> iterator, final Predicate<? super E> predicate) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } return new FilterIterator<E>(iterator, predicate); }