List of usage examples for java.util Collections frequency
public static int frequency(Collection<?> c, Object o)
From source file:org.apache.falcon.regression.core.util.InstanceUtil.java
public static int getInstanceCountWithStatus(OozieClient oozieClient, String processName, CoordinatorAction.Status status, EntityType entityType) throws OozieClientException { List<CoordinatorAction> coordActions = getProcessInstanceList(oozieClient, processName, entityType); List<CoordinatorAction.Status> statuses = new ArrayList<>(); for (CoordinatorAction action : coordActions) { statuses.add(action.getStatus()); }// www . j a va2s . c o m return Collections.frequency(statuses, status); }
From source file:eu.mihosoft.vrl.v3d.Edge.java
private static List<Edge> boundaryEdgesOfPlaneGroup(List<Polygon> planeGroup) { List<Edge> edges = new ArrayList<>(); Stream<Polygon> pStream; if (planeGroup.size() > 200) { pStream = planeGroup.parallelStream(); } else {// w w w .j a v a 2 s.com pStream = planeGroup.stream(); } pStream.map((p) -> Edge.fromPolygon(p)).forEach((pEdges) -> { edges.addAll(pEdges); }); Stream<Edge> edgeStream; if (edges.size() > 200) { edgeStream = edges.parallelStream(); } else { edgeStream = edges.stream(); } // find potential boundary edges, i.e., edges that occur once (freq=1) List<Edge> potentialBoundaryEdges = new ArrayList<>(); edgeStream.forEachOrdered((e) -> { int count = Collections.frequency(edges, e); if (count == 1) { potentialBoundaryEdges.add(e); } }); // now find "false boundary" edges end remove them from the // boundary-edge-list // // thanks to Susanne Hllbacher for the idea :) Stream<Edge> bndEdgeStream; if (potentialBoundaryEdges.size() > 200) { bndEdgeStream = potentialBoundaryEdges.parallelStream(); } else { bndEdgeStream = potentialBoundaryEdges.stream(); } List<Edge> realBndEdges = bndEdgeStream .filter(be -> edges.stream().filter(e -> falseBoundaryEdgeSharedWithOtherEdge(be, e)).count() == 0) .collect(Collectors.toList()); // // System.out.println("#bnd-edges: " + realBndEdges.size() // + ",#edges: " + edges.size() // + ", #del-bnd-edges: " + (boundaryEdges.size() - realBndEdges.size())); return realBndEdges; }
From source file:hydrograph.ui.propertywindow.widgets.dialogs.join.JoinMapDialog.java
private void createOutputFieldColumnInMappingTable() { TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(mappingTableViewer, SWT.NONE); TableColumn tblclmnPropertyValue = tableViewerColumn_1.getColumn(); tblclmnPropertyValue.setWidth(148);/*w w w. java2s . c om*/ tblclmnPropertyValue.setText(JoinMapDialogConstants.OUTPUT_FIELD); outputEditingSupport = new JoinMappingEditingSupport(mappingTableViewer, JoinMapDialogConstants.OUTPUT_FIELD); WidgetUtility.addVerifyListnerToOutputEditingSupport(outputEditingSupport); tableViewerColumn_1.setEditingSupport(outputEditingSupport); tableViewerColumn_1.setLabelProvider(new ColumnLabelProvider() { String tooltipText; @Override public Image getImage(Object element) { Image image = ImagePathConstant.DELETE_ICON.getImageFromRegistry(); LookupMapProperty lookupMapProperty = (LookupMapProperty) element; if (StringUtils.isBlank(lookupMapProperty.getOutput_Field())) return image; else return super.getImage(element); } private List<String> getOutputFieldList() { List<String> outputFieldList = new LinkedList<>(); for (LookupMapProperty lookupMapProperty : mappingTableItemList) { outputFieldList.add(lookupMapProperty.getOutput_Field()); } return outputFieldList; } @Override public String getToolTipText(Object element) { tooltipText = null; int occurrences = Collections.frequency(getOutputFieldList(), ((LookupMapProperty) element).getOutput_Field()); if (occurrences > 1) { tooltipText = FIELD_TOOLTIP_MESSAGE_DUPLICATE_FIELDS; } LookupMapProperty lookupMapProperty = (LookupMapProperty) element; if (StringUtils.isBlank(lookupMapProperty.getSource_Field())) tooltipText = FIELD_TOOLTIP_MESSAGE_FIELD_CANT_BE_EMPTY; return tooltipText; } @Override public Color getForeground(Object element) { int occurrences = Collections.frequency(getOutputFieldList(), ((LookupMapProperty) element).getOutput_Field()); if (occurrences > 1) { return CustomColorRegistry.INSTANCE.getColorFromRegistry(255, 0, 0); } else { return super.getForeground(element); } } @Override public Color getBackground(Object element) { LookupMapProperty lookupMapProperty = (LookupMapProperty) element; if (StringUtils.isBlank(lookupMapProperty.getOutput_Field())) return CustomColorRegistry.INSTANCE.getColorFromRegistry(0xFF, 0xDD, 0xDD); else return super.getBackground(element); } @Override public String getText(Object element) { LookupMapProperty lookupMapProperty = (LookupMapProperty) element; if (ParameterUtil.isParameter(lookupMapProperty.getOutput_Field())) lookupMapProperty.setSource_Field(lookupMapProperty.getOutput_Field()); return lookupMapProperty.getOutput_Field(); } }); }
From source file:com.github.rinde.rinsim.scenario.measure.MetricsTest.java
static <T> boolean areAllValuesTheSame(List<T> list) { if (list.isEmpty()) { return true; }//from w w w.jav a 2 s .co m return Collections.frequency(list, list.get(0)) == list.size(); }
From source file:au.org.ala.delta.key.Key.java
private boolean compareStateDistributions(List<Set<Item>> dist1, List<Set<Item>> dist2) { for (Set<Item> dist1Item : dist1) { if (dist1Item.isEmpty()) { continue; }/*from w ww . java2 s . c om*/ if (Collections.frequency(dist1, dist1Item) != Collections.frequency(dist2, dist1Item)) { return false; } } return true; }
From source file:edu.duke.cabig.c3pr.dao.StudySubjectDao.java
public List<Study> getMostEnrolledStudies(Date startDate, Date endDate) { List<Study> listStudies = new ArrayList<Study>(); List<StudySubject> studySubjects = getHibernateTemplate().find( "select ss from StudySubject ss where ss.regWorkflowStatus=? and ss.startDate between ? and ? order by ss.id desc", new Object[] { RegistrationWorkFlowStatus.ON_STUDY, startDate, endDate }); for (StudySubject ss : studySubjects) { Study s = ss.getStudySite().getStudy(); listStudies.add(s);//from w ww . j a va 2 s. co m } Set<Study> setStudy = new HashSet<Study>(); setStudy.addAll(listStudies); for (Study study : setStudy) { study.setAccrualCount(Collections.frequency(listStudies, study)); } List<Study> studies = new ArrayList<Study>(); studies.addAll(setStudy); Collections.sort(studies, new AccrualCountComparator()); return studies; }
From source file:de.uni_potsdam.hpi.asg.logictool.mapping.SequenceBasedAndGateDecomposer.java
private void getNewSteps(IOBehaviourSimulationStep step, Signal sig, Set<IOBehaviour> newSequences, Deque<IOBehaviourSimulationStep> newSteps, Set<Signal> relevant) { int occurrences = Collections.frequency(step.getStates(), step.getNextState()); if (occurrences >= 2) { boolean isLoop = false; int[] a = new int[occurrences]; int index = 0; for (int i = step.getStates().size() - 1; i >= 0; i--) { if (step.getStates().get(i) == step.getNextState()) { a[index++] = i;//w w w. jav a 2 s. c o m } } Map<Integer, List<State>> lists = new HashMap<>(); int endindex = step.getStates().size(); List<State> xlist = null; for (int startindex : a) { xlist = step.getStates().subList(startindex, endindex); lists.put(endindex, xlist); endindex = startindex; } boolean finished = false; int smallesidloop = -1; for (Entry<Integer, List<State>> l1 : lists.entrySet()) { for (Entry<Integer, List<State>> l2 : lists.entrySet()) { if (l1.getKey() != l2.getKey()) { if (l1.getValue().equals(l2.getValue())) { // System.out.println("loop: listmatch!"); isLoop = true; smallesidloop = l1.getKey() < l2.getKey() ? l1.getKey() : l2.getKey(); xlist = l1.getValue(); finished = true; break; } } } if (finished) { break; } } if (isLoop) { // System.out.println("Loop: " + xlist + ", listsize: " + lists.size()); // System.out.println("Smallestid : " + smallesidloop + ", size: " + step.getStates().size()); step.findStateAndClean(step.getStates().size() - smallesidloop - 1, pool, newSteps); return; } } for (Entry<Transition, State> entry : step.getNextState().getNextStates().entrySet()) { //System.out.println(entry.toString()); if (entry.getKey().getSignal() == sig) { List<Transition> seq = new ArrayList<>(step.getSequence()); IOBehaviour beh = new IOBehaviour(seq, step.getStart(), step.getNextState()); newSequences.add(beh); } else { IOBehaviourSimulationStep newStep; try { newStep = pool.borrowObject(); } catch (Exception e) { e.printStackTrace(); logger.error("Could not borrow object"); return; } newStep.getSequence().addAll(step.getSequence()); if (relevant.contains(entry.getKey().getSignal())) { newStep.getSequence().add(entry.getKey()); } newStep.setStart(step.getStart()); newStep.setNextState(entry.getValue()); newStep.getStates().addAll(step.getStates()); newStep.getStates().add(step.getNextState()); newStep.setPrevStep(step); step.getNextSteps().add(newStep); newSteps.add(newStep); } } step.killIfCan(pool); }
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; }//from www . jav a2 s . c om 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 ww w. java2 s . 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; }