List of usage examples for org.apache.commons.collections Bag add
boolean add(Object object, int nCopies);
nCopies
copies of the specified object to the Bag. From source file:com.discursive.jccook.collections.bag.BagExample.java
private void start() { // Read our inventory into a Bag populateInventory();//from w ww .ja v a 2 s.co m System.out.println("Inventory before Transactions"); printAlbums(inventoryBag); printSeparator(); // A Customer wants to purchase 400 copies of ABBA and 2 copies of Radiohead Bag shoppingCart1 = new HashBag(); shoppingCart1.add(album4, 500); shoppingCart1.add(album3, 150); shoppingCart1.add(album1, 2); checkout(shoppingCart1, "Customer 1"); // Another Customer wants to purchase 600 copies of ABBA Bag shoppingCart2 = new HashBag(); shoppingCart2.add(album4, 600); checkout(shoppingCart2, "Customer 2"); // Another Customer wants to purchase 3 copies of Kraftwerk Bag shoppingCart3 = new HashBag(); shoppingCart3.add(album2, 3); checkout(shoppingCart3, "Customer 3"); System.out.println("Inventory after Transactions"); printAlbums(inventoryBag); }
From source file:annis.sqlgen.TestAbstractFromClauseGenerator.java
private void setupTableAliases(String table, String tableAlias, int count) { HashMap<String, String> tableAliases = new HashMap<String, String>(); tableAliases.put(table, tableAlias); tableAccessStrategy.setTableAliases(tableAliases); Bag tables = new HashBag(); tables.add(tableAlias, count); given(tableAccessStrategy.computeSourceTables()).willReturn(tables); }
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
private boolean checkWithScheduledRemovalsLocal(MaterialKey key, String materializationDirectory) throws IOException { Map<String, LocalFileRemover> materialRemovers = fileRemovers.get(key); if (materialRemovers == null) { return true; }/* ww w.j a va2 s .c o m*/ LocalFileRemover localFileRemover = materialRemovers.get(materializationDirectory); if (localFileRemover == null) { return true; } boolean managedToCancel = localFileRemover.scheduledFuture.cancel(false); if (managedToCancel) { // Put back to L1 cache if (!materialCache.containsKey(key)) { if (localFileRemover.cryptoMaterial != null) { materialCache.put(key, localFileRemover.cryptoMaterial); } else { CryptoMaterial material = getMaterialFromDatabase(key); materialCache.put(key, material); } } // Put back to material map Bag materializeBag = materializedCerts.get(key); if (materializeBag != null) { materializeBag.add(materializationDirectory, 1); } else { Bag materializedBag = new HashBag(); materializedBag.add(materializationDirectory); materializedCerts.put(key, materializedBag); } // Remove from scheduled removers materialRemovers.remove(materializationDirectory); if (materialRemovers.isEmpty()) { fileRemovers.remove(key); } return false; } else { forceRemoveLocalMaterial(key.username, key.projectName, materializationDirectory); return true; } }
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
private void materializeLocalInternal(MaterialKey key, String localDirectory) throws IOException { Bag materializedDirs = materializedCerts.get(key); if (materializedDirs == null) { // Check to see if there is any scheduled removal // If there is try to cancel it // If not possible materialize boolean shouldContinue = checkWithScheduledRemovalsLocal(key, localDirectory); if (shouldContinue) { // First time it was requested to be materialized // 1. Get certs fro DB CryptoMaterial material = getMaterialFromDatabase(key); // 2. Add them to L1 Cache materialCache.put(key, material); // 3. Write them to local FS flushToLocalFileSystem(key, material, localDirectory); // 4. Add Directory to Bag and then to materializedCerts Bag materialBag = new HashBag(); String targetDir = localDirectory != null ? localDirectory : transientDir; materialBag.add(targetDir, 1); materializedCerts.put(key, materialBag); }/* w w w . j a va 2s. co m*/ } else { int cardinality = materializedDirs.getCount(localDirectory); if (cardinality == 0) { // Check to see if there is any scheduled removal // If there is try to cancel it // If not possible materialize boolean shouldContinue = checkWithScheduledRemovalsLocal(key, localDirectory); if (shouldContinue) { // First time for this directory, but not for the material in general // 1. Get byte material from L1 Cache. If not there, something went wrong // but fetch them from DB anyways CryptoMaterial material = materialCache.get(key); if (material == null) { material = getMaterialFromDatabase(key); } // 2. Flush buffers to local filesystem flushToLocalFileSystem(key, material, localDirectory); // 3. Increment cardinality materializedDirs.add(localDirectory, 1); } } else { // Materialization in this Directory has already been requested // 1. Increment cardinality for this Material and Directory materializedDirs.add(localDirectory, 1); } } }
From source file:org.lockss.crawler.CrawlManagerImpl.java
Bag copyRunKeys(boolean sharedOnly) { synchronized (runningCrawlersLock) { Bag res = new HashBag(); for (Map.Entry<String, PoolCrawlers> ent : poolMap.entrySet()) { PoolCrawlers pc = ent.getValue(); if (sharedOnly && !pc.isShared()) { continue; }//from w w w . ja v a 2 s .c o m int sum = 0; for (CrawlRateLimiter crl : pc.crls) { sum += crl.getNewContentCount(); } res.add(ent.getKey(), sum); } return res; } }