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.google.enterprise.connector.ldap.LdapPersonRepository.java

@Override
public Iterator<LdapPerson> iterator() throws SnapshotRepositoryRuntimeException {
    final Function<JsonDocument, LdapPerson> f = new LoggingFunction();
    return Iterators.transform(personFetcher.iterator(), f);
}

From source file:org.apache.fluo.core.log.TracingColumnScanner.java

@Override
public Iterator<ColumnValue> iterator() {
    return Iterators.transform(cs.iterator(), cv -> {
        log.trace("txid: {} scanId: {} next()-> {} {} {}", txid, scanId, encRow,
                Hex.encNonAscii(cv.getColumn()), Hex.encNonAscii(cv.getValue()));
        return cv;
    });//from w w w  .  ja  va  2  s.c o m
}

From source file:org.apache.crunch.impl.spark.fn.FlatMapPairDoFn.java

@Override
public Iterable<T> call(Iterator<Tuple2<K, V>> input) throws Exception {
    ctxt.initialize(fn, null);//from ww w.ja va2  s.  c o  m
    return new CrunchIterable<Pair<K, V>, T>(fn, Iterators.transform(input, GuavaUtils.<K, V>tuple2PairFunc()));
}

From source file:org.seedstack.seed.web.internal.security.shiro.SimpleFilterChainResolver.java

public FilterChain getChain(ServletRequest request, ServletResponse response, final FilterChain originalChain) {
    String path = WebUtils.getPathWithinApplication(WebUtils.toHttp(request));
    for (final String pathPattern : chains.keySet()) {
        if (patternMatcher.matches(pathPattern, path)) {
            return new SimpleFilterChain(originalChain,
                    Iterators.transform(Iterators.forArray(chains.get(pathPattern)),
                            (Function<ShiroWebModule.FilterKey, Filter>) input -> injector
                                    .getInstance(input.getKey())));
        }/*from w ww .  j  ava2  s.  co m*/
    }
    return null;
}

From source file:org.apache.mahout.fpm.pfpgrowth.convertors.TransactionIterator.java

public TransactionIterator(Iterator<Pair<List<T>, Long>> transactions,
        final Map<T, Integer> attributeIdMapping) {
    transactionBuffer = new int[attributeIdMapping.size()];
    delegate = Iterators.transform(transactions, new Function<Pair<List<T>, Long>, Pair<int[], Long>>() {
        @Override/*www . j  a va2s  .  c o m*/
        public Pair<int[], Long> apply(Pair<List<T>, Long> from) {
            int index = 0;
            if (from == null) {
                return null;
            }
            for (T attribute : from.getFirst()) {
                if (attributeIdMapping.containsKey(attribute)) {
                    transactionBuffer[index++] = attributeIdMapping.get(attribute);
                }
            }
            int[] transactionList = new int[index];
            System.arraycopy(transactionBuffer, 0, transactionList, 0, index);
            return new Pair<int[], Long>(transactionList, from.getSecond());
        }
    });
}

From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java

public static <T> Iterator<RowResult<T>> viewOfEntries(
        Iterator<Map.Entry<byte[], SortedMap<byte[], T>>> mapEntries) {
    Function<Entry<byte[], SortedMap<byte[], T>>, RowResult<T>> f = createRowResultFunction();
    return Iterators.transform(mapEntries, f);
}

From source file:com.cg.mapreduce.fpgrowth.mahout.fpm.convertors.TransactionIterator.java

public TransactionIterator(Iterator<Pair<List<T>, Long>> transactions,
        final Map<T, Integer> attributeIdMapping) {
    transactionBuffer = new int[attributeIdMapping.size()];
    delegate = Iterators.transform(transactions, new Function<Pair<List<T>, Long>, Pair<int[], Long>>() {
        @Override//from www  .  j a v  a  2  s .  c  om
        public Pair<int[], Long> apply(Pair<List<T>, Long> from) {
            if (from == null) {
                return null;
            }
            int index = 0;
            for (T attribute : from.getFirst()) {
                if (attributeIdMapping.containsKey(attribute)) {
                    transactionBuffer[index++] = attributeIdMapping.get(attribute);
                }
            }
            int[] transactionList = new int[index];
            System.arraycopy(transactionBuffer, 0, transactionList, 0, index);
            return new Pair<int[], Long>(transactionList, from.getSecond());
        }
    });
}

From source file:com.anjuke.romar.mahout.similarity.file.RomarFileSimilarityIterator.java

private RomarFileSimilarityIterator(DataFileIterator fileIterator, final SimilarityBuilder<T> builder) {
    _delegate = Iterators.transform(fileIterator, new Function<byte[], T>() {
        public T apply(byte[] input) {
            ByteBuffer buffer = ByteBuffer.wrap(input);
            return builder.create(buffer.getLong(), buffer.getLong(), buffer.getDouble());
        }//from   w w  w  .  j a va2s .c o m
    });
}

From source file:org.apache.fluo.core.log.TracingCellScanner.java

@Override
public Iterator<RowColumnValue> iterator() {
    return Iterators.transform(wrappedScanner.iterator(), rcv -> {
        log.trace("txid: {} scanId: {} next()-> {} {}", txid, scanId, Hex.encNonAscii(rcv.getRowColumn()),
                Hex.encNonAscii(rcv.getValue()));
        return rcv;
    });/*from  w  w w. j  a v  a2  s . c om*/
}

From source file:org.apache.parquet.cli.json.AvroJsonReader.java

public AvroJsonReader(InputStream stream, Schema schema) {
    this.stream = stream;
    this.schema = schema;
    this.model = GenericData.get();
    this.iterator = Iterators.transform(AvroJson.parser(stream), new Function<JsonNode, E>() {
        @Override//from   ww  w  . j  a  v  a  2  s .c  om
        @SuppressWarnings("unchecked")
        public E apply(@Nullable JsonNode node) {
            return (E) AvroJson.convertToAvro(model, node, AvroJsonReader.this.schema);
        }
    });
}