List of usage examples for org.apache.commons.collections.bag HashBag HashBag
public HashBag()
HashBag
. From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> getCallDirectionGraphData(List<CdrCallDirectionDecorator> cdrdecorated) { List<CdrGraphBean> directionCalls = new ArrayList<CdrGraphBean>(); Bag directionCallsBag = new HashBag(); for (CdrCallDirectionDecorator cdr : cdrdecorated) { directionCallsBag.add(cdr.getCallDirection()); }/* w w w . j ava 2s . co m*/ Set uniqueSetDirection = directionCallsBag.uniqueSet(); for (Object key : uniqueSetDirection) { CdrGraphBean bean = new CdrGraphBean((String) key, directionCallsBag.getCount(key)); directionCalls.add(bean); } return directionCalls; }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> getActiveCallersData(List<Cdr> cdrs) { Bag bagCallers = new HashBag(); for (Cdr cdr : cdrs) { bagCallers.add(cdr.getCaller()); }/*from w ww .j a va 2s. c o m*/ List<CdrGraphBean> activeCallers = mostActiveExtensions(bagCallers); return activeCallers; }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> getActiveReceiversData(List<Cdr> cdrs) { Bag bagReceivers = new HashBag(); for (Cdr cdr : cdrs) { bagReceivers.add(cdr.getCallee()); }/* w w w.j ava 2 s.c o m*/ List<CdrGraphBean> activeReceivers = mostActiveExtensions(bagReceivers); return activeReceivers; }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> getTerminationCallsData(List<Cdr> cdrs, Locale locale) { List<CdrGraphBean> terminationCalls = new ArrayList<CdrGraphBean>(); Bag terminationCallsBag = new HashBag(); for (Cdr cdr : cdrs) { CdrDecorator cdrDecorator = new CdrDecorator(cdr, locale, getMessages()); terminationCallsBag.add(cdrDecorator.getTermination()); }//from w w w. j a va 2 s . c om Set uniqueSetTermination = terminationCallsBag.uniqueSet(); for (Object key : uniqueSetTermination) { CdrGraphBean bean = new CdrGraphBean((String) key, terminationCallsBag.getCount(key)); terminationCalls.add(bean); } return terminationCalls; }
From source file:org.squashtest.tm.service.internal.testcase.TestCaseCallTreeFinder.java
/** * returns an extended graph of ALL the test cases that can be reached by the source test cases, navigating on the call test steps * in both directions. This graph include the callers and the called test cases, recursively including their callers and test cases * etc until all relevant test cases are included in the resulting graph. * * @param calledIds// w w w .java2s.com * @return */ // note : for each node, call steps are searched both upward and downward. As a result every edge will // be found twice (once on the up, once on the down). We then must build the graph by using only one edge over two // that's why we use a bag here, and then we halve the cardinality. public LibraryGraph<NamedReference, SimpleNode<NamedReference>> getExtendedGraph(List<Long> sourceIds) { // remember which nodes were processed (so that we can spare less DB calls in the worst cases scenarios) Set<Long> treated = new HashSet<>(); treated.addAll(sourceIds); // the temporary result variable Bag allpairs = new HashBag(); // a temporary buffer variable List<Long> currentNodes = new LinkedList<>(sourceIds); // phase 1 : data collection while (!currentNodes.isEmpty()) { List<NamedReferencePair> currentPair = testCaseDao.findTestCaseCallsUpstream(currentNodes); currentPair.addAll(testCaseDao.findTestCaseCallsDownstream(currentNodes)); allpairs.addAll(currentPair); /* * collect the caller ids in the currentPair for the next loop, with the following restrictions : * 1) if the "caller" slot of the Object[] is not null, * 2) if the "called" slot is not null, * 2) if that node was not already processed * * then we can add that id. */ List<Long> nextNodes = new LinkedList<>(); for (NamedReferencePair pair : currentPair) { // no caller or no called -> no need for further processing if (pair.getCaller() == null || pair.getCalled() == null) { continue; } Long callerkey = pair.getCaller().getId(); if (!treated.contains(callerkey)) { nextNodes.add(callerkey); treated.add(callerkey); } Long calledkey = pair.getCalled().getId(); if (!treated.contains(calledkey)) { nextNodes.add(calledkey); treated.add(calledkey); } } currentNodes = nextNodes; } // phase 2 : halve the number of edges as explained in the comment above the method // every edges will appear two times, except for "boundaries" (ie caller is null or called is null), // for which the cardinality is 1. for (NamedReferencePair pair : (Set<NamedReferencePair>) allpairs.uniqueSet()) { int cardinality = allpairs.getCount(pair); if (cardinality > 1) { allpairs.remove(pair, cardinality / 2); } } // phase 3 : make that graph LibraryGraph<NamedReference, SimpleNode<NamedReference>> graph = new LibraryGraph<>(); for (NamedReferencePair pair : (Iterable<NamedReferencePair>) allpairs) { graph.addEdge(node(pair.getCaller()), node(pair.getCalled())); } return graph; }
From source file:pl.polzone.classifier.Classifier.java
public void feed(String category, java.util.List<String> words) { feedCount++;/*from w ww .ja va 2s . co m*/ for (Object word : new HashSet(Lists.transform(words, new Function<String, String>() { @Override public String apply(String word) { return stem(word); } }))) { if (word == null) continue; wordCount.add(word); if (!occurences.containsKey(word)) occurences.put((String) word, new HashBag()); occurences.get(word).add(category); } }
From source file:uk.ac.ebi.intact.dataexchange.cvutils.CvUpdater.java
/** * This method should check if the below constraint is violated * CONSTRAINT_INDEX_0 ON PUBLIC.IA_CONTROLLEDVOCAB(OBJCLASS, SHORTLABEL) * * @param allValidCvs List of all Uniq Cvs * @return true if violated or false if not *//*from w ww.ja v a 2 s .co m*/ public boolean isConstraintViolated(List<CvDagObject> allValidCvs) { if (allValidCvs == null) { throw new NullPointerException("Cvs Null"); } Bag hashBag = new HashBag(); for (CvDagObject cvDag : allValidCvs) { String primaryKey = cvDag.getObjClass().toString() + ":" + cvDag.getShortLabel(); if (log.isTraceEnabled()) { log.trace("PrimaryKey: " + primaryKey); } hashBag.add(primaryKey); } for (Object aHashBag : hashBag) { String s = (String) aHashBag; if (hashBag.getCount(s) > 1) { if (log.isDebugEnabled()) { log.debug("Constraint violated by " + s); } return true; } } return false; }