List of usage examples for com.google.common.collect SetMultimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.jboss.weld.bootstrap.Validator.java
public void validateBeanNames(BeanManagerImpl beanManager) { SetMultimap<String, Bean<?>> namedAccessibleBeans = Multimaps .newSetMultimap(new HashMap<String, Collection<Bean<?>>>(), HashSetSupplier.<Bean<?>>instance()); for (Bean<?> bean : beanManager.getAccessibleBeans()) { if (bean.getName() != null) { namedAccessibleBeans.put(bean.getName(), bean); }/*from w w w . java 2s . c o m*/ } List<String> accessibleNamespaces = new ArrayList<String>(); for (String namespace : beanManager.getAccessibleNamespaces()) { accessibleNamespaces.add(namespace); } SpecializationAndEnablementRegistry registry = beanManager.getServices() .get(SpecializationAndEnablementRegistry.class); for (String name : namedAccessibleBeans.keySet()) { Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver() .resolve(Beans.removeDisabledBeans(namedAccessibleBeans.get(name), beanManager, registry)); if (resolvedBeans.size() > 1) { throw ValidatorLogger.LOG.ambiguousElName(name, resolvedBeans); } if (accessibleNamespaces.contains(name)) { throw ValidatorLogger.LOG.beanNameIsPrefix(name); } } }
From source file:com.google.devtools.build.lib.query2.output.ConditionalEdges.java
/** * Returns map of dependency to list of condition-labels. * * <p>Example: For a rule like below, * * <pre>/*ww w. j a v a2s . c om*/ * some_rule( * ... * deps = [ * ... default dependencies ... * ] + select ({ * "//some:config1": [ "//some:a", "//some:common" ], * "//some:config2": [ "//other:a", "//some:common" ], * "//conditions:default": [ "//some:default" ], * }) * ) * </pre> * * it returns following map: * * <pre> * { * "//some:a": ["//some:config1" ] * "//other:a": ["//some:config2" ] * "//some:common": ["//some:config1", "//some:config2" ] * "//some:default": [ "//conditions:default" ] * } * </pre> */ private SetMultimap<Label, Label> getAllConditions(Rule rule, RawAttributeMapper attributeMap) { SetMultimap<Label, Label> conditions = HashMultimap.create(); for (Attribute attr : rule.getAttributes()) { // TODO(bazel-team): Handle the case where dependency exists through both configurable as well // as non-configurable attributes. Currently this prints such an edge as a conditional one. if (!attributeMap.isConfigurable(attr.getName())) { // skip non configurable attributes continue; } for (BuildType.Selector<?> selector : ((BuildType.SelectorList<?>) attributeMap .getRawAttributeValue(rule, attr)).getSelectors()) { if (selector.isUnconditional()) { // skip unconditional selectors continue; } for (Map.Entry<Label, ?> entry : selector.getEntries().entrySet()) { if (entry.getValue() instanceof List<?>) { List<?> deps = (List<?>) entry.getValue(); for (Object dep : deps) { if (dep instanceof Label) { conditions.put((Label) dep, entry.getKey()); } } } else if (entry.getValue() instanceof Label) { conditions.put((Label) entry.getValue(), entry.getKey()); } } } } return conditions; }
From source file:com.analog.lyric.dimple.model.transform.JunctionTreeTransform.java
/** * Computes list of edges from {@code clique} to other cliques that are not yet in the * spanning tree.//from ww w .jav a 2 s.c o m * * @param clique * @param varToCliques is a mapping from variable to the cliques that contain it. */ private List<CliqueEdge> edgesNotInTree(Clique clique, SetMultimap<Discrete, Clique> varToCliques) { final SetMultimap<Clique, Discrete> cliqueToCommonVars = LinkedHashMultimap.create(); // NOTE: because clique._variables is sorted the variables in the edge list will also be sorted. for (Discrete variable : clique._variables) { for (Clique neighbor : varToCliques.get(variable)) { if (!neighbor._inSpanningTree) { cliqueToCommonVars.put(neighbor, variable); } } } List<CliqueEdge> edges = new ArrayList<CliqueEdge>(cliqueToCommonVars.size()); for (Clique neighbor : cliqueToCommonVars.keySet()) { final Set<Discrete> commonVars = cliqueToCommonVars.get(neighbor); edges.add(new CliqueEdge(clique, neighbor, ArrayUtil.copy(Discrete.class, commonVars))); } return edges; }
From source file:org.cytoscape.model.internal.CyTableImpl.java
private final void addToReverseMap(final String columnName, final Object key, final Object oldValue, final Object newValue) { final String normalizedColName = normalizeColumnName(columnName); final SetMultimap<Object, Object> valueTokeysMap = reverse.get(normalizedColName); valueTokeysMap.remove(oldValue, key); valueTokeysMap.put(newValue, key); }
From source file:com.google.protoeditor.validation.ProtoValidator.java
public void checkEnums(ProtoDefinitionBody protoMessageDefinition, AnnotationHolder annotationHolder) { SetMultimap<String, ProtoEnumDefinition> enumNames = HashMultimap.create(); for (ProtoEnumDefinition enm : protoMessageDefinition.getEnumerations()) { SetMultimap<String, ProtoEnumConstant> enumConstantNames = HashMultimap.create(); String enumName = enm.getName(); enumNames.put(enumName, enm); final SortedMap<Long, Set<ProtoEnumConstant>> enumNumbers = getUsedEnumConstantValues(enm, enumConstantNames);/* www .ja va2 s .com*/ for (Map.Entry<Long, Set<ProtoEnumConstant>> entry : enumNumbers.entrySet()) { Set<ProtoEnumConstant> consts = entry.getValue(); if (consts.size() > 1) { for (ProtoEnumConstant constant : consts) { ProtoEnumValue enumValue = constant.getEnumValue(); if (enumValue == null) { continue; } final ProtoAbstractIntegerLiteral valueLiteral = enumValue.getValueLiteral(); if (valueLiteral == null) { continue; } Annotation anno = annotationHolder.createWarningAnnotation(valueLiteral, "multiple constants in " + enm.getName() + " have value " + entry.getKey()); anno.registerFix(new IntentionAction() { @Override public String getText() { return "Reassign enum constant value"; } @Override public String getFamilyName() { return "ReassignEnumValue"; } @Override public boolean isAvailable(Project project, Editor editor, PsiFile file) { return true; } @Override public void invoke(Project project, Editor editor, PsiFile file) { valueLiteral.setIntValue(enumNumbers.lastKey() + 1); } @Override public boolean startInWriteAction() { return true; } }); } } } for (Map.Entry<String, Collection<ProtoEnumConstant>> entry : enumConstantNames.asMap().entrySet()) { Collection<ProtoEnumConstant> consts = entry.getValue(); if (consts.size() > 1) { for (ProtoEnumConstant constant : consts) { annotationHolder.createErrorAnnotation(constant.getNameElement(), "multiple constants in " + enm.getName() + " have name " + entry.getKey()); } } } } for (Map.Entry<String, Collection<ProtoEnumDefinition>> entry : enumNames.asMap().entrySet()) { Collection<ProtoEnumDefinition> enums = entry.getValue(); if (enums.size() > 1) { for (ProtoEnumDefinition enm : enums) { annotationHolder.createErrorAnnotation(enm.getNameElement(), "multiple definitions " + "of enum " + entry.getKey()); } } } }
From source file:io.tilt.minka.business.leader.distributor.SpillOverBalancer.java
private SetMultimap<Shard, ShardDuty> collectTransceivers(final PartitionTable table, boolean loadStrat, final Map<Shard, AtomicLong> spaceByReceptor, final long maxValue) { final SetMultimap<Shard, ShardDuty> transmitting = HashMultimap.create(); for (final Shard shard : table.getAllImmutable()) { final Set<ShardDuty> dutiesByShard = table.getDutiesByShard(shard); final List<ShardDuty> checkingDuties = new ArrayList<>(dutiesByShard); if (loadStrat) { // order it so we can obtain sequentially granulated reductions of the transmitting shard Collections.sort(checkingDuties, Workload.getComparator()); }//from ww w .j a va 2s .c om final long totalWeight = dutiesByShard.stream().mapToLong(i -> i.getDuty().getWeight().getLoad()).sum(); final boolean isEmisor = (!loadStrat && dutiesByShard.size() > maxValue) || (loadStrat && (totalWeight) > maxValue); final boolean isReceptor = (!loadStrat && dutiesByShard.size() < maxValue) || (loadStrat && totalWeight < maxValue); if (isEmisor) { if (!loadStrat) { for (int i = 0; i < dutiesByShard.size() - maxValue; i++) { transmitting.put(shard, checkingDuties.get(i)); } } else if (loadStrat) { long liftAccumulated = 0; for (final ShardDuty takeMe : dutiesByShard) { long load = takeMe.getDuty().getWeight().getLoad(); if ((liftAccumulated += load) <= totalWeight - maxValue) { transmitting.put(shard, takeMe); } else { break; // following are bigger because sorted } } } } else if (isReceptor) { // until loop ends we cannot for certain which shard is receptor and can receive which duty spaceByReceptor.put(shard, new AtomicLong(maxValue - (loadStrat ? totalWeight : dutiesByShard.size()))); } } return transmitting; }
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 w w w.j a v a 2 s . c o m } 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.onosproject.net.intent.impl.compiler.LinkCollectionCompiler.java
/** * Helper method to compute input and output ports * for each device crossed in the path./* w w w. j a v a 2s .c om*/ * * @param intent the related intents * @param inputPorts the input ports to compute * @param outputPorts the output ports to compute */ protected void computePorts(LinkCollectionIntent intent, SetMultimap<DeviceId, PortNumber> inputPorts, SetMultimap<DeviceId, PortNumber> outputPorts) { for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } }
From source file:tiger.NewDependencyCollector.java
/** * Adds the give {@link NewDependencyInfo} to the map, handling generic type with formal * parameters. Returns if it changed the given map. */// w w w . jav a 2s. c om private boolean addDependencyInfo(SetMultimap<NewBindingKey, NewDependencyInfo> existingDependencies, NewDependencyInfo info) { NewBindingKey key = info.getDependant(); TypeName typeName = key.getTypeName(); // For generic type with type variable, only keep raw type. if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName; TypeName anyParameter = Preconditions.checkNotNull( Iterables.getFirst(parameterizedTypeName.typeArguments, null), String.format("ParameterizedTypeName of %s has no parameter.", key)); if (anyParameter instanceof TypeVariableName) { typeName = parameterizedTypeName.rawType; key = NewBindingKey.get(typeName, key.getQualifier()); } } return existingDependencies.put(key, info); }
From source file:com.google.protoeditor.validation.ProtoValidator.java
private SortedMap<Long, Set<ProtoEnumConstant>> getUsedEnumConstantValues(ProtoEnumDefinition enm, SetMultimap<String, ProtoEnumConstant> enumConstantNames) { SortedMap<Long, Set<ProtoEnumConstant>> enumNumbers = new TreeMap<Long, Set<ProtoEnumConstant>>(); for (ProtoEnumConstant constant : enm.getConstants()) { ProtoNameElement nameElement = constant.getNameElement(); if (nameElement != null) { String name = nameElement.getName(); enumConstantNames.put(name, constant); }/*from w w w. j a va2 s. c om*/ ProtoEnumValue enumValue = constant.getEnumValue(); if (enumValue != null && enumValue.hasValidValue()) { long value = enumValue.getValue(); Set<ProtoEnumConstant> constsForId = enumNumbers.get(value); if (constsForId == null) { constsForId = new HashSet<ProtoEnumConstant>(); enumNumbers.put(value, constsForId); } constsForId.add(constant); } } return enumNumbers; }