List of usage examples for com.google.common.collect SetMultimap containsKey
boolean containsKey(@Nullable Object key);
From source file:edu.harvard.med.screensaver.model.libraries.Library.java
@Transient public SortedSet<LibraryPlate> getLibraryPlates() { SetMultimap<Integer, AssayPlate> index = HashMultimap.create(); for (Copy copy : getCopies()) { for (Map.Entry<Integer, Plate> entry : copy.getPlates().entrySet()) { index.putAll(entry.getKey(), entry.getValue().getAssayPlates()); }/*from ww w . j a v a 2s . c o m*/ } SortedSet<LibraryPlate> libraryPlates = Sets.newTreeSet(); Set<AssayPlate> assayPlates; for (int p = getStartPlate(); p <= getEndPlate(); ++p) { if (index.containsKey(p)) { assayPlates = index.get(p); } else { assayPlates = Collections.emptySet(); } libraryPlates.add(new LibraryPlate(p, this, assayPlates)); } return libraryPlates; }
From source file:exm.stc.ic.opt.WaitCoalescer.java
public boolean tryPushdownClosedVar(Logger logger, Block top, ExecContext topContext, StackLite<Continuation> ancestors, Block curr, ExecContext currContext, SetMultimap<Var, InstOrCont> waitMap, ArrayList<Continuation> pushedDown, ListIterator<Statement> it, Var v) {/*w w w . ja va2 s. co m*/ boolean changed = false; if (waitMap.containsKey(v)) { Pair<Boolean, Set<Continuation>> pdRes = relocateDependentInstructions(logger, top, topContext, ancestors, curr, currContext, it, waitMap, v); changed = pdRes.val1; pushedDown.addAll(pdRes.val2); } return changed; }
From source file:org.sosy_lab.cpachecker.cpa.predicate.PredicateCPAGlobalRefiner.java
/** * Do refinement for a set of target states. * * The strategy is to first build the predecessor/successor relations for all * abstraction states on the paths to the target states, and then call * {@link #performRefinementOnPath(List, ARGState, List, ARGReachedSet, InterpolatingProverEnvironment)} * on the root state of the ARG./*from w ww. ja va 2s . co m*/ */ private Optional<ARGState> doPathWiseRefinement(ARGReachedSet pReached, List<AbstractState> targets) throws CPAException, InterruptedException, SolverException { logger.log(Level.FINE, "Starting refinement for", targets.size(), "elements."); Map<ARGState, ARGState> predecessors = Maps.newHashMap(); SetMultimap<ARGState, ARGState> successors = HashMultimap.create(); Deque<AbstractState> todo = new ArrayDeque<>(targets); while (!todo.isEmpty()) { final ARGState currentAbstractionState = (ARGState) todo.removeFirst(); assert currentAbstractionState.mayCover(); ARGState currentState = currentAbstractionState; do { currentState = currentState.getParents().iterator().next(); } while (!getPredicateState(currentState).isAbstractionState()); if (!currentState.getParents().isEmpty() && !predecessors.containsKey(currentState)) { todo.add(currentState); } predecessors.put(currentAbstractionState, currentState); successors.put(currentState, currentAbstractionState); } final ARGState root = (ARGState) pReached.asReachedSet().getFirstState(); assert successors.containsKey(root); // Now predecessors/successors contains all abstraction states on all error // paths and their relations. // These states and the relation form a tree. // We now iterate through this tree in a depth-first order. // For each state, we check reachability. // We do not descend beyond unreachable states, // but instead perform refinement on them. try (InterpolatingProverEnvironment<?> itpProver = solver.newProverEnvironmentWithInterpolation()) { return doPathWiseRefinement(root, successors, predecessors, pReached, targets, itpProver); } }
From source file:org.sosy_lab.cpachecker.cpa.predicate.ImpactGlobalRefiner.java
/** * Do refinement for a set of target states. * * The strategy is to first build the predecessor/successor relations for all * abstraction states on the paths to the target states, and then call * {@link #performRefinementOnSubgraph(ARGState, List, SetMultimap, Map, ReachedSet, List)} * on the root state of the ARG./* w w w .j a v a 2 s. c o m*/ */ private boolean performRefinement0(ReachedSet pReached, List<AbstractState> targets) throws CPAException, InterruptedException { logger.log(Level.FINE, "Starting refinement for", targets.size(), "elements."); Map<ARGState, ARGState> predecessors = Maps.newHashMap(); SetMultimap<ARGState, ARGState> successors = HashMultimap.create(); Deque<AbstractState> todo = new ArrayDeque<>(targets); while (!todo.isEmpty()) { final ARGState currentAbstractionState = (ARGState) todo.removeFirst(); assert currentAbstractionState.mayCover(); ARGState currentState = currentAbstractionState; do { currentState = currentState.getParents().iterator().next(); } while (!getPredicateState(currentState).isAbstractionState()); if (!currentState.getParents().isEmpty() && !predecessors.containsKey(currentState)) { todo.add(currentState); } predecessors.put(currentAbstractionState, currentState); successors.put(currentState, currentAbstractionState); } final ARGState root = (ARGState) pReached.getFirstState(); assert successors.containsKey(root); // Now predecessors/successors contains all abstraction states on all error // paths and their relations. // These states and the relation form a tree. // We now iterate through this tree in a depth-first order. // For each state, we check reachability. // We do not descend beyond unreachable states, // but instead perform refinement on them. try (InterpolatingProverEnvironment<?> itpProver = solver.newProverEnvironmentWithInterpolation()) { return performRefinement0(root, successors, predecessors, pReached, targets, itpProver); } }
From source file:edu.buaa.satla.analysis.core.predicate.ImpactGlobalRefiner.java
/** * Do refinement for a set of target states. * * The strategy is to first build the predecessor/successor relations for all * abstraction states on the paths to the target states, and then call * {@link #performRefinementOnSubgraph(ARGState, List, SetMultimap, Map, ReachedSet, List)} * on the root state of the ARG./* w w w. jav a 2 s . co m*/ */ private boolean performRefinement0(ReachedSet pReached, List<AbstractState> targets) throws CPAException, InterruptedException { logger.log(Level.FINE, "Starting refinement for", targets.size(), "elements."); Map<ARGState, ARGState> predecessors = Maps.newHashMap(); SetMultimap<ARGState, ARGState> successors = HashMultimap.create(); Deque<AbstractState> todo = new ArrayDeque<>(targets); while (!todo.isEmpty()) { final ARGState currentAbstractionState = (ARGState) todo.removeFirst(); assert currentAbstractionState.mayCover(); ARGState currentState = currentAbstractionState; do { currentState = currentState.getParents().iterator().next(); } while (!getPredicateState(currentState).isAbstractionState()); if (!currentState.getParents().isEmpty() && !predecessors.containsKey(currentState)) { todo.add(currentState); } predecessors.put(currentAbstractionState, currentState); successors.put(currentState, currentAbstractionState); } final ARGState root = (ARGState) pReached.getFirstState(); assert successors.containsKey(root); // Now predecessors/successors contains all abstraction states on all error // paths and their relations. // These states and the relation form a tree. // We now iterate through this tree in a depth-first order. // For each state, we check reachability. // We do not descend beyond unreachable states, // but instead perform refinement on them. try (InterpolatingProverEnvironment<?> itpProver = factory.newProverEnvironmentWithInterpolation(false)) { return performRefinement0(root, successors, predecessors, pReached, targets, itpProver); } }
From source file:org.sosy_lab.cpachecker.cpa.predicate.PredicateCPAGlobalRefiner.java
/** * Recursively perform refinement on the subgraph of the ARG starting with a given state. * Each recursion step corresponds to one "block" of the ARG. As one block * may have several successors, this is recursion on a tree. * We proceed in a DFS order.//from w w w .j a va 2s. c om * Recursion stops as soon as the path has been determined to be infeasible * (so we do refinement as soon as possible) or a target state is reached * (then we found a feasible counterexample). * When an infeasible state was found, we call * {@link #performRefinementOnPath(List, ARGState, List, ARGReachedSet, InterpolatingProverEnvironment)} * to do the actual refinement. * * Note that the successor and predecessor relation contains only states * that belong to paths to a target state, so we refine only such paths, * and not all paths in the ARG. * * @param currentPath The list of ARG states from the root to the current element. * @param itpStack The stack of interpolation groups added to the solver environment so far. * @param successors The successor relation between abstraction states. * @param predecessors The predecessor relation between abstraction states. * @param pReached The complete reached set. * @param targets The set of target states. * @return The feasible error location or absent */ private <T> Optional<ARGState> step(final LinkedList<ARGState> currentPath, final List<T> itpStack, final SetMultimap<ARGState, ARGState> successors, final Map<ARGState, ARGState> predecessors, final ARGReachedSet pReached, final List<AbstractState> targets, InterpolatingProverEnvironment<T> itpProver) throws InterruptedException, SolverException, CPAException { for (final ARGState succ : successors.get(currentPath.getLast())) { assert succ.getChildren().isEmpty() == targets.contains(succ); assert succ.mayCover(); BooleanFormula blockFormula = getPredicateState(succ).getAbstractionFormula().getBlockFormula() .getFormula(); itpStack.add(itpProver.push(blockFormula)); currentPath.add(succ); try { satCheckTime.start(); boolean isUnsat = itpProver.isUnsat(); satCheckTime.stop(); if (isUnsat) { logger.log(Level.FINE, "Found unreachable state", succ); List<ARGState> abstractionStatesTrace = new ArrayList<>(currentPath); ARGState cur = succ; while (successors.containsKey(cur)) { // we just always use the first child, as every interpolant // below the unreacheable state will be false anyway we don't need // to have all paths to all reachable error states ARGState tmp = successors.get(cur).iterator().next(); abstractionStatesTrace.add(tmp); cur = tmp; } assert cur.isTarget() : "Last state in path has to be a target state"; performRefinementOnPath(unmodifiableList(itpStack), succ, abstractionStatesTrace, pReached, itpProver); } else if (targets.contains(succ)) { // We have found a reachable target state, immediately abort refinement. logger.log(Level.FINE, "Found reachable target state", succ); return Optional.of(succ); } else { // Not yet infeasible, but path is longer, // so descend recursively. Optional<ARGState> tmp = step(currentPath, itpStack, successors, predecessors, pReached, targets, itpProver); if (tmp.isPresent()) { return tmp; } } } finally { itpStack.remove(itpStack.size() - 1); itpProver.pop(); currentPath.remove(currentPath.size() - 1); } } return Optional.empty(); }
From source file:com.b2international.snowowl.snomed.core.tree.TreeBuilderImpl.java
@Override public TerminologyTree build(final String branch, final Iterable<SnomedConceptDocument> nodes) { final Collection<SnomedConceptDocument> topLevelConcepts = this.topLevelConcepts == null ? getDefaultTopLevelConcepts(branch) : this.topLevelConcepts; final Map<String, SnomedConceptDocument> treeItemsById = newHashMap(); // all matching concepts should be in the componentMap treeItemsById.putAll(FluentIterable.from(nodes).uniqueIndex(ComponentUtils.<String>getIdFunction())); final Collection<String> requiredTopLevelConceptIds = ComponentUtils.getIdSet(topLevelConcepts); // compute subType and superType maps for the tree final SetMultimap<String, String> superTypeMap = HashMultimap.create(); final SetMultimap<String, String> subTypeMap = HashMultimap.create(); for (SnomedConceptDocument entry : nodes) { final LongCollection parentIds = getParents(entry); final LongCollection ancestorIds = getAncestors(entry); if (parentIds != null) { final Collection<String> parents = LongSets.toStringSet(parentIds); final Collection<String> selectedParents = newHashSet(); // if the parent is not a match or TOP level for (String parent : parents) { if (treeItemsById.containsKey(parent) || requiredTopLevelConceptIds.contains(parent)) { selectedParents.add(parent); }//from ww w . j av a 2s . c om } if (selectedParents.isEmpty()) { findParentInAncestors(entry, treeItemsById, requiredTopLevelConceptIds, subTypeMap, superTypeMap); } else { for (String parent : selectedParents) { subTypeMap.put(parent, entry.getId()); superTypeMap.put(entry.getId(), parent); } } } else if (ancestorIds != null) { findParentInAncestors(entry, treeItemsById, requiredTopLevelConceptIds, subTypeMap, superTypeMap); } else { // no parents or ancestors, root element subTypeMap.put(null, entry.getId()); } } // add TOP levels for (SnomedConceptDocument entry : topLevelConcepts) { if (!Concepts.ROOT_CONCEPT.equals(entry.getId()) && !treeItemsById.containsKey(entry.getId())) { if (subTypeMap.containsKey(entry.getId())) { treeItemsById.put(entry.getId(), entry); } } } for (SnomedConceptDocument entry : topLevelConcepts) { if (Concepts.ROOT_CONCEPT.equals(entry.getId())) { // find all top level child and connect them with the root for (SnomedConceptDocument tl : topLevelConcepts) { if (!Concepts.ROOT_CONCEPT.equals(tl.getId()) && treeItemsById.containsKey(tl.getId())) { subTypeMap.put(entry.getId(), tl.getId()); superTypeMap.put(tl.getId(), entry.getId()); } } // only add root concept if the tree contains top level concepts if (subTypeMap.containsKey(Concepts.ROOT_CONCEPT)) { treeItemsById.put(entry.getId(), entry); subTypeMap.put(null, entry.getId()); } break; } } // fetch all missing components to build the remaining part of the FULL tree final Set<String> allRequiredComponents = newHashSet(); allRequiredComponents.addAll(superTypeMap.keySet()); allRequiredComponents.addAll(subTypeMap.keySet()); allRequiredComponents.removeAll(treeItemsById.keySet()); allRequiredComponents.remove(null); // fetch required data for all unknown items for (SnomedConceptDocument entry : getComponents(branch, allRequiredComponents)) { treeItemsById.put(entry.getId(), entry); } return new TerminologyTree(treeItemsById, subTypeMap, superTypeMap); }
From source file:org.jakstab.ProgramGraphWriter.java
public void writeDisassembly(Program program, String filename) { logger.info("Writing assembly file to " + filename); SetMultimap<AbsoluteAddress, CFAEdge> branchEdges = HashMultimap.create(); SetMultimap<AbsoluteAddress, CFAEdge> branchEdgesRev = HashMultimap.create(); if (!Options.noGraphs.getValue()) { for (CFAEdge e : program.getCFA()) { AbsoluteAddress sourceAddr = e.getSource().getAddress(); AbsoluteAddress targetAddr = e.getTarget().getAddress(); if (program.getInstruction(sourceAddr) instanceof BranchInstruction && !sourceAddr.equals(targetAddr)) { branchEdges.put(sourceAddr, e); branchEdgesRev.put(targetAddr, e); }/*from w ww .j a v a2s. c o m*/ } } try { FileWriter out = new FileWriter(filename); for (Map.Entry<AbsoluteAddress, Instruction> entry : program.getAssemblyMap().entrySet()) { AbsoluteAddress pc = entry.getKey(); Instruction instr = entry.getValue(); StringBuilder sb = new StringBuilder(); SymbolFinder symFinder = program.getModule(pc).getSymbolFinder(); if (symFinder.hasSymbolFor(pc)) { sb.append(Characters.NEWLINE); sb.append(symFinder.getSymbolFor(pc)); sb.append(":").append(Characters.NEWLINE); } sb.append(pc).append(":\t"); sb.append(instr.toString(pc.getValue(), symFinder)); if (instr instanceof BranchInstruction) { Set<CFAEdge> targets = branchEdges.get(pc); sb.append("\t; targets: "); if (targets.isEmpty()) { sb.append("unresolved"); } else { boolean first = true; for (CFAEdge e : targets) { if (first) first = false; else sb.append(", "); sb.append(e.getTarget().getAddress()); sb.append('(').append(e.getKind()).append(')'); } } } if (branchEdgesRev.containsKey(pc)) { Set<CFAEdge> referers = branchEdgesRev.get(pc); sb.append("\t; from: "); boolean first = true; for (CFAEdge e : referers) { if (first) first = false; else sb.append(", "); sb.append(e.getSource().getAddress()); sb.append('(').append(e.getKind()).append(')'); } } sb.append(Characters.NEWLINE); if (instr instanceof ReturnInstruction) sb.append(Characters.NEWLINE); out.write(sb.toString()); } out.close(); } catch (IOException e) { logger.fatal(e); return; } }
From source file:de.bund.bfr.knime.openkrise.MyKrisenInterfacesNodeModel.java
private BufferedDataTable getStationTable(Connection conn, Map<Integer, String> stationIds, Collection<Delivery> deliveries, ExecutionContext exec, boolean useSerialAsId) throws CanceledExecutionException { SetMultimap<String, String> deliversTo = LinkedHashMultimap.create(); SetMultimap<String, String> receivesFrom = LinkedHashMultimap.create(); for (Delivery d : deliveries) { deliversTo.put(d.getSupplierId(), d.getRecipientId()); receivesFrom.put(d.getRecipientId(), d.getSupplierId()); }/*from w ww . j a v a2 s. co m*/ DataTableSpec spec = getStationSpec(conn, useSerialAsId); BufferedDataContainer container = exec.createDataContainer(spec); long index = 0; SelectJoinStep<Record> select = DSL.using(conn, SQLDialect.HSQLDB).select().from(STATION); if (set.isLotBased()) { select = select.join(PRODUKTKATALOG).on(STATION.ID.equal(PRODUKTKATALOG.STATION)).join(CHARGEN) .on(PRODUKTKATALOG.ID.equal(CHARGEN.ARTIKEL)); } for (Record r : select) { String stationId = stationIds.get(r.getValue(STATION.ID)); String district = clean(r.getValue(STATION.DISTRICT)); String state = clean(r.getValue(STATION.BUNDESLAND)); String country = clean(r.getValue(STATION.LAND)); String zip = clean(r.getValue(STATION.PLZ)); String company = r.getValue(STATION.NAME) == null || set.isAnonymize() ? getISO3166_2(country, state) + "#" + r.getValue(STATION.ID) : clean(r.getValue(STATION.NAME)); DataCell[] cells = new DataCell[spec.getNumColumns()]; fillCell(spec, cells, TracingColumns.ID, !set.isLotBased() ? createCell(stationId) : createCell(String.valueOf(r.getValue(CHARGEN.ID)))); fillCell(spec, cells, TracingColumns.STATION_ID, createCell(stationId)); fillCell(spec, cells, BackwardUtils.STATION_NODE, createCell(company)); fillCell(spec, cells, TracingColumns.NAME, !set.isLotBased() ? createCell(company) : createCell(r.getValue(PRODUKTKATALOG.BEZEICHNUNG))); fillCell(spec, cells, TracingColumns.STATION_NAME, createCell(company)); fillCell(spec, cells, TracingColumns.STATION_STREET, set.isAnonymize() ? DataType.getMissingCell() : createCell(r.getValue(STATION.STRASSE))); fillCell(spec, cells, TracingColumns.STATION_HOUSENO, set.isAnonymize() ? DataType.getMissingCell() : createCell(r.getValue(STATION.HAUSNUMMER))); fillCell(spec, cells, TracingColumns.STATION_ZIP, createCell(zip)); fillCell(spec, cells, TracingColumns.STATION_CITY, set.isAnonymize() ? DataType.getMissingCell() : createCell(r.getValue(STATION.ORT))); fillCell(spec, cells, TracingColumns.STATION_DISTRICT, set.isAnonymize() ? DataType.getMissingCell() : createCell(district)); fillCell(spec, cells, TracingColumns.STATION_STATE, set.isAnonymize() ? DataType.getMissingCell() : createCell(state)); fillCell(spec, cells, TracingColumns.STATION_COUNTRY, set.isAnonymize() ? DataType.getMissingCell() : createCell(country)); fillCell(spec, cells, BackwardUtils.STATION_VAT, set.isAnonymize() ? DataType.getMissingCell() : createCell(r.getValue(STATION.VATNUMBER))); fillCell(spec, cells, TracingColumns.STATION_TOB, createCell(r.getValue(STATION.BETRIEBSART))); fillCell(spec, cells, BackwardUtils.STATION_NUMCASES, createCell(r.getValue(STATION.ANZAHLFAELLE))); fillCell(spec, cells, BackwardUtils.STATION_DATESTART, createCell(r.getValue(STATION.DATUMBEGINN))); fillCell(spec, cells, BackwardUtils.STATION_DATEPEAK, createCell(r.getValue(STATION.DATUMHOEHEPUNKT))); fillCell(spec, cells, BackwardUtils.STATION_DATEEND, createCell(r.getValue(STATION.DATUMENDE))); fillCell(spec, cells, BackwardUtils.STATION_SERIAL, createCell(r.getValue(STATION.SERIAL))); fillCell(spec, cells, TracingColumns.STATION_SIMPLESUPPLIER, !receivesFrom.containsKey(stationId) && deliversTo.get(stationId).size() == 1 ? BooleanCell.TRUE : BooleanCell.FALSE); fillCell(spec, cells, TracingColumns.STATION_DEADSTART, !receivesFrom.containsKey(stationId) ? BooleanCell.TRUE : BooleanCell.FALSE); fillCell(spec, cells, TracingColumns.STATION_DEADEND, !deliversTo.containsKey(stationId) ? BooleanCell.TRUE : BooleanCell.FALSE); fillCell(spec, cells, TracingColumns.FILESOURCES, createCell(r.getValue(STATION.IMPORTSOURCES))); fillCell(spec, cells, BackwardUtils.STATION_COUNTY, set.isAnonymize() ? DataType.getMissingCell() : createCell(district)); if (set.isLotBased()) { fillCell(spec, cells, TracingColumns.LOT_NUMBER, createCell(r.getValue(CHARGEN.CHARGENNR))); fillCell(spec, cells, TracingColumns.PRODUCT_NUMBER, createCell(r.getValue(PRODUKTKATALOG.ARTIKELNUMMER))); } for (String column : spec.getColumnNames()) { if (column.startsWith("_")) { Result<Record1<String>> result; if (!set.isLotBased()) { String attribute = column.substring(1); result = DSL.using(conn, SQLDialect.HSQLDB).select(EXTRAFIELDS.VALUE).from(EXTRAFIELDS) .where(EXTRAFIELDS.TABLENAME.equal(STATION.getName()), EXTRAFIELDS.ID.equal(r.getValue(STATION.ID)), EXTRAFIELDS.ATTRIBUTE.equal(attribute)) .fetch(); } else { String table = column.substring(1, column.indexOf(".")); String attribute = column.substring(column.indexOf(".") + 1); result = DSL.using(conn, SQLDialect.HSQLDB).select(EXTRAFIELDS.VALUE).from(EXTRAFIELDS) .where(EXTRAFIELDS.TABLENAME.equal(table), EXTRAFIELDS.ID.equal(r.getValue(ID_COLUMNS.get(table))), EXTRAFIELDS.ATTRIBUTE.equal(attribute)) .fetch(); } fillCell(spec, cells, column, !result.isEmpty() ? createCell(result.get(0).value1()) : DataType.getMissingCell()); } } container.addRowToTable(new DefaultRow(RowKey.createRowKey(index++), cells)); exec.checkCanceled(); } container.close(); return container.getTable(); }