List of usage examples for com.google.common.collect Multimaps newSetMultimap
public static <K, V> SetMultimap<K, V> newSetMultimap(Map<K, Collection<V>> map, final Supplier<? extends Set<V>> factory)
From source file:net.minecraftforge.common.model.animation.AnimationStateMachine.java
@Deprecated public AnimationStateMachine(ImmutableMap<String, ITimeValue> parameters, ImmutableMap<String, IClip> clips, ImmutableList<String> states, ImmutableMap<String, String> transitions, String startState) { this(parameters, clips, states, ImmutableMultimap.copyOf(Multimaps .newSetMultimap(Maps.transformValues(transitions, new Function<String, Collection<String>>() { public Collection<String> apply(String input) { return ImmutableSet.of(input); }//from w ww . j a v a 2 s . c o m }), new Supplier<Set<String>>() { public Set<String> get() { return Sets.newHashSet(); } })), startState); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext.java
public EffectiveSchemaContext(final Set<Module> modules) { /*/*from w w w . j av a 2s . co m*/ * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()]))); /* * The most common lookup is from Namespace->Module. * * RESTCONF performs lookups based on module name only, where it wants * to receive the latest revision * * Invest some quality time in building up lookup tables for both. */ final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); Set<ModuleIdentifier> modIdBuilder = new HashSet<>(); for (Module m : modules) { nameMap.put(m.getName(), m); nsMap.put(m.getNamespace(), m); modIdBuilder.add(ModuleIdentifierImpl.create(m.getName(), Optional.of(m.getNamespace()), Optional.of(m.getRevision()))); resolveSubmoduleIdentifiers(m.getSubmodules(), modIdBuilder); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder); rootDeclaredStatements = ImmutableList.of(); rootEffectiveStatements = ImmutableList.of(); }
From source file:com.android.tools.idea.experimental.codeanalysis.callgraph.Callgraph.java
protected Callgraph() { this.callerNodeToMethodsMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<PsiCFGMethod>>() { @Override//from ww w . j a v a 2s .c om public Set<PsiCFGMethod> get() { return Sets.newHashSet(); } }); this.calleeMethodToCallerGraphNodeMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<GraphNode>>() { @Override public Set<GraphNode> get() { return Sets.newHashSet(); } }); this.callerNodeToCalleeNodeMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<GraphNode>>() { @Override public Set<GraphNode> get() { return Sets.newHashSet(); } }); this.calleeNodeToCallerNodeMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<GraphNode>>() { @Override public Set<GraphNode> get() { return Sets.newHashSet(); } }); this.callerMethodToCalleeMethodMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<PsiCFGMethod>>() { @Override public Set<PsiCFGMethod> get() { return Sets.newHashSet(); } }); this.calleeMethodToCallerMethodReturnMap = Multimaps.newSetMultimap(Maps.newHashMap(), new Supplier<Set<PsiCFGMethod>>() { @Override public Set<PsiCFGMethod> get() { return Sets.newHashSet(); } }); allMethodsInGraph = Sets.newHashSet(); }
From source file:org.nuxeo.runtime.test.runner.RuntimeFeature.java
/** * Deploys bundles specified in the @Bundles annotation. *//*from w ww . ja v a 2s. c om*/ protected void deployTestClassBundles(FeaturesRunner runner) throws Exception { Set<String> bundles = new HashSet<String>(); Map<String, Collection<String>> mainDeployments = new HashMap<>(); SetMultimap<String, String> mainIndex = Multimaps.newSetMultimap(mainDeployments, new Supplier<Set<String>>() { @Override public Set<String> get() { return new HashSet<String>(); } }); Map<String, Collection<String>> localDeployments = new HashMap<>(); SetMultimap<String, String> localIndex = Multimaps.newSetMultimap(localDeployments, new Supplier<Set<String>>() { @Override public Set<String> get() { return new HashSet<String>(); } }); indexBundleResources(runner, bundles, mainIndex, getDeployments()); indexBundleResources(runner, bundles, localIndex, getLocalDeployments()); AssertionError errors = new AssertionError("cannot deploy components"); for (String name : bundles) { Bundle bundle = null; try { harness.deployBundle(name); bundle = harness.getOSGiAdapter().getBundle(name); } catch (Exception error) { errors.addSuppressed(error); continue; } try { // deploy bundle contribs for (String resource : mainIndex.removeAll(name)) { try { harness.deployContrib(name, resource); } catch (Exception error) { errors.addSuppressed(error); } } // deploy local contribs for (String resource : localIndex.removeAll(name)) { URL url = runner.getTargetTestResource(name); if (url == null) { url = bundle.getEntry(resource); } if (url == null) { url = runner.getTargetTestClass().getClassLoader().getResource(resource); } if (url == null) { throw new AssertionError("Cannot find " + resource + " in " + name); } harness.deployTestContrib(name, url); } } catch (Exception error) { errors.addSuppressed(error); } } for (Map.Entry<String, String> resource : mainIndex.entries()) { try { harness.deployContrib(resource.getKey(), resource.getValue()); } catch (Exception error) { errors.addSuppressed(error); } } for (Map.Entry<String, String> resource : localIndex.entries()) { try { harness.deployTestContrib(resource.getKey(), resource.getValue()); } catch (Exception error) { errors.addSuppressed(error); } } if (errors.getSuppressed().length > 0) { throw errors; } }
From source file:org.jetbrains.jet.grammar.GrammarGenerator.java
private static String generate(List<Token> tokens) throws IOException { StringWriter result = new StringWriter(); Set<String> declaredSymbols = new HashSet<String>(); Set<String> usedSymbols = new HashSet<String>(); Multimap<String, String> usages = Multimaps.newSetMultimap(Maps.<String, Collection<String>>newHashMap(), new Supplier<Set<String>>() { @Override// w w w .j av a2 s.c om public Set<String> get() { return Sets.newHashSet(); } }); Declaration lastDeclaration = null; for (Token advance : tokens) { if (advance instanceof Declaration) { Declaration declaration = (Declaration) advance; lastDeclaration = declaration; declaredSymbols.add(declaration.getName()); } else if (advance instanceof Identifier) { Identifier identifier = (Identifier) advance; assert lastDeclaration != null; usages.put(identifier.getName(), lastDeclaration.getName()); usedSymbols.add(identifier.getName()); } } try { JAXBContext context = JAXBContext.newInstance(Annotation.class, Comment.class, Declaration.class, DocComment.class, Identifier.class, Other.class, StringToken.class, SymbolToken.class, Token.class, WhiteSpace.class, TokenList.class); Marshaller m = context.createMarshaller(); TokenList list = new TokenList(tokens); list.updateUsages(usedSymbols, usages); m.marshal(list, result); } catch (PropertyException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } result.flush(); result.close(); return result.toString(); }
From source file:org.jboss.weld.bootstrap.ConcurrentValidator.java
@Override public void validateBeanNames(final BeanManagerImpl beanManager) { final 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 ww .j av a 2 s . co m } final List<String> accessibleNamespaces = new ArrayList<String>(); for (String namespace : beanManager.getAccessibleNamespaces()) { accessibleNamespaces.add(namespace); } final SpecializationAndEnablementRegistry registry = beanManager.getServices() .get(SpecializationAndEnablementRegistry.class); executor.invokeAllAndCheckForExceptions( new IterativeWorkerTaskFactory<String>(namedAccessibleBeans.keySet()) { protected void doWork(String name) { Set<Bean<?>> resolvedBeans = beanManager.getBeanResolver().resolve( Beans.removeDisabledBeans(namedAccessibleBeans.get(name), beanManager, registry)); if (resolvedBeans.size() > 1) { throw ValidatorLogger.LOG.ambiguousElName(name, WeldCollections.toMultiRowString(resolvedBeans)); } if (accessibleNamespaces.contains(name)) { throw ValidatorLogger.LOG.beanNameIsPrefix(name); } } }); }
From source file:collene.cache.CachingIO.java
private void runEvictions() throws Exception { // don't bother if there is no eviction policy. if (evictionStrategy == null) { return;/*from w ww . j a v a 2 s . c om*/ } synchronized (evictionStrategy) { // keep track of what to remove here. final SetMultimap<String, Long> willRemove = Multimaps .newSetMultimap(Maps.<String, Collection<Long>>newHashMap(), new Supplier<Set<Long>>() { @Override public Set<Long> get() { return Sets.newHashSet(); } }); // iterate over the table, evaluating each member. // do not evaluate members that need to be flushed (written). for (String key : cache.rowKeySet()) { Set<Long> colsToAvoid = needsFlush.get(key); for (Long col : cache.row(key).keySet()) { if (colsToAvoid.contains(col)) { continue; } if (evictionStrategy.shouldEvict(key, col)) { willRemove.put(key, col); } } } // actually remove them now. synchronized (cache) { for (String key : willRemove.keySet()) { for (long col : willRemove.get(key)) { cache.remove(key, col); evictionStrategy.remove(key, col); } } } } }
From source file:io.crate.analyze.relations.RelationSplitter.java
private void processOrderBy() { if (!querySpec.orderBy().isPresent()) { return;/*from w ww . j av a2s . c o m*/ } OrderBy orderBy = querySpec.orderBy().get(); Set<AnalyzedRelation> relations = Collections .newSetFromMap(new IdentityHashMap<AnalyzedRelation, Boolean>()); Multimap<AnalyzedRelation, Integer> splits = Multimaps.newSetMultimap( new IdentityHashMap<AnalyzedRelation, Collection<Integer>>(specs.size()), INT_SET_SUPPLIER); // Detect remaining orderBy before any push down happens, // since if remaining orderBy is detected we need to // process again all pushed down orderBys and merge them // to the remaining OrderBy in the correct order. for (Symbol symbol : orderBy.orderBySymbols()) { relations.clear(); RelationCounter.INSTANCE.process(symbol, relations); if (relations.size() > 1 || // Outer Join requires post-order-by because the nested loop adds rows which affects ordering JoinPairs.isOuterRelation(relations.iterator().next().getQualifiedName(), joinPairs)) { remainingOrderBy = new RemainingOrderBy(); break; } } Integer idx = 0; for (Symbol symbol : orderBy.orderBySymbols()) { relations.clear(); RelationCounter.INSTANCE.process(symbol, relations); // If remainingOrderBy detected then don't push down anything but // merge it with remainingOrderBy since we need to re-apply this // sort again at the place where remainingOrderBy is applied. if (remainingOrderBy != null) { OrderBy newOrderBy = orderBy.subset(Collections.singletonList(idx)); for (AnalyzedRelation rel : relations) { remainingOrderBy.addRelation(rel.getQualifiedName()); } remainingOrderBy.addOrderBy(newOrderBy); } else { // push down splits.put(Iterables.getOnlyElement(relations), idx); } idx++; } // Process pushed down order by for (Map.Entry<AnalyzedRelation, Collection<Integer>> entry : splits.asMap().entrySet()) { AnalyzedRelation relation = entry.getKey(); OrderBy newOrderBy = orderBy.subset(entry.getValue()); QuerySpec spec = getSpec(relation); assert !spec.orderBy().isPresent(); spec.orderBy(newOrderBy); requiredForQuery.addAll(newOrderBy.orderBySymbols()); } }
From source file:org.sonar.java.resolve.LeastUpperBound.java
/** * For any element G of MEC that is a generic type, let the "relevant" parameterizations of G, Relevant(G), be: * Relevant(G) = { V | 1 i k: V in ST(Ui) and V = G<...> } * * @param minimalErasedCandidates MEC//from www.jav a 2 s .com * @param supertypes * @return the set of known parameterizations for each generic type G of MEC */ private static Multimap<Type, Type> relevantParameterizations(List<Type> minimalErasedCandidates, List<Set<Type>> supertypes) { Multimap<Type, Type> result = Multimaps.newSetMultimap(new HashMap<>(), LinkedHashSet::new); for (Set<Type> supertypesSet : supertypes) { for (Type supertype : supertypesSet) { Type erasedSupertype = supertype.erasure(); if (minimalErasedCandidates.contains(erasedSupertype)) { result.put(erasedSupertype, supertype); } } } return result; }
From source file:org.jetbrains.jet.lang.resolve.calls.autocasts.DelegatingDataFlowInfo.java
@NotNull /* package */ static SetMultimap<DataFlowValue, JetType> newTypeInfo() { return Multimaps.newSetMultimap(Maps.<DataFlowValue, Collection<JetType>>newHashMap(), CommonSuppliers.<JetType>getLinkedHashSetSupplier()); }