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:org.geogit.osm.changeset.internal.CreateOSMChangesetOp.java
/** * Executes the diff operation./*from w w w .j a v a 2 s.c om*/ * * @return an iterator to a set of differences between the two trees * @see DiffEntry */ @Override public Iterator<ChangeContainer> call() { Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME) .setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call(); Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME) .setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call(); Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator); final EntityConverter converter = new EntityConverter(); Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() { @Override @Nullable public ChangeContainer apply(@Nullable DiffEntry diff) { NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject() : diff.getNewObject(); RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId()) .call(RevFeature.class).get(); RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId()) .call(RevFeatureType.class).get(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( (SimpleFeatureType) revFeatureType.type()); ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors(); ImmutableList<Optional<Object>> values = revFeature.getValues(); for (int i = 0; i < descriptors.size(); i++) { PropertyDescriptor descriptor = descriptors.get(i); Optional<Object> value = values.get(i); featureBuilder.set(descriptor.getName(), value.orNull()); } SimpleFeature feature = featureBuilder.buildFeature(ref.name()); Entity entity = converter.toEntity(feature); EntityContainer container; if (entity instanceof Node) { container = new NodeContainer((Node) entity); } else { container = new WayContainer((Way) entity); } ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete; return new ChangeContainer(container, action); } }; return Iterators.transform(iterator, function); }
From source file:org.calrissian.mango.collect.CloseableIterators.java
/** * Returns a closeable iterator that applies {@code function} to each element of {@code * fromIterator}.// w w w.j a v a2 s.c o m */ public static <F, T> CloseableIterator<T> transform(CloseableIterator<F> iterator, Function<F, T> function) { return wrap(Iterators.transform(iterator, function), iterator); }
From source file:es.usc.citius.composit.wsc08.data.WSCLazyServiceProvider.java
@Override public Iterable<Operation<Concept>> getOperations() { // Returns an iterable of transformed operations. // Operations are transformed dynamically and not beforehand. return new Iterable<Operation<Concept>>() { @Override/* ww w .j a va 2 s .c om*/ public Iterator<Operation<Concept>> iterator() { return Iterators.transform(delegatedProvider.getOperations().iterator(), new Function<Operation<String>, Operation<Concept>>() { @Override public Operation<Concept> apply(Operation<String> op) { return translate(op); } }); } }; }
From source file:qdg.StaticMixedGraph.java
@Override public Iterator<Edge> getArcIterator() { return Iterators.transform(new IndexIterator<EdgeData>(arcs), constructArc); }
From source file:org.apache.marmotta.commons.collections.EquivalenceHashSet.java
/** * Returns an iterator over the elements in this set. The elements are * returned in no particular order (unless this set is an instance of some * class that provides a guarantee)./* w w w . j a v a2s. co m*/ * * @return an iterator over the elements in this set */ @Override public Iterator<E> iterator() { return Iterators.transform(delegate.iterator(), unwrapper); }
From source file:org.locationtech.geogig.geotools.plumbing.ExportOp.java
/** * Executes the export operation using the parameters that have been specified. * /*w w w .ja v a 2 s . c o m*/ * @return a FeatureCollection with the specified features */ @Override protected SimpleFeatureStore _call() { final ObjectDatabase database = objectDatabase(); if (filterFeatureTypeId != null) { RevObject filterType = database.getIfPresent(filterFeatureTypeId); checkArgument(filterType instanceof RevFeatureType, "Provided filter feature type is does not exist"); } final SimpleFeatureStore targetStore = getTargetStore(); final String refspec = resolveRefSpec(); final String treePath = refspec.substring(refspec.indexOf(':') + 1); final RevTree rootTree = resolveRootTree(refspec); final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree); final ObjectId defaultMetadataId = typeTreeRef.getMetadataId(); final RevTree typeTree = database.getTree(typeTreeRef.objectId()); final ProgressListener progressListener = getProgressListener(); progressListener.started(); progressListener .setDescription("Exporting from " + path + " to " + targetStore.getName().getLocalPart() + "... "); final Iterator<SimpleFeature> filtered; { final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database, defaultMetadataId, progressListener); Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId); Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures, ExportOp.this.function); Iterator<SimpleFeature> result = Iterators .filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() { @Override public SimpleFeature apply(Optional<Feature> input) { return (SimpleFeature) input.orNull(); } }), Predicates.notNull()); // check the resulting schema has something to contribute PeekingIterator<SimpleFeature> peekingIt = Iterators.peekingIterator(result); if (peekingIt.hasNext()) { Function<AttributeDescriptor, String> toString = new Function<AttributeDescriptor, String>() { @Override public String apply(AttributeDescriptor input) { return input.getLocalName(); } }; SimpleFeature peek = peekingIt.peek(); Set<String> sourceAtts = new HashSet<String>( Lists.transform(peek.getFeatureType().getAttributeDescriptors(), toString)); Set<String> targetAtts = new HashSet<String>( Lists.transform(targetStore.getSchema().getAttributeDescriptors(), toString)); if (Sets.intersection(sourceAtts, targetAtts).isEmpty()) { throw new GeoToolsOpException(StatusCode.UNABLE_TO_ADD, "No common attributes between source and target feature types"); } } filtered = peekingIt; } FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() { @Override public FeatureIterator<SimpleFeature> features() { return new DelegateFeatureIterator<SimpleFeature>(filtered); } }; // add the feature collection to the feature store final Transaction transaction; if (transactional) { transaction = new DefaultTransaction("create"); } else { transaction = Transaction.AUTO_COMMIT; } try { targetStore.setTransaction(transaction); try { targetStore.addFeatures(asFeatureCollection); transaction.commit(); } catch (final Exception e) { if (transactional) { transaction.rollback(); } Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class); throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } finally { transaction.close(); } } catch (IOException e) { throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } progressListener.complete(); return targetStore; }
From source file:org.apache.arrow.flight.FlightClient.java
/** * Performs an action on the Flight service. * * @param action The action to perform./*from w w w . j ava2 s . c o m*/ * @param options RPC-layer hints for this call. * @return An iterator of results. */ public Iterator<Result> doAction(Action action, CallOption... options) { return Iterators.transform(CallOptions.wrapStub(blockingStub, options).doAction(action.toProtocol()), Result::new); }
From source file:qdg.view.UGraphAsDiGraph.java
@Override public Iterator<Edge> getIncidentArcIterator(Node node) { Iterator<Edge> forwardUEdges = Iterators.transform(g.getIncidentEdgeIterator(node), forwardEdge); Iterator<Edge> backwardUEdges = Iterators.transform(g.getIncidentUEdgeIterator(node), backwardEdge); return new ConcatIterator<Edge>(forwardUEdges, backwardUEdges); }
From source file:org.kiji.schema.impl.cassandra.RowDecoders.java
/** * Create a new qualified column result set decoder function. * * @param column The Kiji column of the Row. * @param decoderProvider A cell decoder provider for the table. * @param <T> The value type in the column. * @return A decoded cell./* www. j a v a 2 s . c o m*/ */ public static <T> Function<ResultSet, Iterator<KijiCell<T>>> getQualifiedColumnDecoderFunction( final KijiColumnName column, final CellDecoderProvider decoderProvider) { // No min/max timestamp or max versions filter is needed, because the CQL statement for // qualified gets only selects the required cells. return new Function<ResultSet, Iterator<KijiCell<T>>>() { /** {@inheritDoc} */ @Override public Iterator<KijiCell<T>> apply(final ResultSet resultSet) { final Function<Row, KijiCell<T>> decoder = new QualifiedColumnDecoder<>(column, decoderProvider.<T>getDecoder(column)); return Iterators.transform(resultSet.iterator(), decoder); } }; }
From source file:com.freiheit.fuava.simplebatch.http.ConvertingHttpPagingFetcher.java
@Override public Iterable<Result<FetchedItem<T>, T>> fetchAll() { return new Iterable<Result<FetchedItem<T>, T>>() { @Override/*from w w w. j a v a 2s. c om*/ public Iterator<Result<FetchedItem<T>, T>> iterator() { final Iterator<Result<PagingInput, Iterable<Raw>>> iterator = new LazyPageFetchingIterable<Iterable<Raw>>( new HttpPageFetcher<Iterable<Raw>>(fetcher, settings, converter), initialFrom, pageSize, settings); return Iterators.concat(Iterators.transform(iterator, resultTransformer)); } }; }