Java Code Examples for java.util.LinkedHashSet#removeAll()
The following examples show how to use
java.util.LinkedHashSet#removeAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CofactorRemover.java From act with GNU General Public License v3.0 | 6 votes |
/** * The function removes similar chemicals from the substrates and products (conenzymes) and remove duplicates * within each category. * @param reaction The reaction being updated. */ private void findAndIsolateCoenzymesFromReaction(Reaction reaction) { // Build ordered sets of the substrates/products. LinkedHashSet<Long> substrates = new LinkedHashSet<>(Arrays.asList(reaction.getSubstrates())); LinkedHashSet<Long> products = new LinkedHashSet<>(Arrays.asList(reaction.getProducts())); // Compute the intersection between the sets. Set<Long> intersection = new HashSet<>(substrates); intersection.retainAll(products); // A - int(A, B) = A / B substrates.removeAll(intersection); products.removeAll(intersection); // Update the reaction with the new (ordered) substrates/products + coenzymes. reaction.setSubstrates(substrates.toArray(new Long[substrates.size()])); reaction.setProducts(products.toArray(new Long[products.size()])); // Keep any existing coenzymes, but don't use them when computing the difference--they might be there for a reason. intersection.addAll(Arrays.asList(reaction.getCoenzymes())); reaction.setCoenzymes(intersection.toArray(new Long[intersection.size()])); }
Example 2
Source File: RepoMerger.java From git-merge-repos with Apache License 2.0 | 5 votes |
private MergedRef getMergedRef(String refType, String refName, Set<SubtreeConfig> configsWithRef) { LinkedHashSet<SubtreeConfig> configsWithoutRef = new LinkedHashSet<>( subtreeConfigs); configsWithoutRef.removeAll(configsWithRef); return new MergedRef(refType, refName, configsWithRef, configsWithoutRef); }
Example 3
Source File: TransactionalContinuousResourceSubStore.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean unregister(DiscreteResourceId parent, Set<ContinuousResource> resources) { // short-circuit: receiving empty resource is regarded as success if (resources.isEmpty()) { return true; } // even if one of the resources is allocated to a consumer, // all unregistrations are regarded as failure boolean allocated = resources.stream().anyMatch(x -> isAllocated(x.id())); if (allocated) { log.warn("Failed to unregister {}: allocation exists", parent); return false; } Set<ContinuousResource> oldValues = childMap.putIfAbsent(parent, new LinkedHashSet<>()); if (oldValues == null) { log.trace("No-Op removing values. key {} did not exist", parent); return true; } if (resources.stream().allMatch(x -> !oldValues.contains(x))) { // don't write map because none of the values are stored log.trace("No-Op removing values. key {} did not contain {}", parent, resources); return true; } LinkedHashSet<ContinuousResource> newValues = new LinkedHashSet<>(oldValues); newValues.removeAll(resources); return childMap.replace(parent, oldValues, newValues); }
Example 4
Source File: DNS.java From hadoop with Apache License 2.0 | 5 votes |
/** * Returns all the IPs associated with the provided interface, if any, in * textual form. * * @param strInterface * The name of the network interface or sub-interface to query * (eg eth0 or eth0:0) or the string "default" * @param returnSubinterfaces * Whether to return IPs associated with subinterfaces of * the given interface * @return A string vector of all the IPs associated with the provided * interface. The local host IP is returned if the interface * name "default" is specified or there is an I/O error looking * for the given interface. * @throws UnknownHostException * If the given interface is invalid * */ public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException { if ("default".equals(strInterface)) { return new String[] { cachedHostAddress }; } NetworkInterface netIf; try { netIf = NetworkInterface.getByName(strInterface); if (netIf == null) { netIf = getSubinterface(strInterface); } } catch (SocketException e) { LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage()); return new String[] { cachedHostAddress }; } if (netIf == null) { throw new UnknownHostException("No such interface " + strInterface); } // NB: Using a LinkedHashSet to preserve the order for callers // that depend on a particular element being 1st in the array. // For example, getDefaultIP always returns the first element. LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>(); allAddrs.addAll(Collections.list(netIf.getInetAddresses())); if (!returnSubinterfaces) { allAddrs.removeAll(getSubinterfaceInetAddrs(netIf)); } String ips[] = new String[allAddrs.size()]; int i = 0; for (InetAddress addr : allAddrs) { ips[i++] = addr.getHostAddress(); } return ips; }
Example 5
Source File: DNS.java From big-c with Apache License 2.0 | 5 votes |
/** * Returns all the IPs associated with the provided interface, if any, in * textual form. * * @param strInterface * The name of the network interface or sub-interface to query * (eg eth0 or eth0:0) or the string "default" * @param returnSubinterfaces * Whether to return IPs associated with subinterfaces of * the given interface * @return A string vector of all the IPs associated with the provided * interface. The local host IP is returned if the interface * name "default" is specified or there is an I/O error looking * for the given interface. * @throws UnknownHostException * If the given interface is invalid * */ public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException { if ("default".equals(strInterface)) { return new String[] { cachedHostAddress }; } NetworkInterface netIf; try { netIf = NetworkInterface.getByName(strInterface); if (netIf == null) { netIf = getSubinterface(strInterface); } } catch (SocketException e) { LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage()); return new String[] { cachedHostAddress }; } if (netIf == null) { throw new UnknownHostException("No such interface " + strInterface); } // NB: Using a LinkedHashSet to preserve the order for callers // that depend on a particular element being 1st in the array. // For example, getDefaultIP always returns the first element. LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>(); allAddrs.addAll(Collections.list(netIf.getInetAddresses())); if (!returnSubinterfaces) { allAddrs.removeAll(getSubinterfaceInetAddrs(netIf)); } String ips[] = new String[allAddrs.size()]; int i = 0; for (InetAddress addr : allAddrs) { ips[i++] = addr.getHostAddress(); } return ips; }
Example 6
Source File: TaskUpdateImports.java From flow with Apache License 2.0 | 5 votes |
@Override protected Set<CssData> getCss() { LinkedHashSet<CssData> set = new LinkedHashSet<>( fallbackScanner.getCss()); set.removeAll(frontDeps.getCss()); return set; }
Example 7
Source File: CTraceCombinationFunctions.java From binnavi with Apache License 2.0 | 5 votes |
/** * Calculates the event addresses that appear exclusively in the first trace. * * @param trace1 The first input trace. * @param trace2 The second input trace. * * @return The addresses of those events that appear exlusively in the first input trace. */ private static Set<BreakpointAddress> getDifferenceAddresses( final TraceList trace1, final TraceList trace2) { final List<TraceList> traces = Lists.newArrayList(trace1, trace2); final List<Collection<BreakpointAddress>> traceAddresses = getTraceAddresses(traces); final LinkedHashSet<BreakpointAddress> addresses = new LinkedHashSet<BreakpointAddress>(traceAddresses.get(0)); addresses.removeAll(traceAddresses.get(1)); return addresses; }
Example 8
Source File: TaskUpdateImports.java From flow with Apache License 2.0 | 5 votes |
@Override protected List<String> getModules() { LinkedHashSet<String> set = new LinkedHashSet<>( fallbackScanner.getModules()); set.removeAll(frontDeps.getModules()); return new ArrayList<String>(set); }
Example 9
Source File: TaskUpdateImports.java From flow with Apache License 2.0 | 5 votes |
@Override protected Set<String> getScripts() { LinkedHashSet<String> set = new LinkedHashSet<>( fallbackScanner.getScripts()); set.removeAll(frontDeps.getScripts()); return set; }
Example 10
Source File: LatticeSuggester.java From Bats with Apache License 2.0 | 4 votes |
private static <E> Set<E> minus(Collection<E> c, Collection<E> c2) { final LinkedHashSet<E> c3 = new LinkedHashSet<>(c); c3.removeAll(c2); return c3; }
Example 11
Source File: LatticeSuggester.java From calcite with Apache License 2.0 | 4 votes |
private static <E> Set<E> minus(Collection<E> c, Collection<E> c2) { final LinkedHashSet<E> c3 = new LinkedHashSet<>(c); c3.removeAll(c2); return c3; }
Example 12
Source File: TemporalMemoryMonitorMixin.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
/** * Computes the transition traces, if necessary. * * Transition traces are the following: * * predicted => active cells * predicted => inactive cells * predicted => active columns * predicted => inactive columns * unpredicted => active columns */ @SuppressWarnings("unchecked") default void mmComputeTransitionTraces() { if(!transitionTracesStale()) { return; } Map<String, Set<Integer>> predActCells = null; if((predActCells = (Map<String, Set<Integer>>)getDataMap() .get("predictedActiveCellsForSequence")) == null) { getDataMap().put("predictedActiveCellsForSequence", predActCells = new HashMap<String, Set<Integer>>()); } getTraceMap().put("predictedActiveCells", new IndicesTrace(this, "predicted => active cells (correct)")); getTraceMap().put("predictedInactiveCells", new IndicesTrace(this, "predicted => inactive cells (extra)")); getTraceMap().put("predictedActiveColumns", new IndicesTrace(this, "predicted => active columns (correct)")); getTraceMap().put("predictedInactiveColumns", new IndicesTrace(this, "predicted => inactive columns (extra)")); getTraceMap().put("unpredictedActiveColumns", new IndicesTrace(this, "unpredicted => active columns (bursting)")); IndicesTrace predictedCellsTrace = (IndicesTrace)getTraceMap().get("predictedCells"); int i = 0;LinkedHashSet<Integer> predictedActiveColumns = null; for(Set<Integer> activeColumns : mmGetTraceActiveColumns().items) { LinkedHashSet<Integer> predictedActiveCells = new LinkedHashSet<>(); LinkedHashSet<Integer> predictedInactiveCells = new LinkedHashSet<>(); predictedActiveColumns = new LinkedHashSet<>(); LinkedHashSet<Integer> predictedInactiveColumns = new LinkedHashSet<>(); for(Integer predictedCell : predictedCellsTrace.items.get(i)) { Integer predictedColumn = getConnections().getCell(predictedCell).getColumn().getIndex(); if(activeColumns.contains(predictedColumn)) { predictedActiveCells.add(predictedCell); predictedActiveColumns.add(predictedColumn); String sequenceLabel = (String)mmGetTraceSequenceLabels().items.get(i); if(sequenceLabel != null && !sequenceLabel.isEmpty()) { Set<Integer> sequencePredictedCells = null; if((sequencePredictedCells = (Set<Integer>)predActCells.get(sequenceLabel)) == null) { ((Map<String, Set<Integer>>)predActCells).put( sequenceLabel, sequencePredictedCells = new LinkedHashSet<Integer>()); } sequencePredictedCells.add(predictedCell); } }else{ predictedInactiveCells.add(predictedCell); predictedInactiveColumns.add(predictedColumn); } } LinkedHashSet<Integer> unpredictedActiveColumns = new LinkedHashSet<>(activeColumns); unpredictedActiveColumns.removeAll(predictedActiveColumns); ((IndicesTrace)getTraceMap().get("predictedActiveCells")).items.add(predictedActiveCells); ((IndicesTrace)getTraceMap().get("predictedInactiveCells")).items.add(predictedInactiveCells); ((IndicesTrace)getTraceMap().get("predictedActiveColumns")).items.add(predictedActiveColumns); ((IndicesTrace)getTraceMap().get("predictedInactiveColumns")).items.add(predictedInactiveColumns); ((IndicesTrace)getTraceMap().get("unpredictedActiveColumns")).items.add(unpredictedActiveColumns); i++; } setTransitionTracesStale(false); }
Example 13
Source File: LatticeSuggester.java From Quicksql with MIT License | 4 votes |
private static <E> Set<E> minus(Collection<E> c, Collection<E> c2) { final LinkedHashSet<E> c3 = new LinkedHashSet<>(c); c3.removeAll(c2); return c3; }
Example 14
Source File: LambdaCaptureDesugaringRewriter.java From presto with Apache License 2.0 | 4 votes |
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Context context, ExpressionTreeRewriter<Context> treeRewriter) { // Use linked hash set to guarantee deterministic iteration order LinkedHashSet<Symbol> referencedSymbols = new LinkedHashSet<>(); Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), context.withReferencedSymbols(referencedSymbols)); List<Symbol> lambdaArguments = node.getArguments().stream() .map(LambdaArgumentDeclaration::getName) .map(Identifier::getValue) .map(Symbol::new) .collect(toImmutableList()); // referenced symbols - lambda arguments = capture symbols // referencedSymbols no longer contains what its name suggests after this line referencedSymbols.removeAll(lambdaArguments); Set<Symbol> captureSymbols = referencedSymbols; // x -> f(x, captureSymbol) will be rewritten into // "$internal$bind"(captureSymbol, (extraSymbol, x) -> f(x, extraSymbol)) ImmutableMap.Builder<Symbol, Symbol> captureSymbolToExtraSymbol = ImmutableMap.builder(); ImmutableList.Builder<LambdaArgumentDeclaration> newLambdaArguments = ImmutableList.builder(); for (Symbol captureSymbol : captureSymbols) { Symbol extraSymbol = symbolAllocator.newSymbol(captureSymbol.getName(), symbolTypes.get(captureSymbol)); captureSymbolToExtraSymbol.put(captureSymbol, extraSymbol); newLambdaArguments.add(new LambdaArgumentDeclaration(new Identifier(extraSymbol.getName()))); } newLambdaArguments.addAll(node.getArguments()); ImmutableMap<Symbol, Symbol> symbolsMap = captureSymbolToExtraSymbol.build(); Function<Symbol, Expression> symbolMapping = symbol -> symbolsMap.getOrDefault(symbol, symbol).toSymbolReference(); Expression rewrittenExpression = new LambdaExpression(newLambdaArguments.build(), inlineSymbols(symbolMapping, rewrittenBody)); if (captureSymbols.size() != 0) { List<Expression> capturedValues = captureSymbols.stream() .map(symbol -> new SymbolReference(symbol.getName())) .collect(toImmutableList()); rewrittenExpression = new BindExpression(capturedValues, rewrittenExpression); } context.getReferencedSymbols().addAll(captureSymbols); return rewrittenExpression; }
Example 15
Source File: OpenSSLCipherConfigurationParser.java From Tomcat8-Source-Read with MIT License | 4 votes |
static void moveToEnd(final LinkedHashSet<Cipher> ciphers, final Collection<Cipher> toBeMovedCiphers) { List<Cipher> movedCiphers = new ArrayList<>(toBeMovedCiphers); movedCiphers.retainAll(ciphers); ciphers.removeAll(movedCiphers); ciphers.addAll(movedCiphers); }
Example 16
Source File: Tree.java From cuba with Apache License 2.0 | 2 votes |
/** * A {@link Set} of all the items that became deselected. * * <em>Note:</em> this excludes all items that might have been previously * deselected. * * @return a set of the items that became deselected */ public Set<E> getRemoved() { LinkedHashSet<E> copy = new LinkedHashSet<>(getOldSelection()); copy.removeAll(getSelected()); return copy; }
Example 17
Source File: Tree.java From cuba with Apache License 2.0 | 2 votes |
/** * A {@link Set} of all the items that became selected. * * <em>Note:</em> this excludes all items that might have been previously * selected. * * @return a set of the items that became selected */ public Set<E> getAdded() { LinkedHashSet<E> copy = new LinkedHashSet<>(getSelected()); copy.removeAll(getOldSelection()); return copy; }