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:qdg.contrib.ClosenessCentrality.java

public ClosenessCentrality(DiGraph g) {
    this(g, g.<Double>createNodeMap(), (double) Iterators.size(g.getNodeIterator()));
}

From source file:sg.atom.utils._beta.functional.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.
 *///  w ww.  jav  a 2  s  .  c  o  m
public static <K, V> Map<K, V> zipMap(Iterable<K> keys, Iterable<V> values) {
    Map<K, V> retVal = new LinkedHashMap<K, V>();

    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;
}

From source file:org.apache.accumulo.test.functional.FunctionalTestUtils.java

public static int countRFiles(Connector c, String tableName) throws Exception {
    Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
    String tableId = c.tableOperations().tableIdMap().get(tableName);
    scanner.setRange(MetadataSchema.TabletsSection.getRange(tableId));
    scanner.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);

    return Iterators.size(scanner.iterator());
}

From source file:eu.numberfour.n4js.ui.export.nfar.NFARExportOperation.java

private int countSelectedResources() {
    int result = 1; // manifest
    for (IN4JSSourceContainer container : project.getSourceContainers()) {
        int numberOfURIs = Iterators.size(container.iterator());
        numberOfURIs *= 2; // compiled variants
        result += numberOfURIs;/*  ww w.j a va2 s.  c  o  m*/
    }
    return result;
}

From source file:org.elasticsearch.rest.action.main.RestMainAction.java

@Inject
public RestMainAction(Settings settings, Client client, RestController controller) {
    super(settings, client);
    JsonNode rootNode;//from   www  . j a v a  2s . c o m
    int quotesSize;
    try {
        rootNode = Jackson.defaultObjectMapper().readValue(Classes.getDefaultClassLoader()
                .getResourceAsStream("org/elasticsearch/rest/action/main/quotes.json"), JsonNode.class);
        ArrayNode arrayNode = (ArrayNode) rootNode.get("quotes");
        quotesSize = Iterators.size(arrayNode.getElements());
    } catch (Exception e) {
        rootNode = null;
        quotesSize = -1;
    }
    this.rootNode = rootNode;
    this.quotesSize = quotesSize;

    controller.registerHandler(GET, "/", this);
}

From source file:com.replaymod.replaystudio.studio.StudioReplayPartView.java

@Override
public int size() {
    return Iterators.size(iterator());
}

From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.DomainURLCounter.java

@Override
public void reduce(TextBytes key, Iterator<IntWritable> values, OutputCollector<TextBytes, IntWritable> output,
        Reporter reporter) throws IOException {
    int count = Iterators.size(values);
    output.collect(key, new IntWritable(count));
}

From source file:com.ibm.vicos.common.crypto.CryptoUtils.java

public String hash(final Iterable<? extends Serializable> of) {
    checkNotNull(of, "of");
    if (Iterators.size(of.iterator()) > 0) {
        Hasher hasher = getHashFunction().newHasher();
        for (Object obj : of) {
            hasher.putString(obj.toString(), Charsets.UTF_8);
        }//  w w w .  ja va 2  s  .  co  m
        return hasher.hash().toString();
    } else {
        return NULL_HASH;
    }
}

From source file:com.facebook.presto.operator.ValuesOperator.java

@Override
public void finish() {
    Iterators.size(pages);
}

From source file:appeng.integration.modules.waila.part.P2PStateWailaDataProvider.java

private static int getOutputCount(PartP2PTunnel tunnel) {
    try {/*  w w  w  . j ava2  s  .co  m*/
        return Iterators.size(tunnel.getOutputs().iterator());
    } catch (GridAccessException e) {
        // Well... unknown size it is!
        return 0;
    }
}