List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:co.paralleluniverse.comsat.webactors.netty.NettyHttpRequest.java
@Override public final Multimap<String, String> getParameters() { QueryStringDecoder queryStringDecoder; if (params == null) { queryStringDecoder = new QueryStringDecoder(req.getUri()); final ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); final Map<String, List<String>> parameters = queryStringDecoder.parameters(); for (final String k : parameters.keySet()) builder.putAll(k, parameters.get(k)); params = builder.build();// www. ja v a 2 s. c o m } return params; }
From source file:org.prebake.core.GlobSet.java
private void groupByPrefixInto(PrefixTree t, ImmutableMultimap.Builder<String, Glob> out, StringBuilder prefix) {/*from ww w . ja v a 2 s. co m*/ Collection<Glob> globs = t.globsByExtension.values(); if (!globs.isEmpty()) { out.putAll(prefix.toString(), globs); } if (!t.children.isEmpty()) { int len = prefix.length(); for (Map.Entry<String, PrefixTree> child : t.children.entrySet()) { if (len != 0) { prefix.append('/'); } groupByPrefixInto(child.getValue(), out, prefix.append(child.getKey())); prefix.setLength(len); } } }
From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java
public ArtifactFileResolver(final MavenProject project, final ImmutableSet<File> bootClasspath, final boolean preferLocal) throws DependencyResolutionRequiredException { checkNotNull(project, "project is null"); this.preferLocal = preferLocal; // This needs to be a multimap, because it is possible by jiggling with classifiers that a local project // (with local folders) does map to multiple artifacts and therefore the file <-> artifact relation is not // 1:1 but 1:n. As found in https://github.com/basepom/duplicate-finder-maven-plugin/issues/10 ImmutableMultimap.Builder<File, Artifact> localFileArtifactCacheBuilder = ImmutableMultimap.builder(); // This can not be an immutable map builder, because the map is used for looking up while it is built up. this.repoArtifactCache = HashBiMap.create(project.getArtifacts().size()); this.bootClasspath = bootClasspath; for (final Artifact artifact : project.getArtifacts()) { final File repoPath = artifact.getFile(); final Artifact canonicalizedArtifact = ArtifactFileResolver.canonicalizeArtifact(artifact); checkState(repoPath != null && repoPath.exists(), "Repository Path '%s' does not exist.", repoPath); final File oldFile = repoArtifactCache.put(canonicalizedArtifact, repoPath); checkState(oldFile == null || oldFile.equals(repoPath), "Already encountered a file for %s: %s", canonicalizedArtifact, oldFile); }//from w ww .j a va 2s . c om for (final MavenProject referencedProject : project.getProjectReferences().values()) { // referenced projects only have GAV coordinates but no scope. final Set<Artifact> repoArtifacts = findRepoArtifacts(referencedProject, repoArtifactCache); // This can happen if another sub-project in the reactor is e.g. used as a compiler plugin dependency. // In that case, the dependency will show up as a referenced project but not in the artifacts list from the project. // Fix up straight from the referenced project. if (repoArtifacts.isEmpty()) { LOG.debug( "Found project reference to %s but no repo reference, probably used in a plugin dependency.", referencedProject.getArtifact()); } for (final Artifact artifact : repoArtifacts) { final File outputDir = isTestArtifact(artifact) ? getTestOutputDirectory(referencedProject) : getOutputDirectory(referencedProject); if (outputDir != null && outputDir.exists()) { localFileArtifactCacheBuilder.put(outputDir, artifact); } } } this.localFileArtifactCache = localFileArtifactCacheBuilder.build(); // Flip the File -> Artifact multimap. This also acts as a sanity check because no artifact // must be present more than one and the Map.Builder will choke if a key is around more than // once. ImmutableMap.Builder<Artifact, File> localArtifactFileCacheBuilder = ImmutableMap.builder(); for (Map.Entry<File, Artifact> entry : localFileArtifactCache.entries()) { localArtifactFileCacheBuilder.put(entry.getValue(), entry.getKey()); } this.localArtifactFileCache = localArtifactFileCacheBuilder.build(); }
From source file:com.ibm.common.activitystreams.internal.MultimapAdapter.java
/** * Method deserialize.//from www . j av a2s .c o m * @param json JsonElement * @param typeOfT Type * @param context JsonDeserializationContext * @return Multimap * @throws JsonParseException * @see com.google.gson.JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) */ public Multimap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { ImmutableMultimap.Builder mm = ImmutableMultimap.builder(); JsonObject obj = json.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { String key = entry.getKey(); JsonElement val = entry.getValue(); if (val.isJsonArray()) { for (JsonElement el : val.getAsJsonArray()) { if (el.isJsonArray()) mm.put(key, arraydes(el.getAsJsonArray(), context)); else if (el.isJsonObject()) mm.put(key, context.deserialize(el, ASObject.class)); else if (el.isJsonPrimitive()) mm.put(key, primConverter.convert(el.getAsJsonPrimitive())); } } else if (val.isJsonObject()) { mm.put(key, context.deserialize(val, ASObject.class)); } else if (val.isJsonPrimitive()) { mm.put(key, primConverter.convert(val.getAsJsonPrimitive())); } } return mm.build(); }
From source file:org.apache.shindig.gadgets.spec.Feature.java
/** * Creates a new Feature from an xml node. * * @param feature The feature to create// w ww . ja v a 2s . c o m * @throws SpecParserException When the Require or Optional tag is not valid */ public Feature(Element feature) throws SpecParserException { this.required = feature.getNodeName().equals("Require"); String name = XmlUtil.getAttribute(feature, "feature"); if (name == null) { throw new SpecParserException((required ? "Require" : "Optional") + "@feature is required."); } this.name = name; NodeList children = feature.getElementsByTagName("Param"); if (children.getLength() > 0) { ImmutableMultimap.Builder<String, String> params = ImmutableMultimap.builder(); for (int i = 0, j = children.getLength(); i < j; ++i) { Element param = (Element) children.item(i); String paramName = XmlUtil.getAttribute(param, "name"); if (paramName == null) { throw new SpecParserException("Param@name is required"); } params.put(paramName, param.getTextContent()); } this.params = params.build(); } else { this.params = ImmutableMultimap.of(); } }
From source file:com.google.caliper.EnvironmentGetter.java
/** * Returns the key/value pairs from the specified properties-file like * reader. Unlike standard Java properties files, {@code reader} is allowed * to list the same property multiple times. Comments etc. are unsupported. *//* www. j a v a 2 s .c o m*/ private static Multimap<String, String> propertiesFileToMultimap(Reader reader) throws IOException { ImmutableMultimap.Builder<String, String> result = ImmutableMultimap.builder(); BufferedReader in = new BufferedReader(reader); String line; while ((line = in.readLine()) != null) { String[] parts = line.split("\\s*\\:\\s*", 2); if (parts.length == 2) { result.put(parts[0], parts[1]); } } in.close(); return result.build(); }
From source file:io.urmia.job.pub.InputAwareZkJobQueue.java
private Map<String, JobInput> split(JobInput input) throws Exception { ImmutableMultimap.Builder<String, ObjectName> b = ImmutableMultimap.builder(); for (/*ObjectName*/String in : input) { Optional<ObjectName> optOn = ObjectName.of(in); if (!optOn.isPresent()) { log.warn("no ObjectName for input: {}", in); continue; }/*w w w . ja v a 2 s . c o m*/ ObjectName on = optOn.get(); ServiceInstance<NodeType> s = whereIs(on); log.info("looking where is on: {} -> {}", on, s); if (s != null) b.put(s.getId(), on); } Map<String, Collection<ObjectName>> m = b.build().asMap(); return Maps.transformValues(m, transformer()); }
From source file:org.apache.calcite.rel.metadata.ChainedRelMetadataProvider.java
public <M extends Metadata> Multimap<Method, MetadataHandler<M>> handlers(MetadataDef<M> def) { final ImmutableMultimap.Builder<Method, MetadataHandler<M>> builder = ImmutableMultimap.builder(); for (RelMetadataProvider provider : providers.reverse()) { builder.putAll(provider.handlers(def)); }/*from w ww .j av a 2s . c o m*/ return builder.build(); }
From source file:com.google.idea.blaze.base.targetmaps.SourceToTargetMapImpl.java
@Nullable private ImmutableMultimap<File, TargetKey> initSourceToTargetMap() { BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); if (blazeProjectData == null) { return null; }/*from w w w . j av a2 s .c o m*/ ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder; ImmutableMultimap.Builder<File, TargetKey> sourceToTargetMap = ImmutableMultimap.builder(); for (TargetIdeInfo target : blazeProjectData.targetMap.targets()) { TargetKey key = target.key; for (ArtifactLocation sourceArtifact : target.sources) { sourceToTargetMap.put(artifactLocationDecoder.decode(sourceArtifact), key); } } return sourceToTargetMap.build(); }
From source file:org.lanternpowered.server.asset.AbstractMultiAssetRepository.java
@Override public Multimap<String, Asset> getAssetsMap(String path, boolean checkChildDirectories) { final Map<String, Map<String, Asset>> map = new HashMap<>(); for (AssetRepository repository : getRepositories()) { final Multimap<String, Asset> multimap = repository.getAssetsMap(path, checkChildDirectories); multimap.entries().forEach(entry -> { final Map<String, Asset> entries = map.computeIfAbsent(entry.getKey(), key -> new HashMap<>()); entries.putIfAbsent(entry.getValue().getId(), entry.getValue()); });//from w ww .j av a 2 s . c o m } final ImmutableMultimap.Builder<String, Asset> builder = ImmutableMultimap.builder(); map.entrySet().forEach(entry -> builder.putAll(entry.getKey(), entry.getValue().values())); return builder.build(); }