List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.franca.tools.contracts.tracevalidator.search.regexp.RegexpBuilder.java
/** * Constructs the regular expression that accepts the traces matching the * given contract.//from ww w.j a v a 2 s . c o m * * @param contract * the Franca contract for the interface * @return the regular expression associated to the contract */ public static RegexpElement buildRegexp(FContract contract) { Set<FState> statesVisited = new HashSet<FState>(); List<FState> statesToVisit = new LinkedList<FState>(); FState initial = contract.getStateGraph().getInitial(); statesToVisit.add(initial); Map<FState, Multimap<FState, TraceElement>> traceElementMap = new HashMap<FState, Multimap<FState, TraceElement>>(); Set<TraceElement> traceElements = new HashSet<TraceElement>(); int stateNum = contract.getStateGraph().getStates().size(); List<FState> states = contract.getStateGraph().getStates(); RegexpElement[][][] regexpArray = new RegexpElement[stateNum][stateNum][stateNum]; // Create trace elements between the states of the contract's state // machine. The state machine must be strongly connected while (!statesToVisit.isEmpty()) { FState state = statesToVisit.remove(0); statesVisited.add(state); Multimap<FState, TraceElement> innerMap = ArrayListMultimap.create(); for (FTransition transition : state.getTransitions()) { TraceElement traceElement = new FrancaTraceElement(state, transition); traceElements.add(traceElement); innerMap.put(transition.getTo(), traceElement); if (!statesVisited.contains(transition.getTo())) { statesToVisit.add(transition.getTo()); } } traceElementMap.put(state, innerMap); } for (int i = 0; i < stateNum; i++) { for (int j = 0; j < stateNum; j++) { Collection<TraceElement> elements = traceElementMap.get(states.get(i)).get(states.get(j)); if (elements != null) { Collection<RegexpElement> regexpElements = new ArrayList<RegexpElement>(); for (TraceElement e : elements) { regexpElements.add(new SingleElement(e)); } if (i != j) { regexpArray[i][j][0] = new OrElement(regexpElements.toArray(new RegexpElement[0])); } else { regexpArray[i][j][0] = RegexpHelper.union( new OrElement(regexpElements.toArray(new RegexpElement[0])), EmptyElement.INSTANCE); } } else { regexpArray[i][j][0] = NullElement.INSTANCE; } } } if (states.size() > 0) { for (int k = 1; k < stateNum; k++) { for (int i = 0; i < stateNum; i++) { for (int j = 0; j < stateNum; j++) { regexpArray[i][j][k] = RegexpHelper.union(regexpArray[i][j][k - 1], RegexpHelper.and( RegexpHelper.and(regexpArray[i][k][k - 1], RegexpHelper.closure(regexpArray[k][k][k - 1])), regexpArray[k][j][k - 1])); } } } } RegexpElement result = regexpArray[0][0][stateNum - 1]; if (states.size() > 1) { for (int i = 1; i < stateNum; i++) { result = RegexpHelper.union(result, regexpArray[0][i][stateNum - 1]); } } //All states are accepting? return result; }
From source file:com.ardor3d.util.scenegraph.DisplayListDelegate.java
public static void cleanAllDisplayLists(final Renderer deleter) { final Multimap<Object, Integer> idMap = ArrayListMultimap.create(); // gather up expired Display Lists... these don't exist in our cache gatherGCdIds(idMap);// w w w .j a v a 2 s . c om // Walk through the cached items and delete those too. for (final DisplayListDelegate buf : _identityCache.keySet()) { // Add id to map idMap.put(buf._id.getGlContext(), buf._id.getId()); } handleDisplayListDelete(deleter, idMap); }
From source file:io.soliton.shapeshifter.ProtoDescriptorGraph.java
private static void populate(Descriptor descriptor, Multimap<Descriptor, Descriptor> graphBuilder) { if (graphBuilder.containsKey(descriptor)) { return;/*from w w w . j a v a 2s . c om*/ } for (FieldDescriptor field : descriptor.getFields()) { if (Type.MESSAGE.equals(field.getType())) { Descriptors.Descriptor subDescriptor = field.getMessageType(); graphBuilder.put(descriptor, subDescriptor); populate(subDescriptor, graphBuilder); } } }
From source file:org.apache.hadoop.hive.ql.exec.FunctionTask.java
public static void addFunctionResources(FunctionResource[] resources) throws HiveException { if (resources != null) { Multimap<SessionState.ResourceType, String> mappings = HashMultimap.create(); for (FunctionResource res : resources) { mappings.put(res.getResourceType(), res.getResourceURI()); }//from w w w . j a v a2 s. c o m for (SessionState.ResourceType type : mappings.keys()) { SessionState.get().add_resources(type, mappings.get(type)); } } }
From source file:org.jboss.weld.util.Interceptors.java
/** * Merge class-level interceptor bindings with interceptor bindings inherited from interceptor bindings and stereotypes. *///from w ww. ja v a2 s . com public static Multimap<Class<? extends Annotation>, Annotation> mergeBeanInterceptorBindings( BeanManagerImpl beanManager, AnnotatedType<?> clazz, Collection<Annotation> classBindingAnnotations, Collection<Annotation> inheritedBindingAnnotations) { Multimap<Class<? extends Annotation>, Annotation> mergedBeanBindings = HashMultimap.create(); Set<Annotation> acceptedInheritedBindings = new HashSet<Annotation>(); // add all class-level interceptor bindings (these have precedence) for (Annotation bindingAnnotation : classBindingAnnotations) { mergedBeanBindings.put(bindingAnnotation.annotationType(), bindingAnnotation); } // add inherited interceptor bindings for (Annotation bindingAnnotation : inheritedBindingAnnotations) { Class<? extends Annotation> bindingAnnotationType = bindingAnnotation.annotationType(); // replace the previous interceptor binding with current binding if (!mergedBeanBindings.containsKey(bindingAnnotationType)) { acceptedInheritedBindings.add(bindingAnnotation); } } for (Annotation bindingAnnotation : acceptedInheritedBindings) { mergedBeanBindings.put(bindingAnnotation.annotationType(), bindingAnnotation); } return mergedBeanBindings; }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Config.java
private static Multimap<String, ObjectName> mapInstancesToModules(Set<ObjectName> instancesToMap) { Multimap<String, ObjectName> retVal = HashMultimap.create(); for (ObjectName objectName : instancesToMap) { String factoryName = ObjectNameUtil.getFactoryName(objectName); retVal.put(factoryName, objectName); }// ww w . j a v a2 s. c om return retVal; }
From source file:com.android.repository.impl.meta.RepositoryPackages.java
private static <P extends RepoPackage> Multimap<String, P> computePackagePrefixes( Map<String, ? extends P> packages) { Multimap<String, P> packagesByPrefix = TreeMultimap.create(); for (Map.Entry<String, ? extends P> entry : packages.entrySet()) { String key = entry.getKey(); while (true) { packagesByPrefix.put(key, entry.getValue()); int endIndex = key.lastIndexOf(RepoPackage.PATH_SEPARATOR); if (endIndex < 0) { break; }//from w w w. j a v a2 s . co m key = key.substring(0, endIndex); } } return packagesByPrefix; }
From source file:org.opentripplanner.graph_builder.impl.osm.AreaGroup.java
public static List<AreaGroup> groupAreas(Map<Area, OSMLevel> areasLevels) { DisjointSet<Area> groups = new DisjointSet<Area>(); Multimap<OSMNode, Area> areasForNode = LinkedListMultimap.create(); for (Area area : areasLevels.keySet()) { for (Ring ring : area.outermostRings) { for (Ring inner : ring.holes) { for (OSMNode node : inner.nodes) { areasForNode.put(node, area); }/*from w w w .ja v a2 s. co m*/ } for (OSMNode node : ring.nodes) { areasForNode.put(node, area); } } } // areas that can be joined must share nodes and levels for (OSMNode osmNode : areasForNode.keySet()) { for (Area area1 : areasForNode.get(osmNode)) { OSMLevel level1 = areasLevels.get(area1); for (Area area2 : areasForNode.get(osmNode)) { OSMLevel level2 = areasLevels.get(area2); if ((level1 == null && level2 == null) || (level1 != null && level1.equals(level2))) { groups.union(area1, area2); } } } } List<AreaGroup> out = new ArrayList<AreaGroup>(); for (Set<Area> areaSet : groups.sets()) { try { out.add(new AreaGroup(areaSet)); } catch (AreaGroup.RingConstructionException e) { for (Area area : areaSet) { LOG.debug("Failed to create merged area for " + area + ". This area might not be at fault; it might be one of the other areas in this list."); out.add(new AreaGroup(Arrays.asList(area))); } } } return out; }
From source file:com.zimbra.cs.account.accesscontrol.ACLUtil.java
private static Multimap<Right, Entry> getGrantedRights(Account grantee, Set<String> fetchAttrs) throws ServiceException { SearchGrants search = new SearchGrants(grantee.getProvisioning(), EnumSet.of(TargetType.account), RightBearer.Grantee.getGrantee(grantee, false).getIdAndGroupIds()); search.addFetchAttribute(fetchAttrs); Set<SearchGrants.GrantsOnTarget> results = search.doSearch().getResults(); Multimap<Right, Entry> map = HashMultimap.create(); for (SearchGrants.GrantsOnTarget grants : results) { ZimbraACL acl = grants.getAcl(); for (ZimbraACE ace : acl.getAllACEs()) { if (ace.getGrantee().equals(grantee.getId())) { map.put(ace.getRight(), grants.getTargetEntry()); }/*from w w w. j av a 2s . c o m*/ } } return map; }
From source file:org.eclipse.viatra.addon.viewers.runtime.specifications.SpecificationDescriptorUtilities.java
static void insertToTraces(IQuerySpecification<?> specification, Multimap<PParameter, PParameter> traces, String parameter) {//from w ww . j a v a2s.c o m String targetName = "trace<" + parameter + ">"; PParameter var_target = new PParameter(targetName, NotationPackage.eINSTANCE.getNsURI() + "||" + NotationPackage.eINSTANCE.getItem().getName()); int positionOfParameter = specification.getPositionOfParameter(parameter); PParameter var_source = specification.getParameters().get(positionOfParameter); traces.put(var_target, var_source); }