List of usage examples for com.google.common.collect SetMultimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:org.apache.cassandra.db.SystemKeyspace.java
/** * Return a map of stored tokens to IP addresses * */// ww w. j a va 2 s. c om public static SetMultimap<InetAddress, Token> loadTokens() { SetMultimap<InetAddress, Token> tokenMap = HashMultimap.create(); for (UntypedResultSet.Row row : executeInternal("SELECT peer, tokens FROM system." + PEERS)) { InetAddress peer = row.getInetAddress("peer"); if (row.has("tokens")) tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance))); } return tokenMap; }
From source file:dagger.internal.codegen.ComponentHierarchyValidator.java
/** * Checks that components do not have any scopes that are also applied on any of their ancestors. *//* w w w .ja v a2s . com*/ private void validateScopeHierarchy(ValidationReport.Builder<TypeElement> report, ComponentDescriptor subject, SetMultimap<ComponentDescriptor, Scope> scopesByComponent) { scopesByComponent.putAll(subject, subject.scopes()); for (ComponentDescriptor child : subject.subcomponents()) { validateScopeHierarchy(report, child, scopesByComponent); } scopesByComponent.removeAll(subject); Predicate<Scope> subjectScopes = subject.kind().isProducer() // TODO(beder): validate that @ProductionScope is only applied on production components ? and(in(subject.scopes()), not(equalTo(Scope.productionScope(elements)))) : in(subject.scopes()); SetMultimap<ComponentDescriptor, Scope> overlappingScopes = Multimaps.filterValues(scopesByComponent, subjectScopes); if (!overlappingScopes.isEmpty()) { StringBuilder error = new StringBuilder().append(subject.componentDefinitionType().getQualifiedName()) .append(" has conflicting scopes:"); for (Map.Entry<ComponentDescriptor, Scope> entry : overlappingScopes.entries()) { Scope scope = entry.getValue(); error.append("\n ").append(entry.getKey().componentDefinitionType().getQualifiedName()) .append(" also has ").append(scope.getReadableSource()); } report.addItem(error.toString(), compilerOptions.scopeCycleValidationType().diagnosticKind().get(), subject.componentDefinitionType()); } }
From source file:org.jboss.capedwarf.datastore.NamespaceServiceImpl.java
public SetMultimap<String, String> getKindsPerNamespaces() { SetMultimap<String, String> multimap = HashMultimap.create(); for (String namespace : getNamespaces()) { multimap.putAll(namespace, getKindsPerNamespace(namespace)); }//from w w w . j a v a2 s .c o m return multimap; }
From source file:omero.cmd.graphs.GraphUtil.java
/** * Rearrange the deletion targets such that original files are listed before their containing directories. * @param session the Hibernate session//from w w w . j a v a 2 s .co m * @param targetObjects the objects that are to be deleted * @return the given target objects with any original files suitably ordered for deletion */ static SetMultimap<String, Long> arrangeDeletionTargets(Session session, SetMultimap<String, Long> targetObjects) { if (targetObjects.get(OriginalFile.class.getName()).size() < 2) { /* no need to rearrange anything, as there are not multiple original files */ return targetObjects; } final SetMultimap<String, Long> orderedIds = LinkedHashMultimap.create(); for (final Map.Entry<String, Collection<Long>> targetObjectsByClass : targetObjects.asMap().entrySet()) { final String className = targetObjectsByClass.getKey(); Collection<Long> ids = targetObjectsByClass.getValue(); if (OriginalFile.class.getName().equals(className)) { final Collection<Collection<Long>> sortedIds = ModelObjectSequencer.sortOriginalFileIds(session, ids); ids = new ArrayList<Long>(ids.size()); for (final Collection<Long> idBatch : sortedIds) { ids.addAll(idBatch); } } orderedIds.putAll(className, ids); } return orderedIds; }
From source file:org.sosy_lab.cpachecker.cpa.invariants.InvariantsWriter.java
public void write(final CFANode pCfaNode, UnmodifiableReachedSet pReachedSet, Appendable pAppendable) throws IOException { FluentIterable<InvariantsState> states = FluentIterable.from(pReachedSet) .filter(new Predicate<AbstractState>() { @Override/*from w ww . jav a 2 s.c o m*/ public boolean apply(@Nullable AbstractState pArg0) { return pArg0 != null && AbstractStates.extractLocation(pArg0).equals(pCfaNode); } }).transform(new Function<AbstractState, InvariantsState>() { @Override @Nullable public InvariantsState apply(@Nullable AbstractState pArg0) { if (pArg0 == null) { return null; } return AbstractStates.extractStateByType(pArg0, InvariantsState.class); } }); SetMultimap<CFANode, InvariantsState> statesToNode = HashMultimap.create(); statesToNode.putAll(pCfaNode, states); write(statesToNode, pAppendable); }
From source file:org.sosy_lab.cpachecker.util.StateToFormulaWriter.java
/** write all formulas for a single program location. */ public void write(final CFANode pCfaNode, UnmodifiableReachedSet pReachedSet, Appendable pAppendable) throws IOException { SetMultimap<CFANode, FormulaReportingState> statesToNode = HashMultimap.create(); statesToNode.putAll(pCfaNode, projectToType(filterLocation(pReachedSet, pCfaNode), FormulaReportingState.class)); write(statesToNode, pAppendable);/* www . j a v a2 s. c o m*/ }
From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.DistanceCollectiveAnswerScorer.java
@SuppressWarnings("unchecked") @Override//from ww w .j a va2 s . c om public void prepare(JCas jcas) { answers = TypeUtil.getRankedAnswers(jcas); distances = HashBasedTable.create(); ImmutableSet<Answer> answerSet = ImmutableSet.copyOf(answers); SetMultimap<Answer, CandidateAnswerOccurrence> answer2caos = HashMultimap.create(); answers.forEach(answer -> TypeUtil.getCandidateAnswerVariants(answer).stream() .map(TypeUtil::getCandidateAnswerOccurrences).forEach(caos -> answer2caos.putAll(answer, caos))); for (List<Answer> pair : Sets.cartesianProduct(answerSet, answerSet)) { Answer answer1 = pair.get(0); Answer answer2 = pair.get(1); if (answer1.equals(answer2)) { distances.put(answer1, answer2, 1.0); } else { Sets.cartesianProduct(answer2caos.get(answer1), answer2caos.get(answer2)).stream() .filter(DistanceCollectiveAnswerScorer::allInTheSameView) .mapToInt(caopair -> getDistance(caopair.get(0), caopair.get(1))).min() .ifPresent(x -> distances.put(answer1, answer2, 1.0 / (1.0 + x))); } } ndistances = normalize(distances); }
From source file:dk.dma.nogoservice.service.NoGoResponseMerger.java
/** * Merge algorithm for multiple NoGoAreas. * <p>//from w w w. j a va 2 s .c o m * <ol> * <li>Find the exclusive zone for each area (the space that is not overlapped with other areas) </li> * <li>Find all the combinations of overlaps. </li> * <li>In the exclusive zone the nogo polygons (after the overlaps have been extracted) can be used directly</li> * <li>In the overlap zones the intersections of NoGo areas, will define the actual NoGo areas, because Go wins over NoGO (as foreign territory is nogo)</li> * </ol> * * @param areas the calculated NoGo areas * @return the response */ CalculatedNoGoArea merge(List<CalculatedNoGoArea> areas) { if (areas.size() == 1) { return areas.get(0); } SetMultimap<CalculatedNoGoArea, Geometry> unprocessed = HashMultimap.create(); areas.forEach(a -> unprocessed.putAll(a, a.getNogoAreas())); List<Geometry> processedNogoAreas = new ArrayList<>(); for (CalculatedNoGoArea area : areas) { List<CalculatedNoGoArea> copy = new ArrayList<>(areas); copy.remove(area); List<Geometry> otherAreas = copy.stream().map(CalculatedNoGoArea::getArea).collect(Collectors.toList()); // we now have the exclusive zone for this area. Now find the polygons inside the exclusive zone, if a polygon intersects with the boundary of the // exclusive zone, then split it in two, the part inside the exclusive zone is done, the other part will be processed later inside the overlapped zone Set<Geometry> nogoAreas = new HashSet<>(unprocessed.get(area)); // take all the nogo areas and calculate the intersection with the exclusive zone for (Geometry nogoArea : nogoAreas) { Geometry result = nogoArea; for (Geometry otherArea : otherAreas) { if (otherArea.intersects(nogoArea)) { Geometry intersection = otherArea.intersection(nogoArea); if (!intersection.isEmpty()) { result = result.difference(otherArea); // add the intersection pat of the NoGo area to the unprocessed set so we can process it during overlap handling if (!result.isEmpty()) { // if there was no difference, this nogo area is completely inside the other area unprocessed.put(area, intersection); } } } } if (!result.isEmpty()) { processedNogoAreas.add(result); unprocessed.remove(area, nogoArea); // area has now been processed } } } // now process all combinations of overlaps Set<Overlap> overlapCombinations = calculateOverlapCombinations(areas); for (Overlap overlapCombination : overlapCombinations) { Geometry exclusiveOverlapArea = overlapCombination.getExclusiveArea(); List<Geometry> nogoAreas = new ArrayList<>(); overlapCombination.included.forEach(g -> nogoAreas.addAll(unprocessed.get(g))); List<Geometry> noGoLayers = overlapCombination.included.stream().map(unprocessed::get) .filter(g -> !g.isEmpty()).map(g -> iterativeOperation(g, Geometry::union)) .collect(Collectors.toList()); List<Geometry> goAreas = noGoLayers.stream().map(exclusiveOverlapArea::difference) .collect(Collectors.toList()); if (!goAreas.isEmpty()) { // We need to join all the NoGo areas, in a way so Go wins over NoGo. Geometry totalGoArea = iterativeOperation(goAreas, Geometry::union); Geometry totalNoGoArea = exclusiveOverlapArea.difference(totalGoArea); if (!totalGoArea.isEmpty()) { processedNogoAreas.add(totalNoGoArea); } } } List<Geometry> collect = areas.stream().map(CalculatedNoGoArea::getArea).collect(Collectors.toList()); Iterator<Geometry> iterator = collect.iterator(); Geometry totalArea = iterator.next(); while (iterator.hasNext()) { totalArea = totalArea.union(iterator.next()); } TopologyPreservingSimplifier simplifier = new TopologyPreservingSimplifier(totalArea); totalArea = simplifier.getResultGeometry(); // construct the result CalculatedNoGoArea result = new CalculatedNoGoArea(); result.setArea(totalArea); result.setNogoAreas(processedNogoAreas); Optional<JSonWarning> optionalWarning = areas.stream().map(CalculatedNoGoArea::getWarning) .filter(Objects::nonNull).findFirst(); optionalWarning.ifPresent(result::setWarning); return result; }
From source file:org.jetbrains.kotlin.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@Override @NotNull/*from www .j a v a2s. co m*/ public DataFlowInfo equate(@NotNull DataFlowValue a, @NotNull DataFlowValue b) { Map<DataFlowValue, Nullability> builder = Maps.newHashMap(); Nullability nullabilityOfA = getNullability(a); Nullability nullabilityOfB = getNullability(b); boolean changed = false; changed |= putNullability(builder, a, nullabilityOfA.refine(nullabilityOfB)); changed |= putNullability(builder, b, nullabilityOfB.refine(nullabilityOfA)); SetMultimap<DataFlowValue, KotlinType> newTypeInfo = newTypeInfo(); newTypeInfo.putAll(a, collectTypesFromMeAndParents(b)); newTypeInfo.putAll(b, collectTypesFromMeAndParents(a)); if (!a.getType().equals(b.getType())) { // To avoid recording base types of own type if (!TypeUtilsKt.isSubtypeOf(a.getType(), b.getType())) { newTypeInfo.put(a, b.getType()); } if (!TypeUtilsKt.isSubtypeOf(b.getType(), a.getType())) { newTypeInfo.put(b, a.getType()); } } changed |= !newTypeInfo.isEmpty(); return !changed ? this : new DelegatingDataFlowInfo(this, ImmutableMap.copyOf(builder), newTypeInfo.isEmpty() ? EMPTY_TYPE_INFO : newTypeInfo); }
From source file:org.jetbrains.jet.lang.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@Override @NotNull/*from w w w. j a v a 2 s . c o m*/ public SetMultimap<DataFlowValue, JetType> getCompleteTypeInfo() { SetMultimap<DataFlowValue, JetType> result = newTypeInfo(); DelegatingDataFlowInfo info = this; while (info != null) { for (DataFlowValue key : info.typeInfo.keySet()) { result.putAll(key, info.typeInfo.get(key)); } info = (DelegatingDataFlowInfo) info.parent; } return result; }