Example usage for com.google.common.collect Iterators transform

List of usage examples for com.google.common.collect Iterators transform

Introduction

In this page you can find the example usage for com.google.common.collect Iterators transform.

Prototype

public static <F, T> Iterator<T> transform(final Iterator<F> fromIterator,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterator that applies function to each element of fromIterator .

Usage

From source file:com.torodb.kvdocument.conversion.mongowp.MongoWpConverter.java

public static KvArray toEagerArray(BsonArray array) {
    return new ListKvArray(Lists.newArrayList(Iterators.transform(array.iterator(), FROM_BSON)));
}

From source file:com.textocat.textokit.eval.cas.FSCasDirectory.java

/**
 * {@inheritDoc}//from ww  w.ja v a 2  s.  com
 */
@Override
public Iterator<CAS> iterator() {
    Iterator<File> xmiFileIter = getXmiFiles().iterator();
    return Iterators.transform(xmiFileIter, deserializeFunc());
}

From source file:org.eclipse.papyrus.uml.diagram.activity.listeners.InInterruptibleActivityRegionListener.java

/**
 * Get the list of all starting or ending Interruptible Edge wich are related to this {@link ActivityNode} and its descendant.
 * Those Iterable can be filled with null elements so test each element for null
 * /*from w  ww  . j av a2 s .c o  m*/
 * @param node
 * @return
 */
public Iterator<Iterable<ActivityEdge>> getActivityEdgeImpactedWithThisChange(ActivityNode node) {
    Iterator<Iterable<ActivityEdge>> activityEdges = Iterators.transform(
            Iterators.concat(Collections.singleton(node).iterator(), node.eAllContents()),
            new Function<EObject, Iterable<ActivityEdge>>() {

                public Iterable<ActivityEdge> apply(EObject from) {
                    if (from instanceof ActivityNode) {
                        ActivityNode activityNode = (ActivityNode) from;
                        Iterable<ActivityEdge> incomingInterruptibleEdge = Iterables
                                .filter(activityNode.getIncomings(), new Predicate<EObject>() {

                                    public boolean apply(EObject input) {
                                        if (input instanceof ActivityEdge) {
                                            return ((ActivityEdge) input).getInterrupts() != null;
                                        }
                                        return false;
                                    }
                                });
                        Iterable<ActivityEdge> outcomingEdgeInterruptibleEdge = Iterables
                                .filter(activityNode.getOutgoings(), new Predicate<EObject>() {

                                    public boolean apply(EObject input) {
                                        if (input instanceof ActivityEdge) {
                                            return ((ActivityEdge) input).getInterrupts() != null;
                                        }
                                        return false;
                                    }
                                });
                        Iterable<ActivityEdge> allInterruptibleEdge = Iterables
                                .concat(outcomingEdgeInterruptibleEdge, incomingInterruptibleEdge);
                        if (!Iterables.isEmpty(allInterruptibleEdge)) {
                            return allInterruptibleEdge;
                        }
                    }
                    return null;
                }
            });
    return activityEdges;
}

From source file:org.apache.jackrabbit.oak.jcr.delegate.GroupDelegator.java

@Override
public Iterator<Authorizable> getMembers() throws RepositoryException {
    return sessionDelegate.perform(new SessionOperation<Iterator<Authorizable>>("getMembers") {
        @Nonnull/*from   w ww  . j ava  2 s  .  c  om*/
        @Override
        public Iterator<Authorizable> perform() throws RepositoryException {
            Iterator<Authorizable> authorizables = getDelegate().getMembers();
            return Iterators.transform(authorizables, new Function<Authorizable, Authorizable>() {
                @Nullable
                @Override
                public Authorizable apply(@Nullable Authorizable authorizable) {
                    return wrap(sessionDelegate, authorizable);
                }
            });
        }
    });
}

From source file:org.grouplens.lenskit.vectors.Vectors.java

/**
 * Iterate over the intersection of two vectors - they keys they have in common.
 * @param v1 The first vector./* w ww  . ja va  2s . c o m*/
 * @param v2 The second vector.
 * @return An iterator over the common pairs. This iterator will never contain null entries.
 */
public static Iterable<ImmutablePair<VectorEntry, VectorEntry>> intersect(final SparseVector v1,
        final SparseVector v2) {
    return new Iterable<ImmutablePair<VectorEntry, VectorEntry>>() {
        @Override
        public Iterator<ImmutablePair<VectorEntry, VectorEntry>> iterator() {
            return Iterators.transform(new FastIntersectIterImpl(v1, v2), IMMUTABLE_PAIR_COPY);
        }
    };
}

From source file:org.kitesdk.data.spi.filesystem.JSONFileReader.java

@Override
public void initialize() {
    Preconditions.checkState(state.equals(ReaderWriterState.NEW),
            "A reader may not be opened more than once - current state:%s", state);
    Preconditions.checkArgument(Schema.Type.RECORD.equals(schema.getType()),
            "Schemas for JSON files should be record");

    if (incoming == null) {
        Preconditions.checkNotNull(fs, "FileSystem cannot be null");
        Preconditions.checkNotNull(path, "Path cannot be null");
        try {/*ww w .j  a  v  a  2s . c o m*/
            this.incoming = fs.open(path);
            this.size = fs.getFileStatus(path).getLen();
        } catch (IOException ex) {
            throw new DatasetIOException("Cannot open path: " + path, ex);
        }
    }

    this.iterator = Iterators.transform(JsonUtil.parser(incoming), new Function<JsonNode, E>() {
        @Override
        @SuppressWarnings("unchecked")
        public E apply(@Nullable JsonNode node) {
            return (E) JsonUtil.convertToAvro(model, node, schema);
        }
    });

    this.state = ReaderWriterState.OPEN;
}

From source file:com.davidbracewell.math.linear.VectorMap.java

@Override
public Set<Entry<Integer, Double>> entrySet() {
    return new AbstractSet<Entry<Integer, Double>>() {
        @Override/* w  w  w . ja  va  2  s.c  om*/
        public Iterator<Entry<Integer, Double>> iterator() {
            return Iterators.transform(vector.iterator(), new Function<DoubleEntry, Entry<Integer, Double>>() {
                @Nullable
                @Override
                public Entry<Integer, Double> apply(@Nullable DoubleEntry input) {
                    return input == null ? null : Pair.of(input.index, input.value);
                }
            });
        }

        @Override
        public int size() {
            return vector.dimension();
        }
    };
}

From source file:io.crate.analyze.WhereClause.java

@Nullable
public Set<String> routingValues() {
    if (clusteredBy.isPresent()) {
        HashSet<String> result = new HashSet<>(clusteredBy.get().size());
        Iterators.addAll(result,//from  www .  j  a  v a 2s .  co  m
                Iterators.transform(clusteredBy.get().iterator(), ValueSymbolVisitor.STRING.function));
        return result;
    } else {
        return null;
    }
}

From source file:org.fcrepo.kernel.impl.rdf.impl.TypeRdfContext.java

private void concatRdfTypes() throws RepositoryException {
    final ImmutableList.Builder<NodeType> nodeTypesB = ImmutableList.<NodeType>builder();

    final NodeType primaryNodeType = resource().getNode().getPrimaryNodeType();

    if (primaryNodeType != null) {
        nodeTypesB.add(primaryNodeType);
    }// w  w w  .j av  a2s  .  c  om

    try {
        final Set<NodeType> primarySupertypes = ImmutableSet.<NodeType>builder()
                .add(primaryNodeType.getSupertypes()).build();
        nodeTypesB.addAll(primarySupertypes);
    } catch (NullPointerException e) {
        // ignore
    }

    final NodeType[] mixinNodeTypesArr = resource().getNode().getMixinNodeTypes();

    if (mixinNodeTypesArr != null) {
        final Set<NodeType> mixinNodeTypes = ImmutableSet.<NodeType>builder().add(mixinNodeTypesArr).build();
        nodeTypesB.addAll(mixinNodeTypes);

        final ImmutableSet.Builder<NodeType> mixinSupertypes = ImmutableSet.<NodeType>builder();
        for (final NodeType mixinNodeType : mixinNodeTypes) {
            mixinSupertypes.addAll(ImmutableSet.<NodeType>builder().add(mixinNodeType.getSupertypes()).build());
        }

        nodeTypesB.addAll(mixinSupertypes.build());
    }

    final ImmutableList<NodeType> nodeTypes = nodeTypesB.build();
    final Iterator<NodeType> nodeTypesIt = nodeTypes.iterator();

    concat(Iterators.transform(nodeTypesIt, nodetype2triple()));
}

From source file:org.trancecode.concurrent.ParallelIterators.java

private static <T> Iterator<T> getUntilLast(final Iterator<Future<T>> futures) {
    final Future<T> last = last();
    final Iterator<Future<T>> futuresUntilLast = TcIterators.until(futures, TcPredicates.identicalTo(last));
    final Function<Future<T>, T> function = FutureFunctions.get();
    return Iterators.transform(futuresUntilLast, function);
}