List of usage examples for java.util Collection removeAll
boolean removeAll(Collection<?> c);
From source file:gov.nih.nci.caintegrator.common.PermissibleValueUtil.java
private static void checkObsolete(Collection<PermissibleValue> abstractPermissibleValues, List<String> newList) { List<PermissibleValue> removeList = new ArrayList<PermissibleValue>(); for (PermissibleValue abstractPermissibleValue : abstractPermissibleValues) { if (newList == null || !newList.contains(abstractPermissibleValue.toString())) { removeList.add(abstractPermissibleValue); }/*from ww w .ja v a 2 s.co m*/ } abstractPermissibleValues.removeAll(removeList); }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
public static <Constraint, Model> Pair<Model, Collection<Constraint>> minimizeFixingSet( Theory<Constraint, Model> theorySolver, List<Constraint> hardConstraints, List<Constraint> softConstraints, Model model, Collection<Constraint> fixingSet) { System.out.println("MINIMIZING FIXING SET [initial size=" + fixingSet.size() + ']'); int iter = 0; Collection<Constraint> positive = new LinkedHashSet<>(); boolean changed; do {/*from w ww. j a v a 2s . c o m*/ ++iter; System.out.println(" --> iteration " + iter + "..."); changed = false; for (Constraint c : fixingSet) { Collection<Constraint> candidate = without(fixingSet, c); positive.addAll(hardConstraints); positive.addAll(softConstraints); positive.removeAll(candidate); Either<Model, Collection<Constraint>> result = theorySolver.check(positive); if (result.left != null) { // it's still a fixing set! changed = true; fixingSet = candidate; model = result.left; break; } } } while (changed); System.out.println("FINISHED MINIMIZING [final size=" + fixingSet.size() + ']'); return Pair.of(model, fixingSet); }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
/** * Given a fixing set finder, a solver for some particular theory, and some constraints, * this procedure either finds a model or it finds a minimum set of constraints * which, if broken, make the system satisfiable (a "fixing set"). * * <p>A <em>theory</em> is a solver that solves simple conjunctions of constraints. * The performance of this algorithm highly depends on the ability of the theory to * produce small unsatisfiable cores.// w w w.j a v a 2s. com * * @param <Constraint> the type of constraint solved by the theory * @param <Model> the type of model produced by the theory * @param theorySolver a solver for some theory * @param fixingSetFinder a strategy for finding a fixing set * @param hardConstraints the hard constraints which MUST be satisfied * @param softConstraints the labeled soft constraints from which the fixing set is drawn * @return A pair (m,l) where l is the fixing set (a minimum set of constraints which had * to be weakened to satisfy the system), and m is the resulting model after weakening. * Note that <code>l.isEmpty()</code> means the entire set of constraints is satisfiable. * @see SatSolver * @see Theory */ public static <Constraint, Model> Pair<Model, Collection<Constraint>> solve( Theory<Constraint, Model> theorySolver, FixingSetFinder<Constraint> fixingSetFinder, List<Constraint> hardConstraints, List<Constraint> softConstraints) { FixingSetListener<Constraint, Model> listener = NOISY ? loggingListener() : FixingSetListener.dummyListener(); fixingSetFinder.setup(softConstraints); // These two are complements of each other: // - fixingSet is the constraints we are going to remove // - positive is the constraints we are going to keep // (i.e. all those not in the fixing set) Collection<Constraint> fixingSet = new ArrayList<>(); Collection<Constraint> positive = new LinkedHashSet<>(); for (;;) { // Be polite---interruptions mean that someone else wants // this thread to stop what it's doing. if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("thread was interrupted"); } positive.addAll(hardConstraints); positive.addAll(softConstraints); positive.removeAll(fixingSet); // Check the proposed fixing set against the theory. Either<Model, Collection<Constraint>> result = timed(() -> theorySolver.check(positive), "CHECKING THEORY"); if (result.right == null) { // The proposed fixing set works! We are done! if (NOISY) System.out.println("VALID MODEL"); listener.onFixingSet(result.left, fixingSet); return Pair.of(result.left, fixingSet); } else { // The proposed fixing set didn't work. We will use the core // to adjust what fixing set gets returned next. // Inform the listener listener.onCore(result.right); // The fixing set finder shouldn't care about hard constraints Collection<Constraint> softCore = result.right.stream().filter(c -> !hardConstraints.contains(c)) .collect(Collectors.toList()); if (softCore.isEmpty()) { throw new IllegalStateException("Hard clauses are unsat!"); } // Push the core to the fixing set finder fixingSet.clear(); fixingSetFinder.addCore(softCore); timed(() -> fixingSetFinder.currentFixingSet(fixingSet, listener), "FINDING FIXING SET"); System.out.println(" --> PROPOSAL SIZE = " + fixingSet.size()); } } }
From source file:org.springframework.osgi.extender.internal.dependencies.shutdown.ShutdownSorter.java
/** * Sorts the given bundles. The method extracts the bundles about to be destroyed from the given lists and returns * them to the user. Since shutting down a bundle can influence the destruction of the others, this method should be * called after all the returned bundles have been destroyed until the list is empty. * // w ww.j av a2 s. c o m * @param managedBundles * @return */ public static Collection<Bundle> getBundles(Collection<Bundle> managedBundles) { List<Bundle> returned = null; try { // 1. eliminate unused bundles returned = unusedBundles(managedBundles); if (returned.isEmpty()) { // go to step 2, and pick the first bundle based on service properties returned = new ArrayList<Bundle>(1); returned.add(findBundleBasedOnServices(managedBundles)); } return returned; } finally { managedBundles.removeAll(returned); } }
From source file:org.apache.cassandra.tools.SSTableExport.java
/** * Export specific rows from an SSTable and write the resulting JSON to a PrintStream. * /*from w w w. j a va 2 s . c om*/ * @param ssTableFile the SSTableScanner to export the rows from * @param outs PrintStream to write the output to * @param toExport the keys corresponding to the rows to export * @param excludes keys to exclude from export * @throws IOException on failure to read/write input/output */ public static void export(String ssTableFile, PrintStream outs, Collection<String> toExport, String[] excludes) throws IOException { SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(ssTableFile)); SSTableScanner scanner = reader.getDirectScanner(BufferedRandomAccessFile.DEFAULT_BUFFER_SIZE); IPartitioner<?> partitioner = StorageService.getPartitioner(); if (excludes != null) toExport.removeAll(Arrays.asList(excludes)); outs.println("{"); int i = 0; // last key to compare order DecoratedKey lastKey = null; for (String key : toExport) { DecoratedKey decoratedKey = partitioner.decorateKey(hexToBytes(key)); if (lastKey != null && lastKey.compareTo(decoratedKey) > 0) throw new IOException("Key out of order! " + lastKey + " > " + decoratedKey); lastKey = decoratedKey; scanner.seekTo(decoratedKey); if (!scanner.hasNext()) continue; SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next(); if (!row.getKey().equals(decoratedKey)) continue; serializeRow(row, decoratedKey, outs); if (i != 0) outs.println(","); i++; } outs.println("\n}"); outs.flush(); scanner.close(); }
From source file:com.adito.vfs.VFSLockManager.java
@SuppressWarnings("unchecked") private static boolean areSessionsActive(Lock lock) { Collection<SessionInfo> lockOwners = lock.getLockOwners(); if (lockOwners.isEmpty()) return false; LogonController logonController = LogonControllerFactory.getInstance(); Collection<SessionInfo> sessions = logonController.getActiveSessions().values(); int lockOwnerCount = lockOwners.size(); lockOwners.removeAll(sessions); return lockOwners.isEmpty() || (lockOwners.size() != lockOwnerCount); }
From source file:com.screenslicer.core.util.BrowserUtil.java
public static String newWindow(Browser browser, boolean cleanupWindows) throws ActionFailed { try {/*w w w . j a v a 2 s . c o m*/ handleNewWindows(browser, browser.getWindowHandle(), cleanupWindows); Set<String> origHandles = new HashSet<String>(browser.getWindowHandles()); try { browser.getKeyboard().sendKeys(Keys.chord(Keys.CONTROL + "n")); } catch (Browser.Retry r) { throw r; } catch (Browser.Fatal f) { throw f; } catch (Throwable t) { Log.exception(t); } Collection<String> handles = new HashSet<String>(browser.getWindowHandles()); handles.removeAll(origHandles); if (!handles.isEmpty()) { browser.switchTo().window(handles.iterator().next()); } else { browser.executeScript("window.open('');"); handles = new HashSet<String>(browser.getWindowHandles()); handles.removeAll(origHandles); if (!handles.isEmpty()) { browser.switchTo().window(handles.iterator().next()); } } return browser.getWindowHandle(); } catch (Browser.Retry r) { throw r; } catch (Browser.Fatal f) { throw f; } catch (Throwable t) { throw new ActionFailed(t); } }
From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ShutdownSorter.java
/** * Sorts the given bundles. The method extracts the bundles about to be destroyed from the given lists and returns * them to the user. Since shutting down a bundle can influence the destruction of the others, this method should be * called after all the returned bundles have been destroyed until the list is empty. * // w w w.jav a 2 s . c o m * @param managedBundles * @return sorted collection of Bundles */ public static Collection<Bundle> getBundles(Collection<Bundle> managedBundles) { List<Bundle> returned = null; try { // 1. eliminate unused bundles returned = unusedBundles(managedBundles); if (returned.isEmpty()) { // go to step 2, and pick the first bundle based on service properties returned = new ArrayList<Bundle>(1); returned.add(findBundleBasedOnServices(managedBundles)); } return returned; } finally { if (returned != null) { managedBundles.removeAll(returned); } } }
From source file:org.eclipse.sw360.datahandler.common.CommonUtils.java
public static <T> void removeAll(Collection<T> left, Collection<T> right) { if (left != null && right != null) { left.removeAll(right); }/*from ww w .j a v a2 s. c o m*/ }
From source file:edu.ksu.cis.indus.tools.slicer.SlicerToolHelper.java
/** * Optimizes the slice calculated by the given tool for space. This method should be called after residualization. * //w w w .j a va2 s. c o m * @param tool in which the slice should be optimized. * @param classesToRetain is the collection of FQN of classes that need to be retained in the slice. * @return the unspecified classes that were retained. * @pre tool != null and classesToRetain != null * @post result != null */ public static Collection<SootClass> optimizeForSpaceAfterResidualization(final SlicerTool<?> tool, final Collection<String> classesToRetain) { final Collection<SootClass> _classesToErase = new HashSet<SootClass>(); final Collection<SootClass> _classes = tool.getSystem().getClasses(); final Iterator<SootClass> _i = _classes.iterator(); final int _iEnd = _classes.size(); for (int _iIndex = 0; _iIndex < _iEnd; _iIndex++) { final SootClass _sc = _i.next(); if (_sc.getMethods().size() == 0 && _sc.getFields().size() == 0 && !classesToRetain.contains(_sc.getName())) { _classesToErase.add(_sc); } } final Collection<SootClass> _c = Util.eraseClassesFrom(_classesToErase, tool.getSystem()); _classesToErase.removeAll(_c); return _c; }