List of usage examples for org.apache.commons.collections Bag size
int size();
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 w w w .j ava 2 s. c o m*/
// 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.marketcetera.util.test.CollectionAssert.java
/** * Asserts that the two given arrays are permutations of each * other. This assertion holds if both arrays are null, or if they * have one or more (but an equal number of) null elements. If the * assertion does not hold, the {@link AssertionError} thrown * starts with the given message, which may be null if no such * custom message prefix is desired.//from w w w . j av a 2s. c o m * * @param message The identifying message. * @param expected The expected array. * @param actual The actual array. */ public static <T> void assertArrayPermutation(String message, T[] expected, T[] actual) { if ((expected == null) && (actual == null)) { return; } String content = null; if (expected == null) { content = "expected array is null but actual is not"; //$NON-NLS-1$ } else if (actual == null) { content = "actual array is null but expected is not"; //$NON-NLS-1$ } else if (expected.getClass() != actual.getClass()) { content = "expected array class is " + //$NON-NLS-1$ expected.getClass().getName() + " but actual array class is " + //$NON-NLS-1$ actual.getClass().getName(); } else { Bag expectedBag = new HashBag(Arrays.asList(expected)); Bag actualBag = new HashBag(Arrays.asList(actual)); for (Object e : expectedBag) { if (!actualBag.remove(e, 1)) { content = "actual is missing '" + //$NON-NLS-1$ e + "'"; //$NON-NLS-1$ break; } } if (content == null) { if (actualBag.size() == 0) { return; } content = "actual contains extra elements such as " + //$NON-NLS-1$ actualBag.iterator().next(); } } if (message != null) { content = message + " " + content; //$NON-NLS-1$ } fail(content); }