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.asoem.greyfish.core.environment.AbstractEnvironment.java

protected int standardCountAgents() {
    return Iterables.size(getActiveAgents());
}

From source file:org.opendaylight.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(), 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);//from ww w.  j a v  a 2 s .c om
        return serializedChild;
    }));
}

From source file:org.eclipse.xtext.resource.impl.AbstractContainer.java

@Override
public int getResourceDescriptionCount() {
    return Iterables.size(getResourceDescriptions());
}

From source file:org.apache.metron.performance.sampler.BiasedSampler.java

public static List<Map.Entry<Integer, Integer>> readDistribution(BufferedReader distrFile, boolean quiet)
        throws IOException {
    List<Map.Entry<Integer, Integer>> ret = new ArrayList<>();
    if (!quiet) {
        System.out.println("Using biased sampler with the following biases:");
    }/* www . j ava 2s.c  o  m*/
    int sumLeft = 0;
    int sumRight = 0;
    for (String line = null; (line = distrFile.readLine()) != null;) {
        if (line.startsWith("#")) {
            continue;
        }
        Iterable<String> it = Splitter.on(",").split(line.trim());
        if (Iterables.size(it) != 2) {
            throw new IllegalArgumentException(
                    line + " should be a comma separated pair of integers, but was not.");
        }
        int left = Integer.parseInt(Iterables.getFirst(it, null));
        int right = Integer.parseInt(Iterables.getLast(it, null));
        if (left <= 0 || left > 100) {
            throw new IllegalArgumentException(
                    line + ": " + (left < 0 ? left : right) + " must a positive integer in (0, 100]");
        }
        if (right <= 0 || right > 100) {
            throw new IllegalArgumentException(line + ": " + right + " must a positive integer in (0, 100]");
        }
        if (!quiet) {
            System.out.println(
                    "\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
        }
        ret.add(new AbstractMap.SimpleEntry<>(left, right));
        sumLeft += left;
        sumRight += right;
    }
    if (sumLeft > 100 || sumRight > 100) {
        throw new IllegalStateException(
                "Neither columns must sum to beyond 100.  " + "The first column is the % of templates. "
                        + "The second column is the % of the sample that % of template occupies.");
    } else if (sumLeft < 100 && sumRight < 100) {
        int left = 100 - sumLeft;
        int right = 100 - sumRight;
        if (!quiet) {
            System.out.println(
                    "\t" + left + "% of templates will comprise roughly " + right + "% of sample output");
        }
        ret.add(new AbstractMap.SimpleEntry<>(left, right));
    }
    return ret;

}

From source file:domain.common.AbstractBusinessObjectBeanMapper.java

public List<Bean> newBusinessObjectBeanList(final Iterable<Bo> businessObjectList) {
    List<Bean> businessObjectBeanList = new ArrayList<>(Iterables.size(businessObjectList));

    for (Bo businessObject : businessObjectList)
        businessObjectBeanList.add(this.newBusinessObjectBean(businessObject));

    return businessObjectBeanList;
}

From source file:com.eucalyptus.util.CollectionUtils.java

/**
 * Apply the given function for each item in the iterable.
 *
 * <p>This method is an anti-pattern as the function is really an effect (it
 * can only be useful for its side effect)</p>
 *
 * @param iterable The iterable//from   ww  w  . ja  v  a  2  s .  c  om
 * @param function The function to apply
 * @param <T> The iterable type
 */
public static <T> void each(final Iterable<T> iterable, final Function<? super T, ?> function) {
    Iterables.size(Iterables.transform(iterable, function)); // transform is lazy
}

From source file:org.jclouds.openstack.marconi.v1.binders.BindIdsToQueryParam.java

@SuppressWarnings("unchecked")
@Override/*from   w w w.  j ava2s.c  o m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(input instanceof Iterable<?>, "This binder is only valid for Iterable");
    Iterable<String> ids = (Iterable<String>) input;
    checkArgument(Iterables.size(ids) > 0, "You must specify at least one id");

    return (R) request.toBuilder().replaceQueryParam("ids", Joiner.on(',').join(ids)).build();
}

From source file:uk.gov.gchq.koryphe.impl.function.Size.java

@Override
@SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored")
public Integer apply(final Iterable input) {
    if (null == input) {
        throw new IllegalArgumentException("Input cannot be null");
    }/*from  ww w . j  a v  a2s  . c  o  m*/
    try {
        return Iterables.size(input);
    } finally {
        CloseableUtil.close(input);
    }
}

From source file:org.cs3.plunit.matcher.PrologResultsInAnyOrder.java

@Override
protected boolean matchesSafely(List<List<String>> item) {
    if (Iterables.size(item) < strings.length)
        return false;

    for (Iterable<String> iterable : item) {
        matchLine(iterable);/*from   w w  w  .ja v  a2s.co  m*/
    }

    for (boolean bool : lineNumbers) {
        if (bool == false) {
            return false;
        }

    }
    return true;
}

From source file:org.obm.push.bean.ServerId.java

public static ServerId of(String value) {
    Iterable<String> parts = Splitter.on(SERVER_ID_SEPARATOR).split(value);
    if (Iterables.size(parts) > 2) {
        throw new InvalidServerId("Too many parts for a serverId");
    }/*from   w ww  . j a va  2  s. c  o m*/
    Iterator<String> iterator = parts.iterator();
    return of(getCollectionId(iterator, value), getItemId(iterator));
}