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

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

Introduction

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

Prototype

public static int size(Iterator<?> iterator) 

Source Link

Document

Returns the number of elements remaining in iterator .

Usage

From source file:org.apache.accumulo.examples.shard.ContinuousQuery.java

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchScannerOpts bsOpts = new BatchScannerOpts();
    opts.parseArgs(ContinuousQuery.class.getName(), args, bsOpts);

    Connector conn = opts.getConnector();

    ArrayList<Text[]> randTerms = findRandomTerms(conn.createScanner(opts.doc2Term, opts.auths), opts.numTerms);

    Random rand = new Random();

    BatchScanner bs = conn.createBatchScanner(opts.tableName, opts.auths, bsOpts.scanThreads);
    bs.setTimeout(bsOpts.scanTimeout, TimeUnit.MILLISECONDS);

    for (long i = 0; i < opts.iterations; i += 1) {
        Text[] columns = randTerms.get(rand.nextInt(randTerms.size()));

        bs.clearScanIterators();//from   ww w  .j av a 2s.  co m
        bs.clearColumns();

        IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class);
        IntersectingIterator.setColumnFamilies(ii, columns);
        bs.addScanIterator(ii);
        bs.setRanges(Collections.singleton(new Range()));

        long t1 = System.currentTimeMillis();
        int count = Iterators.size(bs.iterator());
        long t2 = System.currentTimeMillis();

        System.out.printf("  %s %,d %6.3f%n", Arrays.asList(columns), count, (t2 - t1) / 1000.0);
    }

    bs.close();

}

From source file:com.bbn.poi.xdgf.parsers.Util.java

public static void saveToGraphml(Graph graph, String filename) {

    GraphMLWriter writer = new GraphMLWriter(graph);
    writer.setNormalize(true);//from w  ww .j av a 2  s. com

    writer.setEdgeLabelKey("label");

    System.out.println("** Writing graph to " + filename);
    System.out.println("** -> " + Iterators.size(graph.getVertices().iterator()) + " Nodes"
            + Iterators.size(graph.getEdges().iterator()) + " Edges");

    try {
        writer.outputGraph(filename);
    } catch (IOException e) {
        System.err.println("Error writing to " + filename + ": " + e.getMessage());
    }
}

From source file:com.google.googlejavaformat.Newlines.java

/** Returns the number of line breaks in the input. */
public static int count(String input) {
    return Iterators.size(lineOffsetIterator(input)) - 1;
}

From source file:org.bboxdb.storage.queryprocessor.IteratorHelper.java

/**
 * Count the elements for predicate/*from  w w  w . ja  v  a2s.  c  om*/
 * @param predicate
 * @return
 */
public static int getIteratorSize(final Iterator<Tuple> iterator) {
    return Iterators.size(iterator);
}

From source file:org.janusgraph.testutil.JanusGraphAssert.java

public static int size(Object obj) {
    Preconditions.checkArgument(obj != null);
    if (obj instanceof Traversal)
        return size(((Traversal) obj).toList());
    else if (obj instanceof Collection)
        return ((Collection) obj).size();
    else if (obj instanceof Iterable)
        return Iterables.size((Iterable) obj);
    else if (obj instanceof Iterator)
        return Iterators.size((Iterator) obj);
    else if (obj.getClass().isArray())
        return Array.getLength(obj);
    throw new IllegalArgumentException("Cannot determine size of: " + obj);
}

From source file:fr.inria.atlanmod.neoemf.benchmarks.query.QueryFactory.java

public static Query<Integer> queryCountAllElements(Resource resource) {
    return () -> Iterators.size(resource.getAllContents());
}

From source file:qdg.contrib.DegreeCentrality.java

/**
 * Degree centrality scores are computed for all nodes.
 *//*from   ww w  .j  a  v a2 s .c om*/
public void compute() {
    for (Node n : g.getNodes()) {
        score.put(n, (double) Iterators.size(g.getOutArcIterator(n)));
    }
}

From source file:org.gitools.analysis.stats.mtc.BonferroniMtcFunction.java

@Override
public void onBeforeIterate(IMatrixIterable<Double> parentIterable) {
    n = Iterators.size(parentIterable.filter(new InvalidDoubleFilter()).iterator());
}

From source file:com.metamx.druid.indexer.Utils.java

public static <K, V> Map<K, V> zipMap(Iterable<K> keys, Iterable<V> values) {
    Map<K, V> retVal = new HashMap<K, V>();

    Iterator<K> keyIter = keys.iterator();
    Iterator<V> valsIter = values.iterator();
    while (keyIter.hasNext()) {
        final K key = keyIter.next();

        Preconditions.checkArgument(valsIter.hasNext(),
                "keys longer than vals, bad, bad vals.  Broke on key[%s]", key);
        retVal.put(key, valsIter.next());
    }/*w w  w. ja v a2  s .c  o  m*/
    if (valsIter.hasNext()) {
        throw new ISE("More values[%d] than keys[%d]", retVal.size() + Iterators.size(valsIter), retVal.size());
    }

    return retVal;
}

From source file:com.metamx.common.collect.Utils.java

/** Create a Map from iterables of keys and values. Will throw an exception if there are more keys than values,
 *  or more values than keys. *///www  .jav a  2 s  . com
public static <K, V> Map<K, V> zipMap(Iterable<K> keys, Iterable<V> values) {
    Map<K, V> retVal = new LinkedHashMap<>();

    Iterator<K> keysIter = keys.iterator();
    Iterator<V> valsIter = values.iterator();

    while (keysIter.hasNext()) {
        final K key = keysIter.next();

        Preconditions.checkArgument(valsIter.hasNext(),
                "number of values[%s] less than number of keys, broke on key[%s]", retVal.size(), key);

        retVal.put(key, valsIter.next());
    }

    Preconditions.checkArgument(!valsIter.hasNext(), "number of values[%s] exceeds number of keys[%s]",
            retVal.size() + Iterators.size(valsIter), retVal.size());

    return retVal;
}