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:com.github.tomakehurst.wiremock.common.Urls.java

public static String urlToPathParts(URI uri) {
    Iterable<String> uriPathNodes = Splitter.on("/").omitEmptyStrings().split(uri.getPath());
    int nodeCount = Iterables.size(uriPathNodes);

    return nodeCount > 0 ? Joiner.on("-").join(from(uriPathNodes).skip(nodeCount - Math.min(nodeCount, 2)))
            : "";
}

From source file:com.eucalyptus.simpleworkflow.stateful.AbstractTaskPolledNotificationChecker.java

@Override
public boolean apply(final String channel) {
    final Iterable<String> channelName = Splitter.on(':').limit(4).split(channel);
    if (Iterables.size(channelName) == 4) {
        final String accountNumber = Iterables.get(channelName, 0);
        final String type = Iterables.get(channelName, 1);
        final String domain = Iterables.get(channelName, 2);
        final String taskList = Iterables.get(channelName, 3);
        if (this.type.equals(type))
            try {
                return hasTasks(accountNumber, domain, taskList);
            } catch (final Exception e) {
                logger.error("Error checking for pending tasks", e);
            }/*from  www.  ja va 2  s.c  o  m*/
    }
    return false;
}

From source file:com.google.devtools.build.lib.testutil.MoreAsserts.java

public static <T> void assertContentsAnyOrder(Iterable<? extends T> expected, Iterable<? extends T> actual,
        Comparator<? super T> comp) {
    assertThat(actual).hasSize(Iterables.size(expected));
    int i = 0;//from  www  .ja va 2s . c  om
    for (T e : expected) {
        for (T a : actual) {
            if (comp.compare(e, a) == 0) {
                i++;
            }
        }
    }
    assertThat(actual).hasSize(i);
}

From source file:org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404.java

public Boolean apply(Exception from) {
    Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
            ResourceNotFoundException.class);
    if (Iterables.size(throwables) >= 1) {
        return false;
    } else {/*from w  ww .  j  a v a  2s  . c  o m*/
        return !rto404.apply(from);
    }
}

From source file:com.github.joshelser.BatchScannerQueryTask.java

@Override
public Integer call() throws Exception {
    try (BatchScanner bs = conn.createBatchScanner("usertable", Authorizations.EMPTY, 10)) {
        bs.setRanges(ranges);//from w w w .ja  v  a 2s. c  o m
        return Iterables.size(bs);
    }
}

From source file:org.janusgraph.graphdb.types.indextype.MixedIndexTypeWrapper.java

@Override
public ParameterIndexField[] getFieldKeys() {
    ParameterIndexField[] result = fields;
    if (result == null) {
        Iterable<SchemaSource.Entry> entries = base.getRelated(TypeDefinitionCategory.INDEX_FIELD,
                Direction.OUT);/*from ww w .j  a  v a2 s.  c  o  m*/
        int numFields = Iterables.size(entries);
        result = new ParameterIndexField[numFields];
        int pos = 0;
        for (SchemaSource.Entry entry : entries) {
            assert entry.getSchemaType() instanceof PropertyKey;
            assert entry.getModifier() instanceof Parameter[];
            result[pos++] = ParameterIndexField.of((PropertyKey) entry.getSchemaType(),
                    (Parameter[]) entry.getModifier());
        }
        fields = result;
    }
    assert result != null;
    return result;
}

From source file:com.nesscomputing.sequencer.ImmutableSequencerImpl.java

@SuppressWarnings("unchecked")
@JsonCreator/*from  w  ww .j a  va  2  s  .  c  o  m*/
ImmutableSequencerImpl(Iterable<K> elements) {
    final int size = Iterables.size(elements);
    forward = new TObjectIntHashMap<>(size, LOAD_FACTOR, -1);
    reverse = (K[]) new Object[size];
    int v = 0;
    for (K k : elements) {
        forward.put(k, v);
        reverse[v] = k;
        v++;
    }
}

From source file:org.jclouds.savvis.vpdc.binders.BindVMSpecsToXmlPayload.java

@SuppressWarnings("unchecked")
protected Iterable<VMSpec> findSpecInArgsOrNull(GeneratedHttpRequest gRequest) {
    for (Object arg : gRequest.getInvocation().getArgs()) {
        if (arg instanceof Iterable<?>) {
            Iterable<VMSpec> specs = (Iterable<VMSpec>) arg;
            checkArgument(Iterables.size(specs) > 0,
                    "At least one VMSpec must be included in the argument list");
            return specs;
        }/*from www  .ja v  a2  s . c o  m*/
    }
    throw new IllegalArgumentException("Iterable<VMSpec> must be included in the argument list");
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ListNodeBaseSerializer.java

@Override
public final Iterable<E> serialize(final ListSchemaNode schema, final N node) {
    return Iterables.concat(Iterables.transform(node.getValue(), input -> {
        final Iterable<E> serializedChild = getListEntryNodeSerializer().serialize(schema, input);
        final int size = Iterables.size(serializedChild);

        Preconditions.checkState(size == 1,
                "Unexpected count of entries  for list serialized from: %s, should be 1, was: %s", input, size);
        return serializedChild;
    }));/*www . ja  va2 s.co m*/
}

From source file:models.documentStore.AspectLexiconModel.java

public AspectLexiconModel(AspectLexicon lexicon, boolean expandChildren) {
    super(lexicon);

    if (lexicon != null) {
        if (lexicon.getBaseCorpus() != null) {
            this.baseCorpus = (DocumentCorpusModel) createViewModel(lexicon.getBaseCorpus());
        }//from  w ww.  j a  va 2 s. c  o  m

        if (Iterables.size(lexicon.getDerivedStores()) == 0) {
            this.children = null;
        } else {
            this.children = expandChildren ? Lists.newArrayList(
                    Iterables.transform(Iterables.filter(lexicon.getDerivedStores(), AspectLexicon.class),
                            new Function<AspectLexicon, AspectLexiconModel>() {
                                @Override
                                @Nullable
                                public AspectLexiconModel apply(@Nullable AspectLexicon input) {
                                    return new AspectLexiconModel(input, false);
                                }
                            }))
                    : Lists.<AspectLexiconModel>newArrayList();
        }

        if (lexicon.getBaseStore() instanceof AspectLexicon) {
            this.parent = new AspectLexiconModel((AspectLexicon) lexicon.getBaseStore(), false);
        }
    }
}