List of usage examples for com.google.common.collect Iterators transform
public static <F, T> Iterator<T> transform(final Iterator<F> fromIterator, final Function<? super F, ? extends T> function)
From source file:nz.ac.massey.cs.guery.adapters.blueprints.BlueprintsAdapter.java
@Override public Iterator<Edge> getEdges() { return Iterators.transform(g.getEdges().iterator(), this.edgeCaching); }
From source file:com.moz.fiji.schema.impl.FijiResultRowScanner.java
/** * Constructor for {@code FijiResultRowScanner}. * * @param layout The {@code FijiTableLayout} for the table. * @param resultScanner The {@code FijiResultScanner} backing this {@code FijiRowScanner}. This * {@code FijiResultScanner} is owned by the newly created {@code FijiResultRowScanner} and * calling close on this {@code FijiResultRowScanner} will close the underlying * {@code FijiResultScanner}./* w ww. j a v a2s . c om*/ */ public FijiResultRowScanner(final FijiTableLayout layout, final FijiResultScanner<Object> resultScanner) { mLayout = layout; mResultScanner = resultScanner; mResultRowScanner = Iterators.transform(resultScanner, new Function<FijiResult<Object>, FijiRowData>() { @Override public FijiRowData apply(final FijiResult<Object> result) { return new FijiResultRowData(mLayout, result); } }); }
From source file:controllers.DocumentsController.java
public static Result get(final UUID collection, String document) { JsonNode documentNode = Json.parse(document); if (documentNode.isTextual()) { document = String.format("[%s]", document); documentNode = Json.parse(document); }/*from w ww . ja va 2 s . c o m*/ if (documentNode.isArray()) { Iterator<ViewModel> documents = Iterators.transform(documentNode.getElements(), new Function<JsonNode, ViewModel>() { @Override @Nullable public ViewModel apply(@Nullable JsonNode input) { if (!input.isTextual()) { throw new IllegalArgumentException(); } return createViewModel(fetchDocument(collection, UuidUtils.create(input.asText()))); } }); return ok(Json .toJson(Iterators.toArray(Iterators.filter(documents, Predicates.notNull()), ViewModel.class))); } throw new IllegalArgumentException(); }
From source file:org.trancecode.concurrent.ParallelIterators.java
/** * @see Iterators#transform(Iterator, Function) *///from w w w.ja va2 s .c o m public static <F, T> Iterator<T> transform(final Iterator<F> fromIterable, final Function<? super F, ? extends T> function, final ExecutorService executor) { final Function<F, Callable<T>> applyFunction = CallableFunctions.apply(function); final Iterator<Callable<T>> callables = Iterators.transform(fromIterable, applyFunction); final AtomicReference<Future<?>> submitTask = new AtomicReference<>(); final BlockingQueue<Future<T>> futures = new ArrayBlockingQueue<>(MAXIMUM_NUMBER_OF_ELEMENTS_IN_ADVANCE); final Function<Callable<T>, Future<T>> submitFunction = task -> executor.submit(() -> { try { return task.call(); } catch (final Exception e) { final Future<?> taskToCancel = submitTask.get(); if (taskToCancel != null) { taskToCancel.cancel(true); final Future<T> last = last(); futures.add(last); } throw e; } }); submitTask.set(executor.submit(() -> { Iterators.addAll(futures, Iterators.transform(callables, submitFunction)); final Future<T> last = last(); futures.add(last); })); return TcIterators.handleErrors(getUntilLast(TcIterators.removeAll(futures)), error -> { TcFutures.cancel(futures); return null; }); }
From source file:com.addthis.bundle.value.BundleValueMap.java
@Override public Iterator<ValueMapEntry> iterator() { return Iterators.transform(bundle.iterator(), field -> new ValueMapEntry() { @Override/* w w w . ja v a2 s . co m*/ public String getKey() { return field.getName(); } @Override public ValueObject getValue() { return bundle.getValue(field); } @Override public ValueObject setValue(ValueObject value) { ValueObject previousValue = bundle.getValue(field); bundle.setValue(field, value); return previousValue; } }); }
From source file:org.jboss.weld.event.GlobalObserverNotifierService.java
private static Iterable<ObserverMethod<?>> createGlobalObserverMethodIterable( final Set<BeanManagerImpl> beanManagers) { return new Iterable<ObserverMethod<?>>() { @Override// w w w . ja va 2 s . co m public Iterator<ObserverMethod<?>> iterator() { Iterator<Iterator<ObserverMethod<?>>> observerMethodIterators = Iterators .transform(beanManagers.iterator(), new BeanManagerToObserverMethodIterable()); return Iterators.concat(observerMethodIterators); } }; }
From source file:com.boundlessgeo.geoserver.json.JSONArr.java
/** * Returns an iterator over the array.// www . ja v a2 s . c o m * <p> * JSON objects are wrapped upon return, primitives are returned as is. * </p> */ @Override public Iterator<Object> iterator() { return Iterators.transform(raw.iterator(), new Function<Object, Object>() { @Nullable @Override public Object apply(@Nullable Object o) { return JSONWrapper.wrapOrSelf(o); } }); }
From source file:edu.cmu.lti.oaqa.framework.collection.fs.DirCollectionReader.java
@Override protected Iterator<DataElement> getInputSet() throws ResourceInitializationException { String filename = System.getProperty(DIR_PROPERTY); try {/*from w w w . j a v a 2s . co m*/ if (filename == null) { Iterator<Resource> files = getFilesFromParams(); return iterator(files); } else { File file = new File(filename); String[] files = file.list(); return iterator(Iterators.transform(Iterators.forArray(files), new StringToResourceFunction(""))); } } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:org.apache.fluo.recipes.core.combine.InputImpl.java
@Override public Iterator<V> iterator() { Iterator<Bytes> bytesIter = valuesCollection.iterator(); if (currentValue != null) { bytesIter = Iterators.concat(bytesIter, Iterators.singletonIterator(currentValue)); }//from w w w . java 2s . c om return Iterators.transform(bytesIter, valDeser::apply); }
From source file:org.apache.gobblin.util.request_allocation.GreedyAllocator.java
@Override protected Iterator<T> getJoinIterator(Iterator<? extends Requestor<T>> requestors, final ConcurrentBoundedPriorityIterable<T> requestIterable) { Iterator<T> unionIterator = Iterators .concat(Iterators.transform(requestors, new Function<Requestor<T>, Iterator<T>>() { @Nullable/* w ww.j a va2s. c o m*/ @Override public Iterator<T> apply(Requestor<T> input) { return input.iterator(); } })); return new InterruptibleIterator<>(unionIterator, new Callable<Boolean>() { @Override public Boolean call() throws Exception { return requestIterable.isFull(); } }); }