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.apache.giraph.utils.EdgeIterables.java

/**
 * Make a deep copy of an edge iterable and return it as an {@link
 * ArrayList}./*from w w w  . ja v  a 2  s  .co  m*/
 * Note: this method is slow since it has to deserialize all serialize all
 * the ids and values. It should only be used in unit tests.
 *
 * @param edges Iterable of edges
 * @param <I> Vertex id
 * @param <E> Edge value
 * @return A new list with copies of all the edges
 */
public static <I extends WritableComparable, E extends WritableComparable> ArrayList<Edge<I, E>> copy(
        Iterable<Edge<I, E>> edges) {
    Configuration conf = new Configuration();
    ArrayList<Edge<I, E>> edgeList = new ArrayList<Edge<I, E>>(Iterables.size(edges));
    for (Edge<I, E> edge : edges) {
        edgeList.add(EdgeFactory.create(WritableUtils.clone(edge.getTargetVertexId(), conf),
                WritableUtils.clone(edge.getValue(), conf)));
    }
    return edgeList;
}

From source file:org.apache.cassandra.db.lifecycle.Helpers.java

/**
 * update the contents of an "identity map" with the provided sets, ensuring that the items to remove are
 * really present, and that the items to add are not (unless we're also removing them)
 * @return a new identity map with the contents of the provided one modified
 *//*from  ww w  .  java  2s .c  o m*/
static <T> Map<T, T> replace(Map<T, T> original, Set<T> remove, Iterable<T> add) {
    // ensure the ones being removed are the exact same ones present
    for (T reader : remove)
        assert original.get(reader) == reader;

    // ensure we don't already contain any we're adding, that we aren't also removing
    assert !any(add, and(not(in(remove)), in(original.keySet()))) : String
            .format("original:%s remove:%s add:%s", original.keySet(), remove, add);

    Map<T, T> result = identityMap(concat(add, filter(original.keySet(), not(in(remove)))));

    assert result.size() == original.size() - remove.size() + Iterables.size(add) : String.format(
            "Expecting new size of %d, got %d while replacing %s by %s in %s",
            original.size() - remove.size() + Iterables.size(add), result.size(), remove, add,
            original.keySet());
    return result;
}

From source file:msi.gama.core.web.editor.GamlEditorState.java

public GamlEditorState(final ValidationContext status, final Iterable<? extends IDescription> descriptions) {

    if (status != null) {
        hasImportedErrors = status.hasImportedErrors();
        importedErrors = hasImportedErrors ? status.getImportedErrorsAsStrings() : Collections.EMPTY_MAP;
        hasInternalErrors = status.hasInternalErrors() || status.hasInternalSyntaxErrors();
        hasNullStatus = false;//from   w  w w . j  ava  2  s. com
    } else {
        hasNullStatus = true;
        importedErrors = Collections.EMPTY_MAP;
    }
    final int n = Iterables.size(descriptions);
    if (n > 0) {
        hasExperiments = true;
        experiments = new ArrayList<>(n);
        abbreviations = new ArrayList<>(n);
        types = new ArrayList<>(n);
        for (final IDescription ep : descriptions) {
            final String name = ep.getName();
            experiments.add(name);
            abbreviations.add(name.replaceFirst("Experiment ", ""));
            types.add(((ExperimentDescription) ep).isBatch());
        }
    } else {
        experiments = Collections.EMPTY_LIST;
        abbreviations = Collections.EMPTY_LIST;
        types = Collections.EMPTY_LIST;
    }
}

From source file:org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart.java

/**
 * Redirect the direct edit request to the
 * {@link DescriptionCompartmentEditPart}.
 * /*from w w w .  j  a  v a  2 s . c o  m*/
 * @param request
 *            the direct edit request
 */
@Override
protected void performDirectEditRequest(Request request) {
    Iterable<DescriptionCompartmentEditPart> descriptionCompartmentEditPartsfilter = Iterables
            .filter(this.getChildren(), DescriptionCompartmentEditPart.class);
    if (Iterables.size(descriptionCompartmentEditPartsfilter) == 1) {
        DescriptionCompartmentEditPart descriptionCompartmentEditPart = Iterables
                .getOnlyElement(descriptionCompartmentEditPartsfilter);
        descriptionCompartmentEditPart.performRequest(request);
    }
}

From source file:org.nmdp.ngs.range.tree.AbstractRangeTree.java

@Override
public int count(final Range<C> query) {
    return Iterables.size(intersect(query));
}

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

@SuppressWarnings("unchecked")
@Override//from w w w.  j av  a  2s. c o  m
public final LeafNode<?> parse(final Iterable<E> elements, final LeafSchemaNode schema) {
    final int size = Iterables.size(elements);
    Preconditions.checkArgument(size == 1, "Elements mapped to leaf node illegal count: %s", size);

    final E e = elements.iterator().next();
    Object value = parseLeaf(e, schema);

    NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> leafBuilder = Builders
            .leafBuilder(schema);

    leafBuilder.withAttributes(getAttributes(e));

    @SuppressWarnings("rawtypes")
    final BuildingStrategy rawBuildingStrat = buildingStrategy;
    final LeafNode<?> sample = (LeafNode<?>) rawBuildingStrat.build(leafBuilder.withValue(value));
    return sample == null ? null : LeafInterner.forSchema(schema).intern(sample);
}

From source file:playground.michalm.taxi.data.TaxiRequests.java

public static int countRequestsWithStatus(Iterable<TaxiRequest> requests, TaxiRequestStatus status) {
    return Iterables.size(Iterables.filter(requests, new TaxiRequestStatusPredicate(status)));
}

From source file:org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField.java

@Override
public Set<String> apply(HttpResponse response) {
    return ImmutableSet
            .copyOf(Iterables.filter(Iterables.transform(super.apply(response), new Function<String, String>() {

                @Override/* w w w . j  a  v  a 2  s .  co  m*/
                public String apply(String arg0) {
                    if (arg0 == null)
                        return null;
                    Iterable<String> parts = Splitter.on(' ').split(arg0);
                    if (Iterables.size(parts) == 2)
                        return Iterables.get(parts, 1);
                    else if (Iterables.size(parts) == 1)
                        return Iterables.get(parts, 0);
                    return null;
                }

            }), Predicates.notNull()));
}

From source file:org.onos.yangtools.yang.data.impl.schema.transform.base.parser.LeafSetEntryNodeBaseParser.java

@SuppressWarnings("unchecked")
@Override//from ww  w. ja  va2s. co m
public final LeafSetEntryNode<?> parse(Iterable<E> elements, LeafListSchemaNode schema) {
    final int size = Iterables.size(elements);
    Preconditions.checkArgument(size == 1, "Xml elements mapped to leaf node illegal count: %s", size);

    final E e = elements.iterator().next();
    Object value = parseLeafListEntry(e, schema);

    NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafEntryBuilder = Builders
            .leafSetEntryBuilder(schema);
    leafEntryBuilder.withAttributes(getAttributes(e));
    leafEntryBuilder.withValue(value);

    final BuildingStrategy rawBuildingStrat = buildingStrategy;
    return (LeafSetEntryNode<?>) rawBuildingStrat.build(leafEntryBuilder);
}

From source file:org.jclouds.scriptbuilder.domain.CreateFile.java

public CreateFile(String path, Iterable<String> lines, String marker) {
    this.path = checkNotNull(path, "path");
    this.lines = checkNotNull(lines, "lines");
    this.marker = checkNotNull(marker, "marker");
    checkState(Iterables.size(lines) > 0, "you must pass something to execute");
}