List of usage examples for org.apache.commons.collections Bag isEmpty
boolean isEmpty();
From source file:com.otiliouine.flera.analyzer.SuccessionBasedDictionaryAnalyzer.java
/** * Pick a random character from successor of a given character in dictionary words, most succeeds * characters to the given character have more chances to be picked * //from w w w. j ava 2s. c o m * @param precedent to search on his successors * @return the picked successor */ public char getRandomSuccessor(char precedent) { Bag<Succession> successionBag = successionBags.get(precedent); if (successionBag == null || successionBag.isEmpty()) { throw new RuntimeException("No successors found for the character '" + precedent + "'"); } return successionBag.pickAndRemit().successor; }
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 + "'"); }//w w w . j a v a 2s . c o m 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
private void forceRemoveLocalMaterial(String username, String projectName, String materializationDirectory) { ReentrantReadWriteLock.WriteLock lock = null; try {//from www .j a v a 2 s . c om materializationDirectory = materializationDirectory != null ? materializationDirectory : transientDir; MaterialKey key = new MaterialKey(username, projectName); lock = getWriteLockForKey(key); lock.lock(); // First remove from File Removers list Map<String, LocalFileRemover> materialRemovers = fileRemovers.get(key); if (materialRemovers != null) { LocalFileRemover fileRemover = materialRemovers.remove(materializationDirectory); if (fileRemover != null) { fileRemover.scheduledFuture.cancel(true); } if (materialRemovers.isEmpty()) { fileRemovers.remove(key); } } // Then remove from material Map and maybe from Cache Bag materialBag = materializedCerts.get(key); if (materialBag != null) { materialBag.remove(materializationDirectory); if (materialBag.isEmpty()) { materializedCerts.remove(key); CryptoMaterial material = materialCache.remove(key); if (material != null) { material.wipePassword(); } } } // Then from local FS deleteMaterialFromLocalFs(key, materializationDirectory); removeLockForKey(key); } finally { lock.unlock(); } }