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.eclipse.reqcycle.ocl.utils.OCLUtilities.java

/**
 * Checks whether an OCL resource contains an operation allowing to test whether an uml element can
 * be associated to a given data type. The operation should be named "isX" where "X" is the name
 * of the data type./*from  ww  w. ja  v a2 s  .  c o m*/
 */
public static IStatus isOperationPresent(final IRequirementType type, BaseResource resource) {
    if (Iterables.size(getMatchingOperations(type, resource)) > 0) {
        return Status.OK_STATUS;
    }
    ;
    return new Status(IStatus.ERROR, ReqcycleOCLPlugin.PLUGIN_ID,
            "Required operation : " + OCLUtilities.getOperationRequiredSignature(type) + " could not be found");
}

From source file:com.ebuddy.cassandra.structure.DefaultPath.java

@Override
public int size() {
    return Iterables.size(pathElements);
}

From source file:org.apache.mahout.math.neighborhood.Searcher.java

public List<WeightedThing<Vector>> searchFirst(Iterable<? extends Vector> queries, boolean differentThanQuery) {
    List<WeightedThing<Vector>> results = Lists.newArrayListWithExpectedSize(Iterables.size(queries));
    for (Vector query : queries) {
        results.add(searchFirst(query, differentThanQuery));
    }/* w  ww. ja  va  2 s . c o m*/
    return results;
}

From source file:org.apache.metron.utils.LatencySummarizer.java

public static String getBaseMetric(String s) {
    Iterable<String> tokenIt = Splitter.on('.').split(s);
    int num = Iterables.size(tokenIt);
    return Joiner.on('.').join(Iterables.limit(tokenIt, num - 1));
}

From source file:org.apache.calcite.adapter.spark.SparkRules.java

public static void main(String[] args) {
    final JavaSparkContext sc = new JavaSparkContext("local[1]", "calcite");
    final JavaRDD<String> file = sc.textFile("/usr/share/dict/words");
    System.out.println(file.map(new Function<String, Object>() {
        @Override/*from  www  .  j a  v  a 2s  .c o  m*/
        public Object call(String s) throws Exception {
            return s.substring(0, Math.min(s.length(), 1));
        }
    }).distinct().count());
    file.cache();
    String s = file.groupBy(new Function<String, String>() {
        @Override
        public String call(String s) throws Exception {
            return s.substring(0, Math.min(s.length(), 1));
        }
    }
    //CHECKSTYLE: IGNORE 1
    ).map(new Function<Tuple2<String, Iterable<String>>, Object>() {
        @Override
        public Object call(Tuple2<String, Iterable<String>> pair) {
            return pair._1() + ":" + Iterables.size(pair._2());
        }
    }).collect().toString();
    System.out.print(s);

    final JavaRDD<Integer> rdd = sc.parallelize(new AbstractList<Integer>() {
        final Random random = new Random();

        @Override
        public Integer get(int index) {
            System.out.println("get(" + index + ")");
            return random.nextInt(100);
        }

        @Override
        public int size() {
            System.out.println("size");
            return 10;
        }
    });
    System.out.println(rdd.groupBy(new Function<Integer, Integer>() {
        public Integer call(Integer integer) {
            return integer % 2;
        }
    }).collect().toString());
    System.out.println(file.flatMap(new FlatMapFunction<String, Pair<String, Integer>>() {
        public List<Pair<String, Integer>> call(String x) {
            if (!x.startsWith("a")) {
                return Collections.emptyList();
            }
            return Collections.singletonList(Pair.of(x.toUpperCase(Locale.ROOT), x.length()));
        }
    }).take(5).toString());
}

From source file:com.ydy.cf.solver.impl.AlternatingLeastSquaresSolver.java

private Matrix createMiIi(Iterable<Vector> featureVectors, int numFeatures) {
    Matrix MiIi = new DenseMatrix(numFeatures, Iterables.size(featureVectors));
    int n = 0;//from ww w. ja  va 2  s .c  om
    for (Vector featureVector : featureVectors) {
        for (int m = 0; m < numFeatures; m++) {
            MiIi.setQuick(m, n, featureVector.getQuick(m));
        }
        n++;
    }
    return MiIi;
}

From source file:de.up.ling.irtg.automata.condensed.PatternMatchingInvhomAutomatonFactory.java

public void computeMatcherFromHomomorphism() {
    nondetMatcher = new ConcreteTreeAutomaton<String>(hom.getTargetSignature());
    matcherParentToChildren = new ArrayInt2ObjectMap<>();

    CpuTimeStopwatch sw = new CpuTimeStopwatch();

    sw.record(0);/*from   www .j av a 2s .  c  om*/

    for (int labelSetID = 1; labelSetID <= hom.getMaxLabelSetID(); labelSetID++) {
        String prefix = "q" + labelSetID;
        String matchingStartState = prefix + "/";

        addToPatternMatchingAutomaton(hom.getByLabelSetID(labelSetID), prefix, nondetMatcher,
                hom.getTargetSignature(), false);

        int matchingStartStateId = nondetMatcher.getIdForState(matchingStartState);
        startStateIdToLabelSetID.put(matchingStartStateId, labelSetID);

        recordMatcherStates(matchingStartState, hom.getByLabelSetID(labelSetID), nondetMatcher);
    }

    sw.record(1);

    matcher = nondetMatcher.determinize(detMatcherStatesToNondet);
    System.err.println(Iterables.size(matcher.getRuleSet()) + " rules");

    sw.record(2);

    sw.printMilliseconds("add rules", "determinize");

    //        for (int parent : matcherParentToChildren.keySet()) {
    //            System.err.println(nondetMatcher.getStateForId(parent) + " -> " + Arrays.stream(matcherParentToChildren.get(parent)).mapToObj(nondetMatcher::getStateForId).collect(Collectors.toList()));
    //        }
}

From source file:com.googlecode.blaisemath.style.Styles.java

public static Stroke getStroke(AttributeSet style) {
    float strokeWidth = style.getFloat(Styles.STROKE_WIDTH, 1f);
    String dashes = style.getString(Styles.STROKE_DASHES, null);
    if (!Strings.isNullOrEmpty(dashes)) {
        Iterable<String> sDashes = Splitter.on(",").trimResults().split(dashes);
        try {/*w  w  w .  j  a va 2 s. co  m*/
            Iterable<Float> fDashes = Floats.stringConverter().convertAll(sDashes);
            float[] fArr = new float[Iterables.size(fDashes)];
            int i = 0;
            for (Float f : fDashes) {
                fArr[i] = f == null ? 0f : f;
                i++;
            }
            return new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, fArr,
                    0.0f);
        } catch (NumberFormatException x) {
            Logger.getLogger(Styles.class.getName()).log(Level.WARNING, "Invalid dash pattern: " + dashes, x);
        }
    }
    return new BasicStroke(strokeWidth);
}

From source file:com.spectralogic.ds3cli.command.Recover.java

@Override
public DefaultResult call() throws Exception {
    try {/*from  ww w . j  av a  2  s.c  o  m*/
        if (listOnly) {
            return new DefaultResult(
                    RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType));
        }
        if (deleteFiles) {
            return new DefaultResult(RecoveryFileManager.deleteFiles(this.id, this.bucketName, this.jobType));
        }
        //  get exactly file to recover
        final Iterable<Path> files = RecoveryFileManager.searchFiles(this.id, this.bucketName, this.jobType);
        if (Iterables.isEmpty(files)) {
            return new DefaultResult("No matching recovery files found.");
        }
        if (Iterables.size(files) > 1) {
            return new DefaultResult("Multiple matching recovery files found:\n"
                    + RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType)
                    + "Please restrict search criteria.");
        }
        final Path file = files.iterator().next();
        final RecoveryJob job = RecoveryFileManager.getRecoveryJobByFile(file.toFile());
        return new DefaultResult(recover(job));
    } catch (final IOException e) {
        throw new CommandException("Recovery Job failed", e);
    }
}

From source file:com.android.tools.idea.apk.viewer.dex.DexParser.java

@NotNull
private DexFileStats getDexStats() {
    DexBackedDexFile dexFile;/*from www .  ja  va 2 s . c  om*/
    try {
        dexFile = myDexFileFuture.get();
    } catch (Exception e) {
        return new DexFileStats(-1, -1, -1);
    }

    int definedMethodCount = 0;
    Set<? extends DexBackedClassDef> classes = dexFile.getClasses();
    for (DexBackedClassDef dexBackedClassDef : classes) {
        definedMethodCount += Iterables.size(dexBackedClassDef.getMethods());
    }

    return new DexFileStats(classes.size(), definedMethodCount, dexFile.getMethodCount());
}