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

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

Introduction

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

Prototype

public static int size(Iterable<?> iterable) 

Source Link

Document

Returns the number of elements in iterable .

Usage

From source file:net.freifunk.autodeploy.firmware.Firmware.java

public static Device fromString(final String deviceString) {
    final Iterable<String> parts = Splitter.on('-').split(deviceString);
    Preconditions.checkArgument(Iterables.size(parts) == 2);
    final String model = Iterables.get(parts, 0);
    final String version = Iterables.get(parts, 1);
    return new Device(model, version);
}

From source file:suneido.database.immudb.Columns.java

int[] numsArray(String names) {
    if (names.isEmpty())
        return new int[0];
    Iterable<String> cs = commaSplitter.split(names);
    int[] nums = new int[Iterables.size(cs)];
    int c = 0;//from   w ww. j ava2  s . c  o  m
    for (String name : cs)
        nums[c++] = ck_find(name).field;
    return nums;
}

From source file:org.flinkspector.core.quantify.records.UntilList.java

@Override
public boolean matchesSafely(Iterable<T> objects, Description mismatch) {
    int numMatches = 0;
    int numMismatches = 0;
    int possibleMatches = Iterables.size(objects);
    int i = 0;//from w  w w.j  a va2 s  . c om
    Description mismatches = new StringDescription();
    for (T item : objects) {

        if (!matcher.matches(item)) {
            if (numMismatches < 10) {
                matcher.describeMismatch(item, mismatches);
                mismatches.appendText(" on record #" + (i + 1));
            }
            numMismatches++;
        } else {
            numMatches++;

            if (validWhen(numMatches, possibleMatches)) {
                return true;
            }
        }
        i++;
    }
    describeMismatch(numMatches, mismatch, mismatches);
    return false;
}

From source file:org.apache.metron.indexing.dao.IndexDaoFactory.java

public static IndexDao combine(Iterable<IndexDao> daos, Function<IndexDao, IndexDao> daoTransformation)
        throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {/* w w  w.  java 2s .co m*/
    int numDaos = Iterables.size(daos);
    if (numDaos == 0) {
        throw new IllegalArgumentException(
                "Trying to combine 0 dao's into a DAO is not a supported configuration.");
    }
    if (numDaos == 1) {
        return daoTransformation.apply(Iterables.getFirst(daos, null));
    }
    return new MultiIndexDao(daos, daoTransformation);
}

From source file:org.flinkspector.core.quantify.assertions.UntilCombineMatcher.java

@Override
public boolean matchesSafely(T object, Description mismatch) {
    int matches = 0;
    int possibleMatches = Iterables.size(matchers);

    for (Matcher<? super T> matcher : matchers) {
        if (!matcher.matches(object)) {
            if (!mismatch.toString().endsWith("but: ")) {
                mismatch.appendText("\n          ");
            }//ww w.j  a va  2  s. c  o  m
            matcher.describeMismatch(object, mismatch);
        } else {
            matches++;
            if (validWhen(matches, possibleMatches)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.eightkdata.mongowp.bson.abst.AbstractIterableBasedBsonArray.java

@Override
public int size() {
    if (cachedSize == -1) {
        cachedSize = Iterables.size(this);
        assert cachedSize != -1;
    }/*  w w w .  j a  v a 2s.  c o  m*/
    return cachedSize;
}

From source file:com.adobe.acs.commons.wcm.comparisons.impl.lines.Stepper.java

public T next() {
    T ret = Iterables.size(values) > step ? Iterables.get(values, step) : null;
    step++;
    return ret;
}

From source file:org.flinkspector.core.quantify.list.OutputWithSize.java

@Override
protected boolean matchesSafely(Iterable<T> item, Description mismatchDescription) {
    int size = Iterables.size(item);
    boolean matches = sizeMatcher.matches(size);
    if (!matches) {
        sizeMatcher.describeMismatch(size, mismatchDescription);
    }/* www  . j av  a 2 s  .  c o  m*/
    return matches;
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.AnyXmlNodeBaseParser.java

@Override
public final AnyXmlNode parse(Iterable<E> elements, AnyXmlSchemaNode schema) {
    final int size = Iterables.size(elements);
    Preconditions.checkArgument(size == 1, "Elements mapped to any-xml node illegal count: %s", size);

    final E e = elements.iterator().next();
    DOMSource value = parseAnyXml(e, schema);

    NormalizedNodeAttrBuilder<NodeIdentifier, DOMSource, AnyXmlNode> anyXmlBuilder = Builders
            .anyXmlBuilder(schema);//from w  w w. j a  v a2s  .  c  o m

    return anyXmlBuilder.withValue(value).build();
}

From source file:com.allogy.couch.exporters.ZipCouchMultipleDatabaseExporter.java

public void export(Iterable<CouchDbConnector> couchDbConnectors, OutputStream outputStream) throws IOException {
    if (couchDbConnectors == null || Iterables.size(couchDbConnectors) == 0)
        throw new IllegalArgumentException("couchDbConnectors");
    if (outputStream == null)
        throw new IllegalArgumentException("outputStream");

    ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);

    try {//  w ww.j a va 2  s. c o m
        for (CouchDbConnector couchDbConnector : couchDbConnectors) {
            if (couchDbConnector.queryView(new ViewQuery().allDocs()).getTotalRows() == 0)
                continue;

            String databaseName = couchDbConnector.path();
            databaseName = databaseName.substring(0, databaseName.length() - 1);
            ZipEntry zipEntry = new ZipEntry(databaseName);
            zipOutputStream.putNextEntry(zipEntry);

            couchDatabaseExporter.export(couchDbConnector, zipOutputStream);
        }
    } finally {
        zipOutputStream.finish();
    }
}