List of usage examples for com.google.common.collect Multiset add
@Override
boolean add(E element);
From source file:eu.esdihumboldt.hale.common.align.model.AlignmentUtil.java
/** * Add the values found on the given path to the given set. * /* w w w. ja va 2 s . co m*/ * @param group the parent group * @param path the path on the group * @param collectedValues the set to add the values to * @param onlyValues whether to only return values, or to return whatever * can be found (including groups/instances) */ public static void addValues(Group group, List<ChildContext> path, Multiset<Object> collectedValues, boolean onlyValues) { if (path == null || path.isEmpty()) { // group/instance at end of path if (onlyValues) { // only include instance values if (group instanceof Instance) { Object value = ((Instance) group).getValue(); if (value != null) { collectedValues.add(value); } } } else { // include the group/instance as is collectedValues.add(group); } // empty path - retrieve value from instance } else { // go down the path ChildContext context = path.get(0); List<ChildContext> subPath = path.subList(1, path.size()); Object[] values = group.getProperty(context.getChild().getName()); if (values != null) { // apply the possible source contexts if (context.getIndex() != null) { // select only the item at the index int index = context.getIndex(); if (index < values.length) { values = new Object[] { values[index] }; } else { values = new Object[] {}; } } if (context.getCondition() != null) { // select only values that match the condition List<Object> matchedValues = new ArrayList<Object>(); for (Object value : values) { if (AlignmentUtil.matchCondition(context.getCondition(), value, group)) { matchedValues.add(value); } } values = matchedValues.toArray(); } // check all values for (Object value : values) { if (value instanceof Group) { addValues((Group) value, subPath, collectedValues, onlyValues); } else if (subPath.isEmpty()) { // normal value and at the end of the path if (value != null) { collectedValues.add(value); } } } } } }
From source file:org.splevo.ui.refinementbrowser.ArgoUMLVariantScanHandler.java
private void scanForIncludedFeatures(List<VariationPoint> vps) { Multiset<String> identifiedFeatues = HashMultiset.create(); List<String> errors = Lists.newArrayList(); for (VariationPoint vp : vps) { Set<SoftwareElement> elements = getNotLeadingImplementingElements((VariationPoint) vp); if (elements.size() == 0) { identifiedFeatues.add("{NONE}"); }//from www .j av a2 s . c om for (SoftwareElement element : elements) { SourceLocation sourceLocation = element.getSourceLocation(); String path = sourceLocation.getFilePath(); List<String> lines = null; try { lines = FileUtils.readLines(new File(path)); } catch (IOException e) { e.printStackTrace(); continue; } int markerLineIndex = getMarkerLineIndex(vp, sourceLocation, lines); if (markerLineIndex == -1) { errors.add("No marker found for " + path.substring(path.length() - 20)); continue; } String featureId = getFeatureId(lines, markerLineIndex); if (isMarkerLine(lines, markerLineIndex - 1)) { featureId = getFeatureId(lines, markerLineIndex - 1) + " + " + featureId; } else if (isMarkerLine(lines, markerLineIndex + 1)) { featureId += " + " + getFeatureId(lines, markerLineIndex + 1); } identifiedFeatues.add(featureId); } } if (errors.size() > 0) { MessageDialog.openError(Display.getCurrent().getActiveShell(), "Marker Detection Errors", Joiner.on("\n").join(errors)); } StringBuilder message = new StringBuilder(); message.append("VP Count Total: "); message.append(vps.size()); for (String featureId : identifiedFeatues.elementSet()) { message.append("\n"); message.append(identifiedFeatues.count(featureId)); message.append(" x "); message.append(featureId); } MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Info", message.toString()); }
From source file:org.sonar.java.checks.FieldMatchMethodNameCheck.java
@Override public void visitNode(Tree tree) { Symbol.TypeSymbol classSymbol = ((ClassTree) tree).symbol(); if (classSymbol != null) { Map<String, Symbol> indexSymbol = Maps.newHashMap(); Multiset<String> fields = HashMultiset.create(); Map<String, String> fieldsOriginal = Maps.newHashMap(); Set<String> methodNames = Sets.newHashSet(); Collection<Symbol> symbols = classSymbol.memberSymbols(); for (Symbol sym : symbols) { String symName = sym.name().toLowerCase(); if (sym.isVariableSymbol()) { indexSymbol.put(symName, sym); fields.add(symName); fieldsOriginal.put(symName, sym.name()); }//from w w w.ja va2 s . c om if (sym.isMethodSymbol()) { methodNames.add(symName); } } fields.addAll(methodNames); for (Multiset.Entry<String> entry : fields.entrySet()) { if (entry.getCount() > 1) { Tree field = indexSymbol.get(entry.getElement()).declaration(); if (field != null) { addIssue(field, "Rename the \"" + fieldsOriginal.get(entry.getElement()) + "\" member."); } } } } }
From source file:org.sonar.java.checks.naming.FieldMatchMethodNameCheck.java
@Override public void visitNode(Tree tree) { Symbol.TypeSymbol classSymbol = ((ClassTree) tree).symbol(); if (classSymbol != null) { Map<String, Symbol> indexSymbol = Maps.newHashMap(); Multiset<String> fields = HashMultiset.create(); Map<String, String> fieldsOriginal = Maps.newHashMap(); Set<String> methodNames = Sets.newHashSet(); Collection<Symbol> symbols = classSymbol.memberSymbols(); for (Symbol sym : symbols) { String symName = sym.name().toLowerCase(Locale.US); if (sym.isVariableSymbol()) { indexSymbol.put(symName, sym); fields.add(symName); fieldsOriginal.put(symName, sym.name()); }// w w w. j a v a 2 s . c o m if (sym.isMethodSymbol()) { methodNames.add(symName); } } fields.addAll(methodNames); for (Multiset.Entry<String> entry : fields.entrySet()) { if (entry.getCount() > 1) { Tree field = indexSymbol.get(entry.getElement()).declaration(); if (field != null) { reportIssue(((VariableTree) field).simpleName(), "Rename the \"" + fieldsOriginal.get(entry.getElement()) + "\" member."); } } } } }
From source file:de.tum.bgu.msm.data.JobDataManager.java
public void calculateJobDensityByZone() { Multiset<Integer> counter = ConcurrentHashMultiset.create(); jobs.values().parallelStream().forEach(j -> counter.add(j.getZoneId())); geoData.getZones()/*from w w w . j a v a 2 s . c om*/ .forEach((id, zone) -> zonalJobDensity.put(id, (double) (counter.count(id) / zone.getArea_sqmi()))); }
From source file:Controller.BeanRNV.java
private void pushAverageGradeToClient() { Multiset<Float> setGrades = HashMultiset.create(); for (Entry<String, Pair<Float>> entry : mapIPToRangeGrade.entrySet()) { Pair<Float> range = entry.getValue(); for (int i = range.getLeft().intValue(); i <= range.getRight(); i++) { setGrades.add((float) i); }//w w w.ja v a 2s. c om } // 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("/pushIsFuckingGreatRN", stringToPush); } }
From source file:com.seniorproject.semanticweb.services.WebServices.java
public String prepareResultWithCount(ArrayList<String> in) throws IOException { Multiset<String> multiset = HashMultiset.create(); for (int i = 0; i < in.size(); i++) { if (in.get(i).length() > 0 && !in.get(i).equals("\"\"")) { multiset.add(in.get(i)); }/*from ww w. ja v a 2 s . c o m*/ } JsonArrayBuilder out = Json.createArrayBuilder(); JsonObjectBuilder resultObject = Json.createObjectBuilder(); for (Multiset.Entry<String> entry : multiset.entrySet()) { List<String> matchList = new ArrayList<>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'"); Matcher regexMatcher = regex.matcher(entry.getElement()); while (regexMatcher.find()) { matchList.add(regexMatcher.group()); } resultObject.add("elem", matchList.get(0)); resultObject.add("count", entry.getCount()); if (matchList.size() >= 2) { String label = ""; for (int j = 1; j < matchList.size(); j++) { label += matchList.get(j); } resultObject.add("label", label); } else { resultObject.add("label", ""); } out.add(resultObject); } return out.build().toString(); }
From source file:com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel.java
private void loadColors() { if (myResourceResolver == null) { myColorList = Collections.emptyList(); return;//from w w w.j a v a 2s . c o m } int rows = myModel.getRowCount(); Multiset<Color> colorSet = HashMultiset.create(); for (int i = 0; i < rows; i++) { if (myModel.getCellClass(i, 0) != Color.class) { continue; } EditedStyleItem item = (EditedStyleItem) myModel.getValueAt(i, 0); for (Color color : ResourceHelper.resolveMultipleColors(myResourceResolver, item.getSelectedValue(), myProject)) { myColorReferences.put(color, item); colorSet.add(color); } } myColorList = ImmutableList.copyOf(Multisets.copyHighestCountFirst(colorSet).elementSet()); }
From source file:fabric.worker.transaction.DeadlockDetectorThread.java
/** * Resolves deadlocks by aborting transactions. * //w w w.jav a2s. c o m * @param cycles * the set of deadlocks, represented by the logs of transactions * involved in waits-for cycles. */ private void resolveDeadlocks(Set<Set<Log>> cycles) { // Turn the set of cycles into a map from top-level TIDs to sorted multisets // of transaction logs. The multisets are sorted by transaction depth, outer // transactions first. LongKeyMap<Multiset<Log>> logsByTopLevelTid = new LongKeyHashMap<Multiset<Log>>(); for (Set<Log> cycle : cycles) { for (Log log : cycle) { long topLevelTid = log.getTid().topTid; Multiset<Log> logs = logsByTopLevelTid.get(topLevelTid); if (logs == null) { logs = TreeMultiset.create(LOG_COMPARATOR); logsByTopLevelTid.put(topLevelTid, logs); } logs.add(log); } } // Abort transactions to break up cycles. Transactions involved in more // cycles are aborted first. while (!cycles.isEmpty()) { // Figure out which top-level transaction(s) is involved in the most number // of deadlocks. int curMax = 0; LongSet abortCandidates = new LongHashSet(); for (LongKeyMap.Entry<Multiset<Log>> entry : logsByTopLevelTid.entrySet()) { int curSize = entry.getValue().size(); if (curMax > curSize) continue; if (curMax < curSize) { curMax = curSize; abortCandidates.clear(); } abortCandidates.add(entry.getKey()); } // Figure out which transaction to abort. (Pick the newest one.) Log toAbort = null; Multiset<Log> abortSet = null; for (LongIterator it = abortCandidates.iterator(); it.hasNext();) { long curTopLevelTid = it.next(); Multiset<Log> curCandidateSet = logsByTopLevelTid.get(curTopLevelTid); Log curCandidate = curCandidateSet.iterator().next(); if (toAbort == null || toAbort.startTime < curCandidate.startTime) { toAbort = curCandidate; abortSet = curCandidateSet; } } // Abort the transaction. WORKER_DEADLOCK_LOGGER.log(Level.FINE, "Aborting {0}", toAbort); toAbort.flagRetry(); // Fix up our data structures to reflect the aborted transaction. for (Iterator<Set<Log>> cycleIt = cycles.iterator(); cycleIt.hasNext();) { Set<Log> cycle = cycleIt.next(); // Check if the cycle has a transaction that was aborted. if (!haveCommonElements(cycle, abortSet.elementSet())) continue; // Cycle was broken, so remove from the set of cycles. cycleIt.remove(); // Fix up logsByTopLevelTid. for (Log log : cycle) { long topLevelTid = log.getTid().topTid; Multiset<Log> logs = logsByTopLevelTid.get(topLevelTid); logs.remove(log); if (logs.isEmpty()) { logsByTopLevelTid.remove(topLevelTid); } } } } }
From source file:de.iteratec.iteraplan.businesslogic.service.DashboardServiceImpl.java
/** {@inheritDoc} */ public Map<String, Integer> getIsrSealStateMap(List<InformationSystemRelease> isrs) { Multiset<SealState> multiset = EnumMultiset.create(SealState.class); for (InformationSystemRelease isr : isrs) { multiset.add(isr.getSealState()); }//w ww .j av a2 s . c om Map<String, Integer> statusMap = Maps.newLinkedHashMap(); for (SealState sealState : SealState.values()) { statusMap.put(sealState.toString(), Integer.valueOf(multiset.count(sealState))); } return statusMap; }