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:controllers.modules.opinionMiners.base.OpinionMiner.java

@Override
public Iterable<Module> getSubModules() {
    final Iterable<ViewModel> viewModels = this.viewModels;
    Iterable<Module> modules = Iterables.filter(
            Iterables.transform(this.getSubMiners(), new Function<Class<? extends OpinionMiner>, Module>() {
                @Override// www.  ja va  2  s .c om
                @Nullable
                public Module apply(@Nullable Class<? extends OpinionMiner> input) {
                    try {
                        return input.newInstance().setViewModels(viewModels);
                    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
                        return null;
                    }
                }
            }), Predicates.notNull());

    return Iterables.size(modules) > 0 ? modules : null;
}

From source file:org.apache.beam.runners.core.metrics.MetricsPusher.java

private void pushMetrics() {
    if (!(metricsSink instanceof NoOpMetricsSink)) {
        try {/*from  w w  w  . ja va2 s .  c o  m*/
            // merge metrics
            MetricResults metricResults = asAttemptedOnlyMetricResults(metricsContainerStepMap);
            MetricQueryResults metricQueryResults = metricResults.queryMetrics(MetricsFilter.builder().build());
            if ((Iterables.size(metricQueryResults.getDistributions()) != 0)
                    || (Iterables.size(metricQueryResults.getGauges()) != 0)
                    || (Iterables.size(metricQueryResults.getCounters()) != 0)) {
                metricsSink.writeMetrics(metricQueryResults);
            }

        } catch (Exception e) {
            MetricsPushException metricsPushException = new MetricsPushException(e);
            metricsPushException.printStackTrace();
        }
    }
}

From source file:org.dyndns.jkiddo.dmp.chunks.ContainerChunk.java

@SuppressWarnings("unchecked")
protected <T extends Chunk> T getSingleChunk(final Class<T> clazz) {
    final Iterable<Chunk> iterables = Iterables.filter(this.collection, Predicates.instanceOf(clazz));
    if (Iterables.size(iterables) == 1) {
        return (T) iterables.iterator().next();
    }/*from  ww  w . j a  v  a 2s  .c  o m*/
    if (Iterables.size(iterables) == 0) {
        return null;
    }
    throw new NoSuchElementException("Multiple chunks of type " + clazz + " was found");
}

From source file:org.apache.giraph.graph.IntIntNullIntVertex.java

@Override
public void putMessages(Iterable<IntWritable> newMessages) {
    messages = new int[Iterables.size(newMessages)];
    int n = 0;/*from  www  . j a  va 2  s . c  o m*/
    for (IntWritable message : newMessages) {
        messages[n++] = message.get();
    }
}

From source file:org.oncoblocks.centromere.dataimport.cli.ImportCommandRunner.java

/**
 * Runs the import of the file provided in the input arguments.  Will choose the appropriate 
 *   {@link RecordProcessor} instance, based on the supplied data type.  
 * /*from   w ww  .  j av  a 2s.c  o  m*/
 * @param arguments {@link ImportCommandArguments} instance, parsed from command line args.
 * @throws Exception
 */
public void run(ImportCommandArguments arguments) throws Exception {
    logger.debug(String.format("[CENTROMERE] Starting ImportCommandRunner with arguments: %s",
            arguments.toString()));
    RecordProcessor processor = this.getProcessorByDataType(arguments.getDataType());
    logger.debug(String.format("[CENTROMERE] Using processor %s for data type %s.",
            processor.getClass().getName(), arguments.getDataType()));
    BasicImportOptions options = arguments.getImportOptions();
    logger.debug(String.format("[CENTROMERE] Running import with options: %s", options.toString()));
    DataSetMetadata dataSetMetadata = null;
    DataFileMetadata dataFileMetadata = null;
    String inputFilePath = arguments.getInputFilePath();
    File inputFile = new File(inputFilePath);
    if (!inputFile.exists() || !inputFile.isFile() || !inputFile.canRead()) {
        throw new CommandLineRunnerException(String.format("Input file is not valid: %s", inputFilePath));
    }
    if (processor instanceof DataSetAware) {
        dataSetMetadata = this.getDataSetMetadata(arguments);
        if (dataSetMetadata != null) {
            logger.debug(String.format("[CENTROMERE] Using DataSetMetadata: %s", dataSetMetadata.toString()));
            ((DataSetAware) processor).setDataSetMetadata(dataSetMetadata);
        } else {
            logger.warn("[CENTROMERE] Data set metadata is null.");
        }
    }
    if (processor instanceof ImportOptionsAware) {
        ((ImportOptionsAware) processor).setImportOptions(options);
    }
    if (processor instanceof DataFileAware) {
        if (Iterables.size(manager.getDataFileRepository().getByFilePath(inputFilePath)) == 0) {
            BasicDataFileMetadata df = new BasicDataFileMetadata();
            df.setFilePath(inputFilePath);
            df.setDataType(arguments.getDataType());
            df.setDataSet(dataSetMetadata);
            dataFileMetadata = df;
            logger.debug(String.format("[CENTROMERE] Using DataFileMetadata: %s", dataFileMetadata.toString()));
        } else {
            if (options.isSkipExistingFiles()) {
                logger.info(String.format("[CENTROMERE] Skipping existing data file: %s",
                        arguments.getInputFilePath()));
                return;
            } else {
                logger.warn(String.format("Data file already exists: %s", arguments.getInputFilePath()));
                throw new CommandLineRunnerException(
                        String.format("Data file already exists: %s", arguments.getInputFilePath()));
            }
        }
        ((DataFileAware) processor).setDataFileMetadata(dataFileMetadata);
    }
    processor.doBefore();
    processor.run(inputFile.getCanonicalPath());
    processor.doAfter();
    logger.debug("[CENTROMERE] Import task complete.");
}

From source file:org.janusgraph.core.JanusGraphVertexQuery.java

/**
 * Returns the number of properties that match this query
 *
 * @return Number of properties that match this query
 */// w  ww .  ja  va2  s. co  m
public default long propertyCount() {
    return Iterables.size(properties());
}

From source file:org.apache.hadoop.examples.render.yarntest.YarnTestUtils.java

public static final <T> boolean waitForSize(Iterable<T> iterable, int count, int limit)
        throws InterruptedException {
    int trial = 0;
    int size = Iterables.size(iterable);
    while (size != count && trial < limit) {
        LOG.info("Waiting for {} size {} == {}", iterable, size, count);
        TimeUnit.SECONDS.sleep(1);
        trial++;//from   ww w  .  j  av a2s.c  o  m
        size = Iterables.size(iterable);
    }
    return trial < limit;
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.EventEndToPositionFunction.java

private ISequenceEvent getSafeEvent(Collection<ISequenceEvent> ises) {
    ISequenceEvent ise = null;/*  w  w w. j a v a2s.c  o  m*/
    Predicate<Object> safe = Predicates.or(Predicates.instanceOf(AbstractNodeEvent.class),
            Predicates.instanceOf(AbstractFrame.class));
    Collection<? extends ISequenceEvent> safeEvents = Lists.newArrayList(Iterables.filter(ises, safe));

    if (!safeEvents.isEmpty()) {
        ise = safeEvents.iterator().next();
    } else if (Iterables.size(Iterables.filter(ises, Operand.class)) == 2) {
        ise = getSafeOperandEnd(ises);
    } else {
        ise = ises.iterator().next();
    }
    return ise;
}

From source file:co.cask.cdap.internal.io.Schema.java

/**
 * Creates a {@link Schema} of {@link Type#ENUM ENUM} type, with the given enum values.
 * The set of values given should be unique and must contains at least one value.
 * The ordering of values in the enum type schema would be the same as the {@link Iterable#iterator()} order.
 *
 * @param values Enum values./*from  w  ww.ja  v  a 2s. c  om*/
 * @return A {@link Schema} of {@link Type#ENUM ENUM} type.
 */
public static Schema enumWith(Iterable<String> values) {
    Set<String> uniqueValues = ImmutableSet.copyOf(values);
    Preconditions.checkArgument(uniqueValues.size() > 0, "No enum value provided.");
    Preconditions.checkArgument(Iterables.size(values) == uniqueValues.size(),
            "Duplicate enum value is not allowed.");
    return new Schema(Type.ENUM, uniqueValues, null, null, null, null, null, null);
}

From source file:org.jon.ivmark.graphit.core.graph.traversal.Traversable.java

/**
 * Gets the size by traversing and counting all elements.
 */
public int size() {
    return Iterables.size(iterable);
}