List of usage examples for org.apache.commons.collections Bag getCount
int getCount(Object object);
From source file:org.codice.ddf.ui.searchui.query.model.Search.java
private void updateResultStatus(List<Result> results) { Bag hitSourceCount = new HashBag(); for (QueryStatus status : queryStatus.values()) { status.setResultCount(0);// w w w . j a v a 2 s . c o m } for (Result result : results) { hitSourceCount.add(result.getMetacard().getSourceId()); } for (Object sourceId : hitSourceCount.uniqueSet()) { if (queryStatus.containsKey(sourceId)) { queryStatus.get(sourceId).setResultCount(hitSourceCount.getCount(sourceId)); } } }
From source file:org.lockss.crawler.CrawlManagerImpl.java
boolean isWorthRebuildingQueue() { Bag runKeys = copySharedRunKeys(); for (Map.Entry<String, MutableInt> ent : poolEligible.entrySet()) { int additionalEligible = ent.getValue().intValue(); if (additionalEligible <= 0) { continue; }// www .ja v a 2 s . co m String rateKey = ent.getKey(); if (rateKey == UNSHARED_RATE_KEY) { logger.debug2("Pool " + rateKey + ", addtl eligible: " + additionalEligible); return true; } else { logger.debug2("Pool " + rateKey + ", size " + getCrawlPoolSize(rateKey) + ", running " + runKeys.getCount(rateKey) + ", addtl eligible: " + additionalEligible); if (getCrawlPoolSize(rateKey) > (runKeys.getCount(rateKey))) { return true; } } } return false; }
From source file:org.lockss.crawler.CrawlManagerImpl.java
CrawlReq nextReqFromBuiltQueue() { Bag runKeys = copySharedRunKeys(); synchronized (queueLock) { if (logger.isDebug3()) { logger.debug3("nextReqFromBuiltQueue(), " + sharedRateReqs.size() + " shared, " + unsharedRateReqs.size() + " unshared, " + " runKeys: " + runKeys); }//from www . ja va 2 s.c om // preferentially start those with shared rate limiters, but give // unshared a minimum number of threads BoundedTreeSet finalSort = new BoundedTreeSet(1, CPC); for (Iterator iter = sharedRateReqs.entrySet().iterator(); iter.hasNext();) { Map.Entry<String, TreeSet> ent = (Map.Entry) iter.next(); String rateKey = ent.getKey(); int poolSize = getCrawlPoolSize(rateKey); if (logger.isDebug3()) { logger.debug3("Rate key: " + rateKey + ", pool: " + poolSize + ", current: " + runKeys.getCount(rateKey)); } if (runKeys.getCount(rateKey) >= poolSize) { continue; } CrawlReq req = (CrawlReq) ent.getValue().first(); if (logger.isDebug3()) logger.debug3("Adding to final sort: " + req); finalSort.add(req); } if (!unsharedRateReqs.isEmpty() && (finalSort.isEmpty() || runKeys.size() >= (paramMaxPoolSize - paramFavorUnsharedRateThreads) || ((CrawlReq) unsharedRateReqs.first()).isHiPri())) { CrawlReq req = (CrawlReq) unsharedRateReqs.first(); if (logger.isDebug3()) logger.debug3("Adding to final sort: " + req); finalSort.add(req); } if (finalSort.isEmpty()) { if (logger.isDebug3()) { logger.debug3("nextReqFromBuiltQueue(): null, " + sharedRateReqs.size() + " shared"); } return null; } CrawlReq bestReq = (CrawlReq) finalSort.first(); if (bestReq.rateKey != null) { sharedRateReqs.remove(bestReq.rateKey, bestReq); } else { unsharedRateReqs.remove(bestReq); } logger.debug3("nextReqFromBuiltQueue: " + bestReq); return bestReq; } }
From source file:org.rzo.yajsw.os.ms.win.w32.Pdh.java
/** * Enum object items./* w w w. ja v a 2 s. c om*/ * * @param objectName * the object name * @param english * the english * * @return the list */ public static List enumObjectItems(String objectName, boolean english) { if (english) objectName = translate(objectName); Bag bag = new HashBag(); int pdhStatus = Pdhdll.ERROR_SUCCESS; Memory szCounterListBuffer = null; IntByReference dwCounterListSize = new IntByReference(); Memory szInstanceListBuffer = null; IntByReference dwInstanceListSize = new IntByReference(); String szThisInstance = null; // Determine the required buffer size for the data. pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real time // source null, // local machine objectName, // object to enumerate szCounterListBuffer, // pass NULL and 0 dwCounterListSize, // to get length required szInstanceListBuffer, // buffer size dwInstanceListSize, // Pdhdll.PERF_DETAIL_WIZARD, // counter detail level 0); if (pdhStatus == Pdhdll.PDH_MORE_DATA) { // Allocate the buffers and try the call again. szCounterListBuffer = new Memory(dwCounterListSize.getValue() * 4); szInstanceListBuffer = new Memory((dwInstanceListSize.getValue() * 4)); if ((szCounterListBuffer != null) && (szInstanceListBuffer != null)) { pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real // time // source null, // local machine objectName, // object to enumerate szCounterListBuffer, // buffer to receive counter // list dwCounterListSize, szInstanceListBuffer, // buffer to // receive // instance // list dwInstanceListSize, Pdhdll.PERF_DETAIL_WIZARD, // counter // detail // level 0); if (pdhStatus == Pdhdll.ERROR_SUCCESS) { // System.out.println ("Enumerating Processes:"); // Walk the instance list. The list can contain one // or more null-terminated strings. The last string // is followed by a second null-terminator. int i = 0; for (szThisInstance = szInstanceListBuffer.getString(0); szThisInstance != null && szThisInstance.length() > 0; i += szThisInstance.length() + 1, szThisInstance = szInstanceListBuffer.getString(i)) { // System.out.println( szThisInstance); bag.add(szThisInstance); } } else { System.out.println("PdhEnumObjectItems failed with " + Integer.toHexString(pdhStatus)); } } else { System.out.println("Unable to allocate buffers"); // pdhStatus = ERROR_OUTOFMEMORY; } } else { System.out.println("PdhEnumObjectItems failed with " + Integer.toHexString(pdhStatus)); } List result = new ArrayList(); for (Iterator it = bag.uniqueSet().iterator(); it.hasNext();) { String str = (String) it.next(); result.add(str); // System.out.println(str); for (int i = 1; i < bag.getCount(str); i++) { result.add(str + "#" + i); // System.out.println(str+"#"+i); } } return result; }
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 ww . j a va 2s. c o 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> 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()); }// w ww .j ava 2s .c o m 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.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private List<CdrGraphBean> mostActiveExtensions(Bag bagExtensions) { List<CdrGraphBean> activeExtensions = new ArrayList<CdrGraphBean>(); Set uniqueSetCallers = bagExtensions.uniqueSet(); for (Object key : uniqueSetCallers) { CdrGraphBean bean = new CdrGraphBean((String) key, bagExtensions.getCount(key)); activeExtensions.add(bean);/*from w ww.ja v a 2 s .c o m*/ } Collections.sort(activeExtensions, Collections.reverseOrder()); if (activeExtensions.size() > 10) { activeExtensions = activeExtensions.subList(0, 10); } return activeExtensions; }
From source file:org.sonar.api.utils.KeyValueFormat.java
/** * @since 1.11//from w ww . jav a 2 s. c o m * @deprecated use Multiset from google collections instead of commons-collections bags */ @Deprecated public static String format(Bag bag, int var) { StringBuilder sb = new StringBuilder(); if (bag != null) { boolean first = true; for (Object obj : bag.uniqueSet()) { if (!first) { sb.append(PAIR_SEPARATOR); } sb.append(obj.toString()); sb.append(FIELD_SEPARATOR); sb.append(bag.getCount(obj) + var); first = false; } } return sb.toString(); }
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//from w ww . jav a2 s . c om * @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: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 */// w ww .ja va 2 s. c o 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; }