List of usage examples for com.google.common.collect ImmutableMultimap copyOf
@Beta public static <K, V> ImmutableMultimap<K, V> copyOf( Iterable<? extends Entry<? extends K, ? extends V>> entries)
From source file:com.google.auto.value.processor.BuilderMethodClassifier.java
/** * Returns a multimap from the name of a property to the methods that set it. If the property is * defined by an abstract method in the {@code @AutoValue} class called {@code foo()} or * {@code getFoo()} then the name of the property is {@code foo} and there will be an entry in * the map where the key is {@code "foo"} and the value is a method in the builder called * {@code foo} or {@code setFoo}./*from w ww.j av a 2 s . c o m*/ */ ImmutableMultimap<String, ExecutableElement> propertyNameToSetters() { return ImmutableMultimap .copyOf(settersPrefixed ? propertyNameToPrefixedSetters : propertyNameToUnprefixedSetters); }
From source file:com.google.javascript.jscomp.Diagnostics.java
private static ImmutableMultimap<DiagnosticType, String> initDiagnosticGroups() { Multimap<DiagnosticType, String> builder = HashMultimap.create(); for (Map.Entry<String, DiagnosticGroup> group : GROUPS.getRegisteredGroups().entrySet()) { for (DiagnosticType type : group.getValue().getTypes()) { builder.put(type, group.getKey()); }// w w w . ja v a2 s .c o m } return ImmutableMultimap.copyOf(builder); }
From source file:org.apache.shindig.gadgets.spec.ModulePrefs.java
/** * Produces a new, substituted ModulePrefs * @param prefs An existing ModulePrefs instance * @param substituter The substituter to apply *//*from w w w . j a v a 2s. c om*/ private ModulePrefs(ModulePrefs prefs, Substitutions substituter) { base = prefs.base; categories = prefs.getCategories(); features = prefs.getFeatures(); locales = prefs.getLocales(); oauth = prefs.oauth; List<Preload> preloads = Lists.newArrayList(); for (Preload preload : prefs.preloads) { preloads.add(preload.substitute(substituter)); } this.preloads = ImmutableList.copyOf(preloads); List<Icon> icons = Lists.newArrayList(); for (Icon icon : prefs.icons) { icons.add(icon.substitute(substituter)); } this.icons = ImmutableList.copyOf(icons); ImmutableMap.Builder<String, LinkSpec> links = ImmutableMap.builder(); for (LinkSpec link : prefs.links.values()) { LinkSpec sub = link.substitute(substituter); links.put(sub.getRel(), sub); } this.links = links.build(); ImmutableMap.Builder<String, String> attributes = ImmutableMap.builder(); for (Map.Entry<String, String> attr : prefs.attributes.entrySet()) { String substituted = substituter.substituteString(attr.getValue()); attributes.put(attr.getKey(), substituted); } this.extraElements = ImmutableMultimap.copyOf(prefs.extraElements); this.attributes = attributes.build(); this.needsUserPrefSubstitution = prefs.needsUserPrefSubstitution; }
From source file:org.jclouds.ovf.internal.BaseVirtualSystem.java
@SuppressWarnings("unchecked") public BaseVirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem, Iterable<? extends VirtualHardwareSection> virtualHardwareSections, Iterable<? extends ProductSection> productSections, Multimap<String, Section> additionalSections) { super(info);//w ww . j av a2 s .c o m this.id = id; this.name = name; this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); this.virtualHardwareSections = ImmutableSet .copyOf(checkNotNull(virtualHardwareSections, "virtualHardwareSections")); this.productSections = ImmutableSet.copyOf(checkNotNull(productSections, "productSections")); this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections")); }
From source file:org.glowroot.local.ui.ClasspathCache.java
synchronized void updateCache() { Multimap<String, File> newClassNameLocations = HashMultimap.create(); for (ClassLoader loader : getKnownClassLoaders()) { updateCache(loader, newClassNameLocations); }/*from w ww .j a va 2 s .c o m*/ updateCacheWithBootstrapClasses(newClassNameLocations); if (!newClassNameLocations.isEmpty()) { Multimap<String, File> newMap = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, Ordering.natural()); newMap.putAll(classNameLocations); newMap.putAll(newClassNameLocations); classNameLocations = ImmutableMultimap.copyOf(newMap); } }
From source file:org.apache.brooklyn.core.mgmt.rebind.dto.AbstractMemento.java
protected <K, V> Multimap<K, V> fromPersistedMultimap(Multimap<K, V> m) { if (m == null) return ImmutableMultimap.of(); return ImmutableMultimap.copyOf(m); }
From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainerBuilder.java
@SuppressWarnings("StringEquality") private static ImmutableMultimap<Path, OmniTaskSelector> buildTaskSelectorsRecursively(GradleProject project, Multimap<Path, OmniTaskSelector> taskSelectorsPerProject, boolean enforceAllTasksPublic) { // add task selectors of the current project TreeBasedTable<String, Path, String> aggregatedTasksWithDescription = TreeBasedTable .create(Ordering.usingToString(), Path.Comparator.INSTANCE); Set<String> publicTasks = Sets.newLinkedHashSet(); collectAllTasksRecursively(project, aggregatedTasksWithDescription, publicTasks, enforceAllTasksPublic); for (String selectorName : aggregatedTasksWithDescription.rowKeySet()) { SortedMap<Path, String> pathsAndDescriptions = aggregatedTasksWithDescription.row(selectorName); String description = pathsAndDescriptions.get(pathsAndDescriptions.firstKey()); // description from project task with smallest path SortedSet<Path> fqnTaskNames = ImmutableSortedSet.orderedBy(Path.Comparator.INSTANCE) .addAll(pathsAndDescriptions.keySet()).build(); OmniTaskSelector taskSelector = DefaultOmniTaskSelector.from(selectorName, description != NULL_STRING ? description : null, Path.from(project.getPath()), publicTasks.contains(selectorName), fqnTaskNames); taskSelectorsPerProject.put(Path.from(project.getPath()), taskSelector); }/*from ww w . j a va2s .c o m*/ // recurse into child projects and add their task selectors DomainObjectSet<? extends GradleProject> childProjects = project.getChildren(); for (GradleProject childProject : childProjects) { buildTaskSelectorsRecursively(childProject, taskSelectorsPerProject, enforceAllTasksPublic); } // return the task selectors grouped by project path return ImmutableMultimap.copyOf(taskSelectorsPerProject); }
From source file:org.apache.crunch.impl.mr.plan.MSCRPlanner.java
public MRExecutor plan(Class<?> jarClass, Configuration conf) throws IOException { DotfileUtil dotfileUtil = new DotfileUtil(jarClass, conf); // Generate the debug lineage dotfiles (if configuration is enabled) dotfileUtil.buildLineageDotfile(outputs); Map<PCollectionImpl<?>, Set<Target>> targetDeps = Maps.newTreeMap(DEPTH_COMPARATOR); for (PCollectionImpl<?> pcollect : outputs.keySet()) { targetDeps.put(pcollect, pcollect.getTargetDependencies()); }/* ww w . j a v a 2 s.c o m*/ Multimap<Target, JobPrototype> assignments = HashMultimap.create(); while (!targetDeps.isEmpty()) { Set<Target> allTargets = Sets.newHashSet(); for (PCollectionImpl<?> pcollect : targetDeps.keySet()) { allTargets.addAll(outputs.get(pcollect)); } GraphBuilder graphBuilder = new GraphBuilder(); // Walk the current plan tree and build a graph in which the vertices are // sources, targets, and GBK operations. Set<PCollectionImpl<?>> currentStage = Sets.newHashSet(); for (PCollectionImpl<?> output : targetDeps.keySet()) { Set<Target> deps = Sets.intersection(allTargets, targetDeps.get(output)); if (deps.isEmpty()) { graphBuilder.visitOutput(output); currentStage.add(output); } } Graph baseGraph = graphBuilder.getGraph(); boolean hasInputs = false; for (Vertex v : baseGraph) { if (v.isInput()) { hasInputs = true; break; } } if (!hasInputs) { LOG.warn("No input sources for pipeline, nothing to do..."); return new MRExecutor(conf, jarClass, outputs, toMaterialize, appendedTargets, pipelineCallables); } // Create a new graph that splits up up dependent GBK nodes. Graph graph = prepareFinalGraph(baseGraph); // Break the graph up into connected components. List<List<Vertex>> components = graph.connectedComponents(); // Generate the debug graph dotfiles (if configuration is enabled) dotfileUtil.buildBaseGraphDotfile(outputs, graph); dotfileUtil.buildSplitGraphDotfile(outputs, graph, components); // For each component, we will create one or more job prototypes, // depending on its profile. // For dependency handling, we only need to care about which // job prototype a particular GBK is assigned to. Multimap<Vertex, JobPrototype> newAssignments = HashMultimap.create(); for (List<Vertex> component : components) { newAssignments.putAll(constructJobPrototypes(component)); } // Add in the job dependency information here. for (Map.Entry<Vertex, JobPrototype> e : newAssignments.entries()) { JobPrototype current = e.getValue(); for (Vertex parent : graph.getParents(e.getKey())) { for (JobPrototype parentJobProto : newAssignments.get(parent)) { current.addDependency(parentJobProto); } } } ImmutableMultimap<Target, JobPrototype> previousStages = ImmutableMultimap.copyOf(assignments); for (Map.Entry<Vertex, JobPrototype> e : newAssignments.entries()) { if (e.getKey().isOutput()) { PCollectionImpl<?> pcollect = e.getKey().getPCollection(); JobPrototype current = e.getValue(); // Add in implicit dependencies via SourceTargets that are read into memory for (Target pt : pcollect.getTargetDependencies()) { for (JobPrototype parentJobProto : assignments.get(pt)) { current.addDependency(parentJobProto); } } // Add this to the set of output assignments for (Target t : outputs.get(pcollect)) { assignments.put(t, e.getValue()); } } else { Source source = e.getKey().getSource(); if (source != null && source instanceof Target) { JobPrototype current = e.getValue(); Collection<JobPrototype> parentJobPrototypes = previousStages.get((Target) source); if (parentJobPrototypes != null) { for (JobPrototype parentJobProto : parentJobPrototypes) { current.addDependency(parentJobProto); } } } } } // Remove completed outputs and mark materialized output locations // for subsequent job processing. for (PCollectionImpl<?> output : currentStage) { if (toMaterialize.containsKey(output)) { MaterializableIterable mi = toMaterialize.get(output); if (mi.isSourceTarget()) { output.materializeAt((SourceTarget) mi.getSource()); } } targetDeps.remove(output); } } // Finally, construct the jobs from the prototypes and return. MRExecutor exec = new MRExecutor(conf, jarClass, outputs, toMaterialize, appendedTargets, pipelineCallables); // Generate the debug Plan dotfiles dotfileUtil.buildPlanDotfile(exec, assignments, pipeline, lastJobID); for (JobPrototype proto : Sets.newHashSet(assignments.values())) { exec.addJob(proto.getCrunchJob(jarClass, conf, pipeline, lastJobID)); } // Generate the debug RTNode dotfiles (if configuration is enabled) dotfileUtil.buildRTNodesDotfile(exec); // Attach the dotfiles to the MRExcutor context dotfileUtil.addDotfilesToContext(exec); return exec; }
From source file:com.google.devtools.build.android.DensitySpecificResourceFilter.java
private static Multimap<String, ResourceInfo> groupResourceInfos(final Collection<ResourceInfo> resourceInfos, Function<ResourceInfo, String> keyFunction) { Multimap<String, ResourceInfo> resourceGroups = ArrayListMultimap.create(); for (ResourceInfo resourceInfo : resourceInfos) { resourceGroups.put(keyFunction.apply(resourceInfo), resourceInfo); }// w ww . j a v a 2 s . c o m return ImmutableMultimap.copyOf(resourceGroups); }
From source file:org.apache.james.mailbox.elasticsearch.json.MimePart.java
private MimePart(HeaderCollection headerCollection, Optional<String> bodyTextContent, Optional<String> mediaType, Optional<String> subType, Optional<String> fileName, Optional<String> fileExtension, Optional<String> contentDisposition, List<MimePart> attachments, Multimap<String, String> metadata) { this.headerCollection = headerCollection; this.mediaType = mediaType; this.subType = subType; this.fileName = fileName; this.fileExtension = fileExtension; this.contentDisposition = contentDisposition; this.attachments = attachments; this.bodyTextContent = bodyTextContent; this.metadata = ImmutableMultimap.copyOf(metadata); }