List of usage examples for java.util Collections frequency
public static int frequency(Collection<?> c, Object o)
From source file:msi.gaml.operators.Graphs.java
@operator(value = "strahler", content_type = ITypeProvider.CONTENT_TYPE_AT_INDEX + 1, category = { IOperatorCategory.GRAPH, IConcept.EDGE }) @doc(value = "retur for each edge, its strahler number") public static GamaMap strahlerNumber(final IScope scope, final GamaGraph graph) { final GamaMap<Object, Integer> results = GamaMapFactory.create(Types.NO_TYPE, Types.INT); if (graph == null || graph.isEmpty(scope)) { return results; }//w ww. ja v a 2 s . c o m if (!graph.getConnected() || graph.hasCycle()) { throw GamaRuntimeException .error("Strahler number can only be computed for Tree (connected graph with no cycle)!", scope); } List currentEdges = (List) graph.getEdges().stream() .filter(a -> graph.outDegreeOf(graph.getEdgeTarget(a)) == 0).collect(Collectors.toList()); while (!currentEdges.isEmpty()) { final List newList = new ArrayList<>(); for (final Object e : currentEdges) { final List previousEdges = inEdgesOf(scope, graph, graph.getEdgeSource(e)); final List nextEdges = outEdgesOf(scope, graph, graph.getEdgeTarget(e)); if (nextEdges.isEmpty()) { results.put(e, 1); newList.addAll(previousEdges); } else { final boolean notCompleted = nextEdges.stream().anyMatch(a -> !results.containsKey(a)); if (notCompleted) { newList.add(e); } else { final List<Integer> vals = (List<Integer>) nextEdges.stream().map(a -> results.get(a)) .collect(Collectors.toList()); final Integer maxVal = Collections.max(vals); final int nbIt = Collections.frequency(vals, maxVal); if (nbIt > 1) { results.put(e, maxVal + 1); } else { results.put(e, maxVal); } newList.addAll(previousEdges); } } } currentEdges = newList; } return results; }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public String dochecks() { String passed = ""; //Checks//from w ww. j av a 2s . c o m String CHECKduplicatetempsensors = "- The following Temperature Sensor(s) is duplicated"; String LISTduplicatetempsensors = ""; String CHECKfewbmsinfo = "- You have indicated less than two BMS on site"; String CHECKnogatewayserver = "- You have not indicated a location for a gateway server"; String CHECKethernetportcountsdonotmatchcomponents = "- You have not indicated ethernet access for all network required components"; String LISTethernetportcountsdonotmatchcomponents = ""; String CHECKemptyelc = "- The following ELC(s) has no added components:"; String LISTemptyelc = ""; String CHECKnolegend = "- You are missing a legend on the following floor plans"; String LISTnolegend = ""; String CHECKgapintempsensornumbering = "- You have a gap in your Temperature Sensor numbering:"; String LISTgapintempsensornumbering = ""; String CHECKmissingimages = "- You are missing pictures for the following items:"; String LISTmissingimages = ""; //checkduplicatetemps List<String> templist = new ArrayList<String>(); int bmscount = 0; int gwscount = 0; int ethernetportcount = 0; int ethernetcomponentcount = 0; boolean[] floorplanhaslegend = new boolean[floorplancount]; for (int h = 0; h < floorplancount; h++) { floorplanhaslegend[h] = false; } List<String> floorplanswoutlegend = new ArrayList<String>(); boolean[] elcmissingsams = new boolean[view.maxitems]; boolean[] elcmissingtemps = new boolean[view.maxitems]; for (int h = 1; h < view.ELCCOUNT + 1; h++) { elcmissingsams[h] = true; elcmissingtemps[h] = true; } List<String> elcswithoutattachments = new ArrayList<String>(); for (int x = 0; x < view.i; x++) { if (view.ITEMtype[x] == view.TYPE_TEMPSENSOR) { templist.add("Temperature Sensor " + view.ITEMmasterelcnumber[x] + "." + view.ITEMdisplaynumber[x]); elcmissingtemps[view.ITEMmasterelcnumber[x]] = false; } if (view.ITEMtype[x] == view.TYPE_BMS) { bmscount++; } if (view.ITEMtype[x] == view.TYPE_GATEWAY) { gwscount++; ethernetcomponentcount++; } if (view.ITEMtype[x] == view.TYPE_ELC) { ethernetcomponentcount++; if (view.ITEMsamscount[x] > 0) { elcmissingsams[view.ELCdisplaynumber[x]] = false; } } if (view.ITEMtype[x] == view.TYPE_ETHERNETPORT) { ethernetportcount++; } if (view.ITEMtype[x] == view.TYPE_LEGEND1 || view.ITEMtype[x] == view.TYPE_LEGEND2 || view.ITEMtype[x] == view.TYPE_LEGEND3 || view.ITEMtype[x] == view.TYPE_LEGEND4) { floorplanhaslegend[view.ITEMfloorplannumber[x]] = true; } } //count number of duplicate temps Set<String> uniqueSet = new HashSet<String>(templist); for (String temp : uniqueSet) { if (Collections.frequency(templist, temp) > 1) { LISTduplicatetempsensors = LISTduplicatetempsensors + temp + "\n"; } } if (LISTduplicatetempsensors.length() == 0) { CHECKduplicatetempsensors = passed; } //CHECKfewbmsinfo if (bmscount > 1) { CHECKfewbmsinfo = passed; } //CHECKnogatewayserver if (gwscount > 0) { CHECKnogatewayserver = passed; } //CHECKnolegend if (!NGBICONS) { for (int h = 0; h < floorplancount; h++) { if (!floorplanhaslegend[h]) { floorplanswoutlegend.add(Tabs1.sitefptextview[h].getText().toString()); } } for (String fp : floorplanswoutlegend) { LISTnolegend = LISTnolegend + fp + "\n"; } if (LISTnolegend.trim().length() == 0) { CHECKnolegend = passed; } } else { CHECKnolegend = passed; } //CHECKethernetportcountsdonotmatchcomponents if (ethernetportcount >= ethernetcomponentcount) { CHECKethernetportcountsdonotmatchcomponents = passed; } //CHECKemptyelc for (int h = 1; h < view.ELCCOUNT + 1; h++) { if (elcmissingsams[h] && elcmissingtemps[h]) { elcswithoutattachments.add("ELC " + (h)); } } for (String elc : elcswithoutattachments) { LISTemptyelc = LISTemptyelc + elc + "\n"; } if (LISTemptyelc.trim().length() == 0) { CHECKemptyelc = passed; } //CHECKgapintempsensornumbering view.templistorderedbyitemnumber = view.getorderedtemplist(); for (int h = 0; h < view.templistorderedbyitemnumber.length - 1; h++) { int itemnum = view.templistorderedbyitemnumber[h]; int nextitemnum = view.templistorderedbyitemnumber[h + 1]; if (view.ITEMdisplaynumber[nextitemnum] - view.ITEMdisplaynumber[itemnum] != 1) { //if(view.ITEMmasterelcnumber[nextitemnum]-view.ITEMmasterelcnumber[itemnum]!=1){ if (view.ITEMmasterelcnumber[nextitemnum] == view.ITEMmasterelcnumber[itemnum]) { String current = u.s(view.ITEMmasterelcnumber[itemnum]) + "." + u.s(view.ITEMdisplaynumber[itemnum]); String next = u.s(view.ITEMmasterelcnumber[nextitemnum]) + "." + u.s(view.ITEMdisplaynumber[nextitemnum]); String string = "Temp Sensor " + current + " and " + next; LISTgapintempsensornumbering = LISTgapintempsensornumbering + string + "\n"; } //} } } if (LISTgapintempsensornumbering.trim().length() == 0) { CHECKgapintempsensornumbering = passed; } //Check missing images CHECKmissingimages = passed; String checksstring = "" + CHECKduplicatetempsensors + "\n" + LISTduplicatetempsensors + "\n\n" + CHECKfewbmsinfo + "\n\n" + CHECKnogatewayserver + "\n\n" + CHECKethernetportcountsdonotmatchcomponents + "\n" + LISTethernetportcountsdonotmatchcomponents + "\n\n" + CHECKemptyelc + "\n" + LISTemptyelc + "\n\n" + CHECKnolegend + "\n" + LISTnolegend + "\n\n" + CHECKgapintempsensornumbering + "\n" + LISTgapintempsensornumbering + "\n\n" + CHECKmissingimages + "\n" + LISTmissingimages; return checksstring; }