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.flinkspector.datastream.functions.ParallelFromStreamRecordsFunction.java

public ParallelFromStreamRecordsFunction(TypeSerializer<StreamRecord<T>> serializer,
        Iterable<StreamRecord<T>> input) throws IOException {
    this.serializer = serializer;
    elementsSerialized = serializeOutput(input, serializer).toByteArray();
    numElements = Iterables.size(input);
}

From source file:com.torodb.kvdocument.values.KvDocument.java

public int size() {
    return Iterables.size(this);
}

From source file:com.lyndir.lanterna.view.TextView.java

public void updateTextOffset(final int offsetDelta) {
    textOffset = Math.min(Math.max(0, textOffset + offsetDelta),
            Iterables.size(getTextLines()) - 1 - getContentBoxOnScreen().getSize().getHeight());
}

From source file:brooklyn.location.waratek.WaratekMachineLocation.java

@Override
public WaratekContainerLocation obtain(Map<?, ?> flags) throws NoMachinesAvailableException {
    Integer maxSize = jvm.getConfig(JavaVirtualMachine.JVC_CLUSTER_MAX_SIZE);
    Integer currentSize = jvm.getAttribute(WaratekAttributes.JVC_COUNT);
    Iterable<Entity> available = jvm.getAvailableJvcs();
    Entity entity = (Entity) flags.get("entity");
    if (LOG.isDebugEnabled()) {
        LOG.debug("JVM {}: {} containers, {} available, max {}",
                new Object[] { jvm.getJvmName(), currentSize, Iterables.size(available), maxSize });
    }/* ww  w. j ava2s.  c om*/

    // also try to satisfy the affinty rules etc.

    // If there are no stopped JVCs then add a new one
    if (Iterables.isEmpty(available)) {
        if (currentSize != null && currentSize >= maxSize) {
            throw new NoMachinesAvailableException(
                    String.format("Limit of %d containers reached at %s", maxSize, jvm.getJvmName()));
        }

        // increase size of JVC cluster
        DynamicCluster cluster = jvm.getJvcCluster();
        Optional<Entity> added = cluster.addInSingleLocation(this, MutableMap.of("entity", entity));
        if (!added.isPresent()) {
            throw new NoMachinesAvailableException(
                    String.format("Failed to create containers reached in %s", jvm.getJvmName()));
        }
        return ((JavaVirtualContainer) added.get()).getDynamicLocation();
    } else {
        WaratekContainerLocation container = ((JavaVirtualContainer) Iterables.getLast(available))
                .getDynamicLocation();
        container.setEntity(entity);
        return container;
    }
}

From source file:com.metamx.druid.merger.common.task.MergeTask.java

protected MergeTask(final String dataSource, final List<DataSegment> segments) {
    super(/* ww w. j a  va2s  . co m*/
            // _not_ the version, just something uniqueish
            String.format("merge_%s_%s", computeProcessingID(dataSource, segments), new DateTime().toString()),
            dataSource, computeMergedInterval(segments));

    // Verify segment list is nonempty
    Preconditions.checkArgument(segments.size() > 0, "segments nonempty");
    // Verify segments are all in the correct datasource
    Preconditions.checkArgument(Iterables.size(Iterables.filter(segments, new Predicate<DataSegment>() {
        @Override
        public boolean apply(@Nullable DataSegment segment) {
            return segment == null || !segment.getDataSource().equalsIgnoreCase(dataSource);
        }
    })) == 0, "segments in the wrong datasource");
    // Verify segments are all unsharded
    Preconditions.checkArgument(Iterables.size(Iterables.filter(segments, new Predicate<DataSegment>() {
        @Override
        public boolean apply(@Nullable DataSegment segment) {
            return segment == null || !(segment.getShardSpec() instanceof NoneShardSpec);
        }
    })) == 0, "segments without NoneShardSpec");

    this.segments = segments;
}

From source file:org.apache.crunch.impl.spark.collect.CreatedTable.java

@Override
protected long getSizeInternal() {
    return Iterables.size(contents);
}

From source file:org.calrissian.accumulorecipes.thirdparty.tinkerpop.query.EntityVertexQuery.java

@Override
public long count() {
    CloseableIterable<Edge> edges = edges();
    long count = Iterables.size(edges);
    edges.closeQuietly();//from   w  w w .j a  va 2  s. c  o m
    return count;
}

From source file:org.jclouds.aws.ec2.compute.options.EC2TemplateOptions.java

/**
 * Specifies the security groups to be used for nodes with this template
 *//*from w  w w . j  a va2 s  .  c om*/
public EC2TemplateOptions securityGroups(Iterable<String> groupIds) {
    checkArgument(Iterables.size(groupIds) > 0, "you must specify at least one security group");
    for (String groupId : groupIds)
        Utils.checkNotEmpty(groupId, "all security groups must be non-empty");
    this.groupIds = ImmutableSet.copyOf(groupIds);
    return this;
}

From source file:org.asoem.greyfish.core.actions.FemaleLikeMating.java

@Override
protected ImmutableACLMessage.Builder<A> createCFP(final AgentContext<A> context) {
    final int sensedMatesCount = Iterables.size(sensedMates);
    assert (sensedMatesCount > 0); // see #evaluateCondition(Simulation)

    final A receiver = Iterables.get(sensedMates, RandomGenerators.rng().nextInt(sensedMatesCount));
    sensedMates = ImmutableList.of();/*w  w w  . j  ava  2 s  .co m*/

    return ImmutableACLMessage.<A>builder().sender(context.agent()).performative(ACLPerformative.CFP)
            .ontology(ontology)
            // Choose randomly one receiver. Adding evaluates possible candidates as receivers will decrease the performance in high density populations!
            .addReceiver(receiver);
}

From source file:net.holmes.core.business.streaming.airplay.controlpoint.CommandResponse.java

/**
 * Decode content parameters.//w  ww.jav  a2 s  .  c o m
 *
 * @param content content
 */
public void decodeContentParameters(String content) {
    for (String line : Splitter.on(EOL).split(content)) {
        Iterable<String> it = Splitter.on(PARAMETER_SEPARATOR).trimResults().split(line);
        if (Iterables.size(it) > 1) {
            contentParameters.put(Iterables.get(it, 0), Iterables.getLast(it));
        }
    }
}