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.job.CombinedWorkerProgress.java

/**
 * Constructor//from ww  w.  ja  v  a 2 s.  com
 *
 * @param workerProgresses Worker progresses to combine
 * @param conf Configuration
 */
public CombinedWorkerProgress(Iterable<WorkerProgress> workerProgresses, Configuration conf) {
    normalFreeMemoryFraction = NORMAL_FREE_MEMORY_FRACTION.get(conf);
    for (WorkerProgress workerProgress : workerProgresses) {
        if (workerProgress.getCurrentSuperstep() > currentSuperstep) {
            verticesToCompute = 0;
            verticesComputed = 0;
            partitionsToCompute = 0;
            partitionsComputed = 0;
            currentSuperstep = workerProgress.getCurrentSuperstep();
            workersInSuperstep = 0;
        }

        if (workerProgress.getCurrentSuperstep() == currentSuperstep) {
            workersInSuperstep++;
            if (isInputSuperstep()) {
                verticesLoaded += workerProgress.getVerticesLoaded();
                vertexInputSplitsLoaded += workerProgress.getVertexInputSplitsLoaded();
                edgesLoaded += workerProgress.getEdgesLoaded();
                edgeInputSplitsLoaded += workerProgress.getEdgeInputSplitsLoaded();
            } else if (isComputeSuperstep()) {
                verticesToCompute += workerProgress.getVerticesToCompute();
                verticesComputed += workerProgress.getVerticesComputed();
                partitionsToCompute += workerProgress.getPartitionsToCompute();
                partitionsComputed += workerProgress.getPartitionsComputed();
            } else if (isOutputSuperstep()) {
                verticesToStore += workerProgress.getVerticesToStore();
                verticesStored += workerProgress.getVerticesStored();
                partitionsToStore += workerProgress.getPartitionsToStore();
                partitionsStored += workerProgress.getPartitionsStored();
            }
        }

        if (workerProgress.isStoringDone()) {
            workersDone++;
        }

        if (workerProgress.getFreeMemoryMB() < minFreeMemoryMB) {
            minFreeMemoryMB = workerProgress.getFreeMemoryMB();
            workerWithMinFreeMemory = workerProgress.getTaskId();
        }
        minFreeMemoryFraction = Math.min(minFreeMemoryFraction, workerProgress.getFreeMemoryFraction());
        freeMemoryMB += workerProgress.getFreeMemoryMB();
        int percentage = workerProgress.getLowestGraphPercentageInMemory();
        if (percentage < minGraphPercentageInMemory) {
            minGraphPercentageInMemory = percentage;
            workerWithMinGraphPercentageInMemory = workerProgress.getTaskId();
        }
    }
    if (!Iterables.isEmpty(workerProgresses)) {
        freeMemoryMB /= Iterables.size(workerProgresses);
    }
}

From source file:org.apache.giraph.comm.messages.out_of_core.SequentialFileMessageStore.java

/**
 * Adds messages from one message store to another
 *
 * @param messageMap Add the messages from this map to this store
 * @throws java.io.IOException/*w  w w.ja v a  2s.c om*/
 */
public void addMessages(NavigableMap<I, DataInputOutput> messageMap) throws IOException {
    // Writes messages to its file
    if (file.exists()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("addMessages: Deleting " + file);
        }
        if (!file.delete()) {
            throw new IOException("Failed to delete existing file " + file);
        }
    }
    if (!file.createNewFile()) {
        throw new IOException("Failed to create file " + file);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("addMessages: Creating " + file);
    }

    DataOutputStream out = null;

    try {
        out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), bufferSize));
        int destinationVertexIdCount = messageMap.size();
        out.writeInt(destinationVertexIdCount);

        // Dump the vertices and their messages in a sorted order
        for (Map.Entry<I, DataInputOutput> entry : messageMap.entrySet()) {
            I destinationVertexId = entry.getKey();
            destinationVertexId.write(out);
            DataInputOutput dataInputOutput = entry.getValue();
            Iterable<M> messages = new MessagesIterable<M>(dataInputOutput, messageValueFactory);
            int messageCount = Iterables.size(messages);
            out.writeInt(messageCount);
            if (LOG.isDebugEnabled()) {
                LOG.debug("addMessages: For vertex id " + destinationVertexId + ", messages = " + messageCount
                        + " to file " + file);
            }
            for (M message : messages) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("addMessages: Wrote " + message + " to " + file);
                }
                message.write(out);
            }
        }
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:org.jclouds.compute.stub.extensions.StubSecurityGroupExtension.java

@Override
public SecurityGroup addIpPermission(IpProtocol protocol, int startPort, int endPort,
        Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> ipRanges, Iterable<String> groupIds,
        SecurityGroup group) {/*from  w ww.java  2 s. co m*/
    IpPermission.Builder ipBuilder = IpPermission.builder();

    ipBuilder.ipProtocol(protocol);
    ipBuilder.fromPort(startPort);
    ipBuilder.toPort(endPort);
    if (tenantIdGroupNamePairs.size() > 0) {
        ipBuilder.tenantIdGroupNamePairs(tenantIdGroupNamePairs);
    }
    if (Iterables.size(ipRanges) > 0) {
        ipBuilder.cidrBlocks(ipRanges);
    }
    if (Iterables.size(groupIds) > 0) {
        ipBuilder.groupIds(groupIds);
    }

    IpPermission perm = ipBuilder.build();

    SecurityGroupBuilder builder = SecurityGroupBuilder.fromSecurityGroup(checkNotNull(group, "group"));

    builder.ipPermission(perm);

    SecurityGroup newGroup = builder.build();

    if (groups.containsKey(newGroup.getId())) {
        groups.remove(newGroup.getId());
    }

    groups.put(newGroup.getId(), newGroup);

    return newGroup;
}

From source file:org.polarsys.reqcycle.ocl.utils.OCLUtilities.java

/**
 * Checks whether an OCL resource contains an operation allowing to retrieve a requirement's attribute of a given data type. The operation should be named "getX" where "X" is the name of the attribute.
 *//*from   ww w  . jav a2  s  .  co m*/
public static IStatus isOperationPresent(final IAttribute attribute, BaseResource resource) {
    String attributeTypeName = attribute.getType().getName();
    if (!mapToOCLPrimitives.containsKey(attributeTypeName)) {
        return new Status(IStatus.WARNING, ReqcycleOCLPlugin.PLUGIN_ID,
                "Type " + attributeTypeName + " cannot be used in OCL.");
    }
    if (Iterables.size(getMatchingOperations(attribute, resource)) > 0) {
        return Status.OK_STATUS;
    }
    ;
    return new Status(IStatus.ERROR, ReqcycleOCLPlugin.PLUGIN_ID, "Required operation : "
            + OCLUtilities.getOperationRequiredSignature(attribute) + " could not be found.");
}

From source file:com.codebullets.external.party.simulator.pipeline.HandlerScriptLoader.java

@SuppressWarnings("unchecked")
private <T> Iterable<T> createCollectionOfType(final Class<T> targetType, final Iterable sourceList) {
    List<T> list = new ArrayList<>(Iterables.size(sourceList));

    for (Object entry : sourceList) {
        if (targetType.isInstance(entry)) {
            list.add((T) entry);// w  w w .  j  a  va 2 s  .  c  o  m
        }
    }

    return list;
}

From source file:org.opendaylight.openflowplugin.impl.util.MeterUtil.java

public static <O> Function<List<RpcResult<O>>, RpcResult<List<BatchFailedMetersOutput>>> createCumulativeFunction(
        final Iterable<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter> inputBatchMeters) {
    return createCumulativeFunction(inputBatchMeters, Iterables.size(inputBatchMeters));
}

From source file:com.facebook.buck.apple.project_generator.ProjectGeneratorTestUtils.java

public static <T extends PBXBuildPhase> T getSingletonPhaseByType(PBXTarget target, final Class<T> cls) {
    Iterable<PBXBuildPhase> buildPhases = Iterables.filter(target.getBuildPhases(), cls::isInstance);
    assertEquals("Build phase should be singleton", 1, Iterables.size(buildPhases));
    @SuppressWarnings("unchecked")
    T element = (T) Iterables.getOnlyElement(buildPhases);
    return element;
}

From source file:brooklyn.config.render.RendererHints.java

@SuppressWarnings("rawtypes")
private static Object _applyDisplayValueHint(Object target, Object initialValue, boolean includeClass) {
    Iterable<RendererHints.DisplayValue> hints = RendererHints._getHintsFor(target,
            RendererHints.DisplayValue.class);
    if (Iterables.size(hints) > 1) {
        log.warn("Multiple display value hints set for {}; Only one will be applied, using first", target);
    }//from   w  w  w .ja  v a  2 s.  c o  m

    Optional<RendererHints.DisplayValue> hint = Optional.fromNullable(Iterables.getFirst(hints, null));
    Object value = hint.isPresent() ? hint.get().getDisplayValue(initialValue) : initialValue;
    if (includeClass && value != null && !(value instanceof String) && !(value instanceof Number)
            && !(value.getClass().isPrimitive())) {
        value = _applyDisplayValueHint(value.getClass(), value, false);
    }
    return value;
}

From source file:com.puppetlabs.geppetto.pp.dsl.tests.utils.DiagnosticsAsserter.java

/**
 * No errors or warnings accepted.//www  . j a  v  a2 s  .c  o  m
 * 
 * @param message
 * @param diag
 */
public void assertOk() {
    Iterable<Diagnostic> all = getAllDiagnostics();
    if (Iterables.size(all) > 0)
        throw new ComparisonFailure("No diagnostics expected", "No diagnostics", diagnosticsToString(all));
}

From source file:org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.java

static int[] getPortsToOpenFromElement(NodeElement nodeElement) {
    Iterable<String> portStrings = Splitter.on(',').split(nodeElement.getOpenports());
    int[] ports = new int[Iterables.size(portStrings)];
    int i = 0;//  w w w  . j a  v  a  2s  .c  o  m
    for (String port : portStrings) {
        ports[i++] = Integer.parseInt(port);
    }
    return ports;
}