/** * Gets an iterator that transforms the elements of another iterator. * <p> * The transformation occurs during the next() method and the underlying * iterator is unaffected by the transformation. * * @param <I> the input type * @param <O> the output type * @param iterator the iterator to use, not null * @param transform the transform to use, not null * @return a new transforming iterator * @throws NullPointerException if either parameter is null */ public static <I, O> Iterator<O> transformedIterator(final Iterator<? extends I> iterator, final Transformer<? super I, ? extends O> transform) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (transform == null) { throw new NullPointerException("Transformer must not be null"); } return new TransformIterator<>(iterator, transform); }
/** * Gets the next object from the iteration, transforming it using the * current transformer. If the transformer is null, no transformation * occurs and the object from the iterator is returned directly. * * @return the next object * @throws java.util.NoSuchElementException if there are no more elements */ @Override public O next() { return transform(iterator.next()); }
private O getNext() { boolean done = false; O o = null; while (super.hasNext() && !done) { try { o = super.next(); done = true; } catch (EmptyObjectException e) { // not yet done, so continue fetching next } } // see if there are any results cached by the transformer if (o == null && getTransformer() instanceof Flushable) { done = false; while (!done) { try { o = ((Flushable<O>) getTransformer()).flush(); done = true; } catch (EmptyObjectException e) { // not yet done, so continue flushing } } } return o; } }
@Override @SuppressWarnings("unchecked") public TransformIterator getTransformIterator(Query settings) { TransformIterator origIter = super.getTransformIterator(settings); QueryLogicTransformer transformer = super.getTransformer(settings); DashboardSummary summary = new DashboardSummary(settings.getEndDate()); while (origIter.hasNext()) { EventBase event = (EventBase) transformer.transform(origIter.next()); DashboardFields.addEvent(summary, event); } return new TransformIterator(Arrays.asList(summary).iterator(), this); }
while (!this.finished && ((future != null) || this.iter.hasNext())) { if (executor != null) { if (future == null) { future = executor.submit(() -> iter.next()); o = iter.next(); if (iter.getTransformer() instanceof WritesQueryMetrics) { ((WritesQueryMetrics) iter.getTransformer()).writeQueryMetrics(this.getMetric());
public void closeConnection(AccumuloConnectionFactory factory) throws Exception { this.getMetric().setLifecycle(BaseQueryMetric.Lifecycle.CLOSED); if (iter != null && iter.getTransformer() instanceof WritesResultCardinalities) { ((WritesResultCardinalities) iter.getTransformer()).writeResultCardinalities();
if (this.getMaxResults() < 0) this.setMaxResults(Long.MAX_VALUE); while ((null != last) && !interrupted && transformIterator.hasNext() && (resultCount < this.getMaxResults())) { try { last = transformIterator.next(); if (null != last) { log.debug(Thread.currentThread().getName() + ": Added object to results");
new QueryMetricFactoryImpl()); TransformIterator it = runner.getTransformIterator(); ShardQueryCountTableTransformer ctt = (ShardQueryCountTableTransformer) it.getTransformer(); EventQueryResponseBase resp = (EventQueryResponseBase) ctt.createResponse(runner.next());
@Override public Iterator<AbstractBackupPath> listPrefixes(Date date) { String prefix = pathProvider.get().clusterPrefix(getPrefix().toString()); Iterator<String> fileIterator = listFileSystem(prefix, File.pathSeparator, null); //noinspection unchecked return new TransformIterator( fileIterator, remotePath -> { AbstractBackupPath abstractBackupPath = pathProvider.get(); abstractBackupPath.parsePartialPrefix(remotePath.toString()); return abstractBackupPath; }); }
@Override protected Iterator<? extends Entry<K, V>> nextIterator(final int count) { if ( ! keyIterator.hasNext() ) { return null; } final K key = keyIterator.next(); final Transformer<V, Entry<K, V>> transformer = new Transformer<V, Entry<K, V>>() { @Override public Entry<K, V> transform(final V input) { return new Entry<K, V>() { @Override public K getKey() { return key; } @Override public V getValue() { return input; } @Override public V setValue(final V value) { throw new UnsupportedOperationException(); } }; } }; return new TransformIterator<>(new ValuesIterator(key), transformer); } };
@Override public Iterator<AbstractBackupPath> list(String path, Date start, Date till) { String prefix = pathProvider.get().remotePrefix(start, till, path); Iterator<String> fileIterator = listFileSystem(prefix, null, null); @SuppressWarnings("unchecked") TransformIterator<String, AbstractBackupPath> transformIterator = new TransformIterator( fileIterator, remotePath -> { AbstractBackupPath abstractBackupPath = pathProvider.get(); abstractBackupPath.parseRemote(remotePath.toString()); return abstractBackupPath; }); return new FilterIterator<>( transformIterator, abstractBackupPath -> (abstractBackupPath.getTime().after(start) && abstractBackupPath.getTime().before(till)) || abstractBackupPath.getTime().equals(start)); }
Iterator<String> iterator = fs.listFileSystem(incrementalPrefix, null, marker); Iterator<AbstractBackupPath> transformIterator = new TransformIterator<>( iterator, s -> {
@Override protected Iterator<FieldMapByPositionEntry<T>> nextIterator(int count) { if(count <= complexMapList.size()) { return complexMapList.get(count-1).iterator(); } if(count == complexMapList.size()+1) { return new TransformIterator<Map.Entry<Integer, BeanField<T>>, FieldMapByPositionEntry<T>>( simpleMap.entrySet().iterator(), new Transformer<Map.Entry<Integer, BeanField<T>>, FieldMapByPositionEntry<T>>() { @Override public FieldMapByPositionEntry<T> transform(Map.Entry<Integer, BeanField<T>> input) { return new FieldMapByPositionEntry<T>(input.getKey(), input.getValue()); } }); } return null; } };
@Override public TransformIterator getTransformIterator(Query settings) { // The objects put into the pageQueue have already been transformed. // We will iterate over the pagequeue with the No-Op transformer return new TransformIterator(results.iterator(), NOPTransformer.nopTransformer()); }
return Maps.immutableEntry(d.getMetadata(), d); }; TransformIterator inputIterator = new TransformIterator(input.iterator(), docToEntry); UniqueTransform transform = new UniqueTransform(fields); Iterator iter = Iterators.transform(inputIterator, transform);