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.torodb.mongowp.bson.abst.AbstractIterableBasedBsonDocument.java

@Override
public int size() {
    if (cachedSize == -1) {
        cachedSize = Iterables.size(this);
    }/*  w w  w.  j  ava 2 s .c o  m*/
    assert cachedSize >= 0;
    return cachedSize;
}

From source file:org.raml.utilities.matchers.ContentEqualsAnyOrderIterableMatcher.java

@Override
protected boolean matchesSafely(Iterable<T> toMatch) {
    Map<T, Integer> itemsOcurrences = new HashMap<>(Iterables.size(iterable));

    for (T item : iterable) {
        int itemOcurrences = 1;

        if (itemsOcurrences.containsKey(item)) {
            itemOcurrences = itemsOcurrences.get(item) + 1;
        }/* w w  w.  ja  v a  2s.c  om*/

        itemsOcurrences.put(item, itemOcurrences);
    }

    for (T item : toMatch) {
        if (!itemsOcurrences.containsKey(item)) { // Not in the current iterable.
            return false;
        }

        int itemOccurrences = itemsOcurrences.get(item) - 1;

        if (itemOccurrences == 0) {
            itemsOcurrences.remove(item);
        } else {
            itemsOcurrences.put(item, itemOccurrences);
        }
    }

    return itemsOcurrences.isEmpty();
}

From source file:org.sonar.xoo.extensions.XooPostJob.java

@Override
public void execute(PostJobContext context) {
    LOG.info("Resolved issues: " + Iterables.size(context.resolvedIssues()));
    LOG.info("Open issues: " + Iterables.size(context.issues()));
}

From source file:org.sonar.plugins.python.pylint.PylintArguments.java

private static String pylintVersion(Command command) {
    long timeout = 10000;
    CommandStreamConsumer out = new CommandStreamConsumer();
    CommandStreamConsumer err = new CommandStreamConsumer();
    CommandExecutor.create().execute(command, out, err, timeout);
    Iterable<String> outputLines = Iterables.concat(out.getData(), err.getData());
    for (String outLine : outputLines) {
        Matcher matcher = PYLINT_VERSION_PATTERN.matcher(outLine);
        if (matcher.matches()) {
            return matcher.group(1);
        }//w  w  w  .  j a  v  a 2 s  . c  o  m
    }
    String message = "Failed to determine pylint version with command: \"" + command.toCommandLine()
            + "\", received " + Iterables.size(outputLines) + " line(s) of output:\n"
            + Joiner.on('\n').join(outputLines);
    throw new IllegalArgumentException(message);
}

From source file:org.terasology.logic.ai.AICommands.java

/**
 * Counts all AIs in the world/* w  ww  . j a v  a 2 s . c o  m*/
 * @return String string containing number of simple AIs and hierarchical AIs
 */
@Command(runOnServer = true, shortDescription = "Count all AIs in the world")
public String countAI() {
    int simpleAIs = Iterables.size(entityManager.getEntitiesWith(SimpleAIComponent.class));
    int hierarchical = Iterables.size(entityManager.getEntitiesWith(HierarchicalAIComponent.class));
    return "Simple AIs: " + simpleAIs + ", Hierarchical AIs: " + hierarchical;
}

From source file:org.sosy_lab.cpachecker.util.expressions.And.java

private And(ImmutableSet<ExpressionTree<LeafType>> pOperands) {
    assert Iterables.size(pOperands) >= 2;
    assert !Iterables.contains(pOperands, ExpressionTrees.getFalse());
    assert !Iterables.contains(pOperands, ExpressionTrees.getTrue());
    assert !FluentIterable.from(pOperands).anyMatch(Predicates.instanceOf(And.class));
    operands = pOperands;// w  w  w. ja  v a 2s  . c om
    hashCode = operands.hashCode();
}

From source file:org.apache.beam.runners.flink.translation.functions.FlinkAssignContext.java

FlinkAssignContext(WindowFn<InputT, W> fn, WindowedValue<InputT> value) {
    fn.super();//w ww.j  a  va 2  s.  c  om
    checkArgument(Iterables.size(value.getWindows()) == 1,
            String.format("%s passed to window assignment must be in a single window, but it was in %s: %s",
                    WindowedValue.class.getSimpleName(), Iterables.size(value.getWindows()),
                    value.getWindows()));
    this.value = value;
}

From source file:com.helion3.bedrock.commands.PerformanceCommand.java

public static CommandSpec getCommand() {
    return CommandSpec.builder().description(Text.of("Display server performance statistics."))
            .permission("bedrock.performance").executor((source, args) -> {
                source.sendMessage(Format.heading("Performance Stats"));
                source.sendMessage(Format.message("TPS: " + Bedrock.getGame().getServer().getTicksPerSecond()));

                source.sendMessage(Format.message("Worlds:"));
                for (World world : Bedrock.getGame().getServer().getWorlds()) {
                    source.sendMessage(Text.of(TextColors.WHITE, world.getName() + "\n", TextColors.GRAY,
                            " Entities: ", TextColors.YELLOW, world.getEntities().size(), TextColors.GRAY,
                            " Chunks: ", TextColors.YELLOW, Iterables.size(world.getLoadedChunks())));
                }//from ww w.  java2s .com

                return CommandResult.success();
            }).build();
}

From source file:co.cask.cdap.common.HttpExceptionHandler.java

@Override
public void handle(Throwable t, HttpRequest request, HttpResponder responder) {
    // Check if the exception is caused by Service being unavailable: this will happen during master startup
    if (Iterables.size(Iterables.filter(Throwables.getCausalChain(t), ServiceUnavailableException.class)) > 0) {
        // no need to log ServiceUnavailableException because at master startup we are waiting for services to come up
        responder.sendString(HttpResponseStatus.SERVICE_UNAVAILABLE, t.getMessage());
    } else if (t instanceof HttpErrorStatusProvider) {
        logWithTrace(request, t);/*w  w  w .  j a  va2  s  . c  om*/
        responder.sendString(HttpResponseStatus.valueOf(((HttpErrorStatusProvider) t).getStatusCode()),
                t.getMessage());
    } else {
        LOG.error("Unexpected error: request={} {} user={}:", request.getMethod().getName(), request.getUri(),
                Objects.firstNonNull(SecurityRequestContext.getUserId(), "<null>"), t);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, Throwables.getRootCause(t).getMessage());
    }
}

From source file:org.jclouds.cloudstack.binders.BindCIDRsToCommaDelimitedQueryParam.java

@SuppressWarnings("unchecked")
@Override/*w  ww .  ja va 2s  .  co m*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(input instanceof Iterable<?>, "this binder is only valid for Iterables!");
    Iterable<String> cidrs = (Iterable<String>) checkNotNull(input, "cidr list");
    checkArgument(Iterables.size(cidrs) > 0, "you must specify at least one cidr range");
    return (R) request.toBuilder().replaceQueryParam("cidrlist", Joiner.on(',').join(cidrs)).build();
}