List of usage examples for com.google.common.collect Multiset addAll
boolean addAll(Collection<? extends E> c);
From source file:com.google.devtools.build.lib.rules.objc.ResourceSupport.java
/** * Validates resource attributes on this rule. * * @return this resource support/*from ww w. j av a 2 s.c o m*/ */ ResourceSupport validateAttributes() { Iterable<String> assetCatalogErrors = ObjcCommon.notInContainerErrors(attributes.assetCatalogs(), ObjcCommon.ASSET_CATALOG_CONTAINER_TYPE); for (String error : assetCatalogErrors) { ruleContext.attributeError("asset_catalogs", error); } Iterable<String> dataModelErrors = ObjcCommon.notInContainerErrors(attributes.datamodels(), Xcdatamodels.CONTAINER_TYPES); for (String error : dataModelErrors) { ruleContext.attributeError("datamodels", error); } Multiset<Artifact> resources = HashMultiset.create(); resources.addAll(attributes.resources()); resources.addAll(attributes.structuredResources()); resources.addAll(attributes.strings()); resources.addAll(attributes.assetCatalogs()); resources.addAll(attributes.datamodels()); resources.addAll(attributes.xibs()); resources.addAll(attributes.storyboards()); for (Multiset.Entry<Artifact> entry : resources.entrySet()) { if (entry.getCount() > 1) { ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString()); } } return this; }
From source file:sklearn.cluster.KMeans.java
@Override public ClusteringModel encodeModel(Schema schema) { int[] shape = getClusterCentersShape(); int numberOfClusters = shape[0]; int numberOfFeatures = shape[1]; List<? extends Number> clusterCenters = getClusterCenters(); List<Integer> labels = getLabels(); Multiset<Integer> labelCounts = HashMultiset.create(); if (labels != null) { labelCounts.addAll(labels); }/*from w w w .j av a2s .c om*/ List<Cluster> clusters = new ArrayList<>(); for (int i = 0; i < numberOfClusters; i++) { Array array = PMMLUtil .createRealArray(MatrixUtil.getRow(clusterCenters, numberOfClusters, numberOfFeatures, i)); Cluster cluster = new Cluster().setId(String.valueOf(i)) .setSize((labelCounts.size() > 0 ? labelCounts.count(i) : null)).setArray(array); clusters.add(cluster); } List<Feature> features = schema.getFeatures(); List<ClusteringField> clusteringFields = ClusteringModelUtil.createClusteringFields(features); ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE) .setCompareFunction(CompareFunction.ABS_DIFF).setMeasure(new SquaredEuclidean()); Output output = ClusteringModelUtil.createOutput(FieldName.create("Cluster"), clusters); ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, numberOfClusters, ModelUtil.createMiningSchema(schema), comparisonMeasure, clusteringFields, clusters).setOutput(output); return clusteringModel; }
From source file:edu.uci.ics.sourcerer.tools.java.component.model.cluster.ClusterMatcher.java
public Set<ClusterVersion> getClusterVersions(Collection<FqnVersion> fqns) { Multimap<FqnVersion, ClusterVersion> map = fqnVersionsToClusterVersions.get(); Multiset<ClusterVersion> set = HashMultiset.create(); for (FqnVersion fqn : fqns) { set.addAll(map.get(fqn)); }//w w w . j a va 2s . c o m Set<ClusterVersion> result = new HashSet<>(); for (ClusterVersion version : set.elementSet()) { if (set.count(version) == version.getFqns().size()) { result.add(version); } } return result; }
From source file:nextmethod.web.razor.parser.syntaxtree.Span.java
private String[] getSymbolGroupCounts() { final Multiset<Class<?>> counts = HashMultiset.create(); counts.addAll(symbols.stream().map(ISymbol::getClass).collect(Collectors.toList())); final String[] ret = new String[counts.size()]; int i = 0;//from w w w .ja va 2 s. c om for (Multiset.Entry<Class<?>> entry : counts.entrySet()) { ret[i++] = String.format("%s:%d", entry.getElement().getSimpleName(), entry.getCount()); } return ret; }
From source file:com.opengamma.strata.report.framework.expression.IterableTokenEvaluator.java
@Override public Set<String> tokens(Iterable<?> iterable) { Multiset<String> tokens = HashMultiset.create(); int index = 0; for (Object item : iterable) { tokens.add(String.valueOf(index++)); tokens.addAll(fieldValues(item)); }/*from w w w . j a v a 2s .c o m*/ return tokens.stream().filter(token -> tokens.count(token) == 1).collect(toImmutableSet()); }
From source file:com.google.devtools.build.lib.rules.objc.AppleWatch2Extension.java
private void validateAttributesAndConfiguration(RuleContext ruleContext) throws RuleErrorException { boolean hasError = false; Multiset<Artifact> appResources = HashMultiset.create(); appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_resources", Mode.TARGET).list()); appResources.addAll(ruleContext.getPrerequisiteArtifacts("app_strings", Mode.TARGET).list()); for (Multiset.Entry<Artifact> entry : appResources.entrySet()) { if (entry.getCount() > 1) { ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString()); hasError = true;/*from w w w . j av a 2 s .c o m*/ } } Multiset<Artifact> extResources = HashMultiset.create(); extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_resources", Mode.TARGET).list()); extResources.addAll(ruleContext.getPrerequisiteArtifacts("ext_strings", Mode.TARGET).list()); for (Multiset.Entry<Artifact> entry : extResources.entrySet()) { if (entry.getCount() > 1) { ruleContext.ruleError("The same file was included multiple times in this rule: " + entry.getElement().getRootRelativePathString()); hasError = true; } } AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); Platform watchPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.WATCHOS); Platform iosPlatform = appleConfiguration.getMultiArchPlatform(PlatformType.IOS); if (watchPlatform.isDevice() != iosPlatform.isDevice()) { hasError = true; if (watchPlatform.isDevice()) { ruleContext.ruleError(String.format( "Building a watch extension for watch device architectures [%s] " + "requires a device ios architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS)))); } else { ruleContext.ruleError(String.format( "Building a watch extension for ios device architectures [%s] " + "requires a device watch architecture. Found [%s] instead.", Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.IOS)), Joiner.on(",").join(appleConfiguration.getMultiArchitectures(PlatformType.WATCHOS)))); } ruleContext.ruleError("For building watch extension, there may only be a watch device " + "architecture if and only if there is an ios device architecture"); } if (hasError) { throw new RuleErrorException(); } }
From source file:Controller.BeanUCV.java
private void pushMostVotedCategoryToClient() { Multiset<String> setCategories = HashMultiset.create(); setCategories.addAll(sharedBean.getOneMapIPToCategories(sessionCode).values()); System.out.println("multiset to string: " + setCategories.toString()); String stringToPush = elected + "^"; System.out.println("most voted cat: " + elected); stringToPush = stringToPush + setCategories.toString(); PushContext ctx = PushContextFactory.getDefault().getPushContext(); if (ctx != null) { ctx.push("/pushIsFuckingGreatUC", stringToPush); }//from w ww .j a v a 2 s. c om }
From source file:Controller.BeanUCV.java
private String computeMostVotedCategory() { String mostCat = ""; int mostVotes = 0; Multiset<String> setCountVotes = HashMultiset.create(); setCountVotes.addAll(sharedBean.getOneMapIPToCategories(sessionCode).values()); for (String cat : setCountVotes) { int countCategory = setCountVotes.count(cat); if (countCategory > mostVotes) { mostVotes = countCategory;//w w w. ja va 2 s . c om mostCat = cat; } } return mostCat; }
From source file:bio.gcat.operation.analysis.TupleUsage.java
@Override public Result analyse(Collection<Tuple> tuples, Object... values) { Logger logger = getLogger();// w w w . java2 s . com if (values[0] == null) { logger.log("Choose an existing file to count tuple usage in."); return null; } Acid acid; if ((acid = Tuple.tuplesAcid(tuples)) == null) { logger.log("Tuples with variable acids, can't analyse tuple usage."); return null; //tuples not all in same acid } Multiset<Tuple> tupleCount = HashMultiset.create(); try (BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) values[0]))) { String line; while ((line = reader.readLine()) != null) tupleCount.addAll(normalizeTuples(splitTuples(tupleString(line).trim()), acid)); } catch (IOException e) { logger.log("Error while reading file.", e); return null; } StringBuilder builder = new StringBuilder(); for (Tuple tuple : (!tuples.isEmpty() && !containsOnly(tuples, EMPTY_TUPLE) ? normalizeTuples(tuples, acid) : tupleCount.elementSet())) builder.append(DELIMITER).append(tupleCount.count(tuple)).append(TIMES).append(tuple); return new SimpleResult(this, builder.length() != 0 ? builder.substring(DELIMITER.length()).toString() : "no tuples"); }
From source file:Controller.BeanUNV.java
private void pushAverageGradeToClient() { Multiset<Float> setGrades = HashMultiset.create(); setGrades.addAll(sharedBean.getOneMapIPToGrade(sessionCode).values()); System.out.println("multiset to string: " + setGrades.toString()); String stringToPush = "[averageGrade = " + averageGrade + "]"; stringToPush = stringToPush + setGrades.toString(); PushContext ctx = PushContextFactory.getDefault().getPushContext(); if (ctx != null) { ctx.push("/pushIsFuckingGreatUN", stringToPush); }/*from w w w.j a va 2 s .c om*/ }