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:org.jclouds.cloudstack.binders.BindIdListToCommaDelimitedQueryParam.java

@SuppressWarnings("unchecked")
@Override/*from   w w w .  j av  a2  s  .  c  om*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(input instanceof Iterable<?>, "this binder is only valid for Iterables!");
    Iterable<Long> numbers = (Iterable<Long>) checkNotNull(input, "list of Longs");
    checkArgument(Iterables.size(numbers) > 0, "you must specify at least one element");
    return (R) request.toBuilder().replaceQueryParam("ids", Joiner.on(',').join(numbers)).build();
}

From source file:org.jclouds.blobstore.strategy.internal.CountBlobTypeInList.java

public long execute(String container, ListContainerOptions options) {
    return Iterables.size(getAllBlobMetadata.execute(container, options));
}

From source file:org.apache.metron.solr.writer.MetronSolrClient.java

public static SolrParams toSolrProps(Map<String, Object> config) {
    if (config == null || config.isEmpty()) {
        return null;
    }// ww  w.  j  a  v  a2 s.c o  m

    ModifiableSolrParams ret = new ModifiableSolrParams();
    for (Map.Entry<String, Object> kv : config.entrySet()) {
        Object v = kv.getValue();
        if (v instanceof Boolean) {
            ret.set(kv.getKey(), (Boolean) v);
        } else if (v instanceof Integer) {
            ret.set(kv.getKey(), (Integer) v);
        } else if (v instanceof Iterable) {
            Iterable vals = (Iterable) v;
            String[] strVals = new String[Iterables.size(vals)];
            int i = 0;
            for (Object o : (Iterable) v) {
                strVals[i++] = o.toString();
            }
        }
    }
    return ret;
}

From source file:org.onos.yangtools.yang.data.impl.schema.transform.base.serializer.LeafSetNodeBaseSerializer.java

@Override
public final Iterable<E> serialize(final LeafListSchemaNode schema, final LeafSetNode<?> node) {
    return Iterables
            .concat(Iterables.transform(node.getValue(), new Function<LeafSetEntryNode<?>, Iterable<E>>() {
                @Override//from   w w w. ja v a 2  s. c o m
                public Iterable<E> apply(final LeafSetEntryNode<?> input) {
                    final Iterable<E> serializedChild = getLeafSetEntryNodeSerializer().serialize(schema,
                            input);
                    final int size = Iterables.size(serializedChild);
                    Preconditions.checkState(size == 1,
                            "Unexpected count of elements for leaf-list entry serialized from: %s, should be 1, was: %s",
                            input, size);
                    return serializedChild;
                }
            }));
}

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

@Override
public int size() {
    if (cachedSize < -1) {
        cachedSize = Iterables.size(this);
    }
    return cachedSize;
}

From source file:org.trancecode.xproc.step.CountStepProcessor.java

@Override
protected void execute(final StepInput input, final StepOutput output) {
    // TODO improve performance with "limit" option
    final int count = Iterables.size(input.readNodes(XProcPorts.SOURCE));
    LOG.trace("  count = {}", count);
    final int limit = Integer.parseInt(input.getOptionValue(XProcOptions.LIMIT, "0"));
    LOG.trace("  limit = {}", limit);
    final int result = limit > 0 ? Math.min(count, limit) : count;
    LOG.trace("  result = {}", result);

    output.writeNodes(XProcPorts.RESULT, input.newResultElement(Integer.toString(result)));
}

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

@Override
public final YangModeledAnyXmlNode parse(Iterable<E> elements, YangModeledAnyXmlSchemaNode schema) {
    final int size = Iterables.size(elements);
    Preconditions.checkArgument(size == 1, "Elements mapped to yang modeled any-xml node illegal count: %s",
            size);//w  ww  .j  a v  a2  s .  c  om

    final E e = elements.iterator().next();
    final Collection<DataContainerChild<? extends PathArgument, ?>> value = parseAnyXml(e, schema);

    final DataContainerNodeAttrBuilder<NodeIdentifier, YangModeledAnyXmlNode> yangModeledAnyXmlBuilder = Builders
            .yangModeledAnyXmlBuilder(schema);

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

From source file:net.middell.combo.TextResourceCombo.java

/**
 * Constructor.// www .j  ava 2s  .  c o  m
 *
 * @param resources the resources to be contained in this combo. The iteration order of the parameter is
 *                  supposed to be significant.
 */
public TextResourceCombo(Iterable<TextResource> resources) {
    super(Iterables.size(resources));
    Iterables.addAll(this, resources);
}

From source file:clocker.docker.location.strategy.basic.BreadthFirstPlacementStrategy.java

@Override
public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity context) {
    if (locations == null || locations.isEmpty()) {
        return ImmutableList.of();
    }//from ww  w .ja va2  s.  c om

    int size = Iterables.size(locations);
    int next = counter.incrementAndGet() % size;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Breadth first strategy using {} of {}", next, size);
    }

    return ImmutableList
            .copyOf(Iterables.concat(Iterables.skip(locations, next), Iterables.limit(locations, next)));
}

From source file:com.atlassian.jira.rest.client.test.matchers.SearchResultMatchers.java

public static Matcher<? super SearchResult> withIssueCount(final int issueCount) {
    return new FeatureMatcher<SearchResult, Integer>(Matchers.is(issueCount),
            "search result with issue count that", "issue count") {

        @Override/*from w  w w  .j ava2  s  .c  o m*/
        protected Integer featureValueOf(SearchResult searchResult) {
            final Iterable<Issue> issues = searchResult.getIssues();
            return (issues == null) ? 0 : Iterables.size(issues);
        }
    };
}