List of usage examples for org.apache.commons.collections Bag uniqueSet
Set uniqueSet();
From source file:com.discursive.jccook.collections.bag.BagExample.java
private void printAlbums(Bag albumBag) { Set albums = albumBag.uniqueSet(); Iterator albumIterator = albums.iterator(); while (albumIterator.hasNext()) { Album album = (Album) albumIterator.next(); NumberFormat format = NumberFormat.getInstance(); format.setMinimumIntegerDigits(3); format.setMaximumFractionDigits(0); System.out.println("\t" + format.format(albumBag.getCount(album)) + " - " + album.getBand()); }//from w w w. j a va 2 s .c o m }
From source file:com.pureinfo.tgirls.utils.counts.CountsJob.java
public void execute() { logger.debug("to process counts."); CountsProcess cache = CountsProcess.getInstance(); Bag bag = new HashBag(); synchronized (cache) { bag.addAll(cache.getBag());// w ww . j a v a2 s.co m cache.clear(); } ISession session = null; try { session = LocalContextHelper.currentSession(); Set<String> bagKeySet = bag.uniqueSet(); for (Iterator<String> iterator = bagKeySet.iterator(); iterator.hasNext();) { String type = null; try { type = iterator.next(); Counts counts = new Counts(); counts.setType(type); counts.setCounts(bag.getCount(type)); counts.setCreateTime(); session.save(counts); } catch (Exception e) { logger.error("error when save counts:" + type, e); } } } catch (Exception e) { logger.error("error occur.", e); } finally { bag.clear(); if (session != null) try { session.close(); } catch (Exception e) { logger.error("error when close session.", e); } } }
From source file:com.otiliouine.flera.analyzer.SuccessionBasedDictionaryAnalyzer.java
public char getMostSucceeds(char precedent) { Bag<Succession> successionBag = successionBags.get(precedent); if (successionBag == null || successionBag.isEmpty()) { throw new RuntimeException("No successors found for the character '" + precedent + "'"); }/* ww w. ja v a 2 s.c om*/ Character mostSucceeds = null; int nbrSuccessions = 0; for (Succession current : successionBag.uniqueSet()) { int currentCount = successionBag.getCount(current); if (currentCount > nbrSuccessions) { nbrSuccessions = currentCount; mostSucceeds = current.successor; } } return mostSucceeds; }
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
/** * Returns the state of the CertificateMaterializer service * The state includes://from w ww .j av a 2 s . c o m * 1) Identifier of material, materialization directory and number of references for the certificates in the local * filesystem * * 2) Identifier of material, materialization directory and number of references for the certificates in the remote * filesystem (HDFS) * * 3) Identifier of the material that are scheduled to be removed from the local filesystem * * @return The state of the CertificateMaterializer at that point of time */ @SuppressWarnings("unchecked") public MaterializerState<Map<String, Map<String, Integer>>, Map<String, Map<String, Integer>>, Map<String, Set<String>>, Map<String, Boolean>> getState() { MaterializerState<Map<MaterialKey, Bag>, List<RemoteMaterialReferences>, Map<MaterialKey, Map<String, Runnable>>, Map<MaterialKey, ReentrantReadWriteLock>> state = getImmutableState(); Map<MaterialKey, Bag> localMaterialState = state.getLocalMaterial(); // <Username, <MaterialPath, NumberOfReferences>> Map<String, Map<String, Integer>> simpleLocalMaterialState = new HashMap<>(localMaterialState.size()); for (Map.Entry<MaterialKey, Bag> entry : localMaterialState.entrySet()) { String username = entry.getKey().getExtendedUsername(); Map<String, Integer> referencesMap = new HashMap<>(); Bag pathsBag = entry.getValue(); Set<String> paths = pathsBag.uniqueSet(); for (String path : paths) { referencesMap.put(path, pathsBag.getCount(path)); } simpleLocalMaterialState.put(username, referencesMap); } List<RemoteMaterialReferences> remoteMaterialState = state.getRemoteMaterial(); // <Username, <MaterialPath, NumberOfReferences>> Map<String, Map<String, Integer>> simpleRemoteMaterialState = new HashMap<>(remoteMaterialState.size()); for (RemoteMaterialReferences ref : remoteMaterialState) { String username = ref.getIdentifier().getUsername(); Map<String, Integer> references = simpleRemoteMaterialState.get(username); if (references == null) { references = new HashMap<>(); references.put(ref.getIdentifier().getPath(), ref.getReferences()); simpleRemoteMaterialState.put(username, references); } else { references.put(ref.getIdentifier().getPath(), ref.getReferences()); } } Map<MaterialKey, Map<String, Runnable>> fileRemovals = state.getScheduledRemovals(); // <Username, [MaterialPath]> Map<String, Set<String>> simpleScheduledRemovals = new HashMap<>(); for (Map.Entry<MaterialKey, Map<String, Runnable>> entry : fileRemovals.entrySet()) { String username = entry.getKey().getExtendedUsername(); simpleScheduledRemovals.put(username, entry.getValue().keySet()); } Map<MaterialKey, ReentrantReadWriteLock> materialKeyLocks = state.getMaterialKeyLocks(); // Username, Locked Map<String, Boolean> flatMaterialKeyLocks = new HashMap<>(materialKeyLocks.size()); for (Map.Entry<MaterialKey, ReentrantReadWriteLock> lock : materialKeyLocks.entrySet()) { flatMaterialKeyLocks.put(lock.getKey().getExtendedUsername(), lock.getValue().isWriteLocked()); } return new MaterializerState<>(simpleLocalMaterialState, simpleRemoteMaterialState, simpleScheduledRemovals, flatMaterialKeyLocks); }
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 va 2 s . com } 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.FuncArcExploder.java
public void runTest(boolean good) throws Exception { log.debug3("About to create content"); createContent();/*from w w w . j ava2 s. c om*/ // get the root of the simContent String simDir = sau.getSimRoot(); log.debug3("About to crawl content"); boolean res = crawlContent(good ? null : url[url.length - 1]); if (good) { assertTrue("Crawl failed", res); } else { assertFalse("Crawl succeeded", res); return; } // read all the files links from the root of the simcontent // check the link level of the file and see if it contains // in myCUS (check if the crawler crawl within the max. depth) CachedUrlSet myCUS = sau.getAuCachedUrlSet(); File dir = new File(simDir); if (dir.isDirectory()) { File f[] = dir.listFiles(); log.debug("Checking simulated content."); checkThruFileTree(f, myCUS); log.debug("Checking simulated content done."); checkExplodedUrls(); checkUnExplodedUrls(); log.debug("Check finished."); } else { log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory"); } // Test PluginManager.getAuContentSize(), just because this is a // convenient place to do it. If the simulated AU params are changed, or // SimulatedContentGenerator is changed, this number may have to // change. NB - because the ARC files are compressed, their // size varies randomly by a small amount. long expected = 5579; long actual = AuUtil.getAuContentSize(sau, true); long error = expected - actual; log.debug("Expected " + expected + " actual " + actual); long absError = (error < 0 ? -error : error); assertTrue("size mismatch " + expected + " vs. " + actual, absError < 100); List sbc = ((MySimulatedArchivalUnit) sau).sbc; Bag b = new HashBag(sbc); Set uniq = new HashSet(b.uniqueSet()); for (Iterator iter = uniq.iterator(); iter.hasNext();) { b.remove(iter.next(), 1); } // Permission pages get checked twice. Hard to avoid that, so allow it b.removeAll(sau.getPermissionUrls()); // archives get checked twice - from checkThruFileTree & checkExplodedUrls b.remove(url2[url2.length - 1]); // This test is screwed up by the use of shouldBeCached() in // ArcExploder() to find the AU to store the URL in. //assertEmpty("shouldBeCached() called multiple times on same URLs.", b); // Test getUrlStems checkGetUrlStems(); // Test crawl rules checkCrawlRules(); // Test getPermissionPage //checkGetPermissionPages(); }
From source file:org.lockss.crawler.FuncArcExploder2.java
public void runTest(boolean good) throws Exception { log.debug3("About to create content"); createContent();/* w ww .j a v a 2 s . com*/ // get the root of the simContent String simDir = sau.getSimRoot(); log.debug3("About to crawl content"); boolean res = crawlContent(good ? null : url[url.length - 1]); if (good) { assertTrue("Crawl failed", res); } else { assertFalse("Crawl succeeded", res); return; } // read all the files links from the root of the simcontent // check the link level of the file and see if it contains // in myCUS (check if the crawler crawl within the max. depth) CachedUrlSet myCUS = sau.getAuCachedUrlSet(); File dir = new File(simDir); if (dir.isDirectory()) { checkExplodedUrls(); checkUnExplodedUrls(); log.debug("Check finished."); } else { log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory"); } // Test PluginManager.getAuContentSize(), just because this is a // convenient place to do it. If the simulated AU params are changed, or // SimulatedContentGenerator is changed, this number may have to // change. NB - because the ARC files are compressed, their // size varies randomly by a small amount. long expected = 2671; long actual = AuUtil.getAuContentSize(sau, true); long error = expected - actual; long absError = (error < 0 ? -error : error); assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60); List sbc = ((MySimulatedArchivalUnit) sau).sbc; Bag b = new HashBag(sbc); Set uniq = new HashSet(b.uniqueSet()); for (Iterator iter = uniq.iterator(); iter.hasNext();) { b.remove(iter.next(), 1); } // Permission pages get checked twice. Hard to avoid that, so allow it b.removeAll(sau.getPermissionUrls()); // archives get checked twice - from checkThruFileTree & checkExplodedUrls b.remove(url2[url2.length - 1]); // This test is screwed up by the use of shouldBeCached() in // ArcExploder() to find the AU to store the URL in. //assertEmpty("shouldBeCached() called multiple times on same URLs.", b); }
From source file:org.lockss.crawler.FuncNewContentCrawler.java
public void testRunSelf() throws Exception { createContent();//from ww w.j av a 2 s . c o m // get the root of the simContent String simDir = sau.getSimRoot(); NoCrawlEndActionsFollowLinkCrawler crawler = crawlContent(); // read all the files links from the root of the simcontent // check the link level of the file and see if it contains // in myCUS (check if the crawler crawl within the max. depth) CachedUrlSet myCUS = sau.getAuCachedUrlSet(); File dir = new File(simDir); if (dir.isDirectory()) { File f[] = dir.listFiles(); log.debug("Checking simulated content."); checkThruFileTree(f, myCUS); log.debug("Check finished."); } else { log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory"); } // Test PluginManager.getAuContentSize(), just because this is a // convenient place to do it. (And NewContentCrawler calls it at the // end.) If the simulated AU params are changed, or // SimulatedContentGenerator is changed, this number may have to // change. assertEquals(19262, AuUtil.getAuContentSize(sau, true)); List sbc = ((MySimulatedArchivalUnit) sau).sbc; Bag b = new HashBag(sbc); Set uniq = new HashSet(b.uniqueSet()); for (Iterator iter = uniq.iterator(); iter.hasNext();) { b.remove(iter.next(), 1); } // Permission pages get checked twice. Hard to avoid that, so allow it b.removeAll(sau.getPermissionUrls()); assertEmpty("shouldBeCached() called multiple times on same URLs.", b); String th = "text/html"; String tp = "text/plain"; String[] ct = { null, null, null, tp, tp, th, th, tp, tp, th, tp }; Bag ctb = new HashBag(ListUtil.fromArray(ct)); CrawlRateLimiter crl = crawlMgr.getCrawlRateLimiter(crawler); assertEquals(ctb, new HashBag(crawlMgr.getPauseContentTypes(crawler))); }
From source file:org.lockss.crawler.FuncTarExploder.java
public void runTest(boolean good) throws Exception { log.debug3("About to create content"); createContent();/* w w w. j a v a2 s .co m*/ // get the root of the simContent String simDir = sau.getSimRoot(); log.debug3("About to crawl content"); boolean res = crawlContent(good ? null : "002file.bin"); if (good) { assertTrue("Crawl failed", res); if (false) assertTrue( "Crawl should succeed but got " + lastCrawlResult + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage), lastCrawlResult == Crawler.STATUS_SUCCESSFUL); } else { assertFalse("Crawl succeeded", res); if (false) assertTrue( "Crawl should get STATUS_PLUGIN_ERROR but got " + lastCrawlResult + (lastCrawlMessage == null ? "" : " with " + lastCrawlMessage), lastCrawlResult == Crawler.STATUS_PLUGIN_ERROR); return; } // read all the files links from the root of the simcontent // check the link level of the file and see if it contains // in myCUS (check if the crawler crawl within the max. depth) CachedUrlSet myCUS = sau.getAuCachedUrlSet(); File dir = new File(simDir); if (dir.isDirectory()) { File f[] = dir.listFiles(); log.debug("Checking simulated content."); checkThruFileTree(f, myCUS); log.debug("Checking simulated content done."); checkExplodedUrls(); checkUnExplodedUrls(); log.debug("Check finished."); } else { log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory"); } // Test PluginManager.getAuContentSize(), just because this is a // convenient place to do it. If the simulated AU params are changed, or // SimulatedContentGenerator is changed, this number may have to // change. NB - because the TAR files are compressed, their // size varies randomly by a small amount. long expected = 41399; long actual = AuUtil.getAuContentSize(sau, true); long error = expected - actual; long absError = (error < 0 ? -error : error); assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60); List sbc = ((MySimulatedArchivalUnit) sau).sbc; Bag b = new HashBag(sbc); Set uniq = new HashSet(b.uniqueSet()); for (Iterator iter = uniq.iterator(); iter.hasNext();) { b.remove(iter.next(), 1); } // Permission pages get checked twice. Hard to avoid that, so allow it b.removeAll(sau.getPermissionUrls()); // archives get checked twice - from checkThruFileTree & checkExplodedUrls b.remove("http://www.example.com/content.tar"); // This test is screwed up by the use of shouldBeCached() in // TarExploder() to find the AU to store the URL in. //assertEmpty("shouldBeCached() called multiple times on same URLs.", b); }
From source file:org.lockss.crawler.FuncTarExploder2.java
public void testRunSelf() throws Exception { log.debug3("About to create content"); createContent();//from w w w . jav a 2 s . c o m // get the root of the simContent String simDir = sau.getSimRoot(); assertTrue("No simulated content", simDir != null); log.debug3("About to crawl content"); crawlContent(); // read all the files links from the root of the simcontent // check the link level of the file and see if it contains // in myCUS (check if the crawler crawl within the max. depth) CachedUrlSet myCUS = sau.getAuCachedUrlSet(); File dir = new File(simDir); if (dir.isDirectory()) { File f[] = dir.listFiles(); log.debug("Checking simulated content."); checkThruFileTree(f, myCUS); log.debug("Checking simulated content done."); checkUnExplodedUrls(); checkExplodedUrls(); log.debug("Check finished."); } else { log.error("Error: The root path of the simulated" + " content [" + dir + "] is not a directory"); } // Test PluginManager.getAuContentSize(), just because this is a // convenient place to do it. If the simulated AU params are changed, or // SimulatedContentGenerator is changed, this number may have to // change. NB - because the TAR files are compressed, their // size varies randomly by a small amount. long expected = 261173; long actual = AuUtil.getAuContentSize(sau, true); long error = expected - actual; long absError = (error < 0 ? -error : error); assertTrue("size mismatch " + expected + " vs. " + actual, absError < 60); if (false) { List sbc = ((MySimulatedArchivalUnit) sau).sbc; Bag b = new HashBag(sbc); Set uniq = new HashSet(b.uniqueSet()); for (Iterator iter = uniq.iterator(); iter.hasNext();) { b.remove(iter.next(), 1); } // Permission pages get checked twice. Hard to avoid that, so allow it b.removeAll(sau.getPermissionUrls()); // archives get checked twice - from checkThruFileTree & checkExplodedUrls b.remove("http://www.example.com/issn.tar"); // This test is screwed up by the use of shouldBeCached() in // TarExploder() to find the AU to store the URL in. //assertEmpty("shouldBeCached() called multiple times on same URLs.", b); } // Now check the DOIs checkDOIs(); }