List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.google.idea.blaze.base.rulemaps.SourceToRuleMapImpl.java
@Nullable private ImmutableMultimap<File, Label> initSourceToTargetMap() { BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); if (blazeProjectData == null) { return null; }// w w w . ja v a 2s . c o m ImmutableMultimap.Builder<File, Label> sourceToTargetMap = ImmutableMultimap.builder(); for (RuleIdeInfo rule : blazeProjectData.ruleMap.values()) { Label label = rule.label; for (ArtifactLocation sourceArtifact : rule.sources) { sourceToTargetMap.put(sourceArtifact.getFile(), label); } } return sourceToTargetMap.build(); }
From source file:com.google.devtools.build.lib.skyframe.serialization.MultimapCodec.java
@Override public ImmutableMultimap<K, V> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { ImmutableMultimap.Builder<K, V> result; if (codedIn.readBool()) { result = ImmutableListMultimap.builder(); } else {/* w ww .j ava 2s . co m*/ result = ImmutableSetMultimap.builder(); } int length = codedIn.readInt32(); for (int i = 0; i < length; i++) { K key = context.deserialize(codedIn); Collection<V> values = context.deserialize(codedIn); result.putAll(key, values); } return result.build(); }
From source file:com.wrmsr.kleist.util.collect.MoreCollectors.java
public static <K, V> Collector<Map.Entry<K, V>, ImmutableMultimap.Builder<K, V>, ImmutableMultimap<K, V>> toImmutableMultimap() { return toImmutableMultimap(Map.Entry::getKey, Map.Entry::getValue); }
From source file:com.facebook.swift.service.ThriftServiceProcessor.java
public ThriftServiceProcessor(ThriftCodecManager codecManager, List<Object> services) { Preconditions.checkNotNull(codecManager, "codecManager is null"); Preconditions.checkNotNull(services, "service is null"); Preconditions.checkArgument(!services.isEmpty(), "services is empty"); // NOTE: ImmutableMap enforces that we don't have duplicate method names ImmutableMap.Builder<String, ThriftMethodProcessor> processorBuilder = ImmutableMap.builder(); ImmutableMultimap.Builder<String, ThriftMethodStats> statsBuilder = ImmutableMultimap.builder(); for (Object service : services) { ThriftServiceMetadata serviceMetadata = new ThriftServiceMetadata(service.getClass(), codecManager.getCatalog()); for (ThriftMethodMetadata methodMetadata : serviceMetadata.getMethods().values()) { ThriftMethodProcessor methodProcessor = new ThriftMethodProcessor(service, methodMetadata, codecManager);//from w w w . j av a 2 s . c o m processorBuilder.put(methodMetadata.getName(), methodProcessor); statsBuilder.put(serviceMetadata.getName(), methodProcessor.getStats()); } } methods = processorBuilder.build(); serviceStats = statsBuilder.build(); }
From source file:com.github.nmorel.gwtjackson.guava.client.deser.BaseImmutableMultimapJsonDeserializer.java
/** * Build the {@link ImmutableMultimap} using the given builder. * * @param reader {@link JsonReader} used to read the JSON input * @param ctx Context for the full deserialization process * @param params Parameters for this deserialization * @param builder {@link ImmutableMultimap.Builder} used to collect the entries *//*from ww w . ja v a 2 s. c o m*/ protected void buildMultimap(JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params, ImmutableMultimap.Builder<K, V> builder) { reader.beginObject(); while (JsonToken.END_OBJECT != reader.peek()) { String name = reader.nextName(); K key = keyDeserializer.deserialize(name, ctx); reader.beginArray(); while (JsonToken.END_ARRAY != reader.peek()) { V value = valueDeserializer.deserialize(reader, ctx, params); builder.put(key, value); } reader.endArray(); } reader.endObject(); }
From source file:net.minecrell.ice.launch.transformers.AccessTransformer.java
protected AccessTransformer(String file) throws IOException { checkNotNull(file, "file"); ImmutableMultimap.Builder<String, Modifier> builder = ImmutableListMultimap.builder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader( getClass().getClassLoader().getResourceAsStream(file), StandardCharsets.UTF_8))) { String line;/*from www.java2 s .co m*/ while ((line = reader.readLine()) != null) { line = substringBefore(line, '#').trim(); if (line.isEmpty()) { continue; } List<String> parts = SEPARATOR.splitToList(line); checkArgument(parts.size() <= 3, "Invalid access transformer config line: " + line); String name = null; String desc = null; boolean isClass = parts.size() == 2; if (!isClass) { name = parts.get(2); int pos = name.indexOf('('); if (pos >= 0) { desc = name.substring(pos); name = name.substring(0, pos); } } String s = parts.get(0); int access = 0; if (s.startsWith("public")) { access = ACC_PUBLIC; } else if (s.startsWith("protected")) { access = ACC_PROTECTED; } else if (s.startsWith("private")) { access = ACC_PRIVATE; } Boolean markFinal = null; if (s.endsWith("+f")) { markFinal = true; } else if (s.endsWith("-f")) { markFinal = false; } String className = parts.get(1).replace('/', '.'); builder.put(className, new Modifier(name, desc, isClass, access, markFinal)); } } this.modifiers = builder.build(); }
From source file:net.hydromatic.optiq.impl.java.ReflectiveSchema.java
@Override protected Multimap<String, TableFunction> getTableFunctionMultimap() { final ImmutableMultimap.Builder<String, TableFunction> builder = ImmutableMultimap.builder(); for (Method method : clazz.getMethods()) { final String methodName = method.getName(); if (method.getDeclaringClass() == Object.class || methodName.equals("toString")) { continue; }/*from www .j a v a2s .co m*/ final TableFunction tableFunction = methodMember(method); builder.put(methodName, tableFunction); } return builder.build(); }
From source file:org.jclouds.json.internal.IgnoreNullMultimapTypeAdapterFactory.java
private <K, V> TypeAdapter<Multimap<K, V>> newMapAdapter(final TypeAdapter<K> keyAdapter, final TypeAdapter<V> valueAdapter) { return new TypeAdapter<Multimap<K, V>>() { public void write(JsonWriter out, Multimap<K, V> map) throws IOException { out.beginObject();// w w w .j av a2 s .c o m for (K key : map.keySet()) { out.name(String.valueOf(key)); out.beginArray(); for (V value : map.get(key)) { valueAdapter.write(out, value); } out.endArray(); } out.endObject(); } public Multimap<K, V> read(JsonReader in) throws IOException { ImmutableMultimap.Builder<K, V> result = ImmutableListMultimap.builder(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); K name = keyAdapter.read(in); in.beginArray(); while (in.hasNext()) { V value = valueAdapter.read(in); if (value != null) result.put(name, value); } in.endArray(); } in.endObject(); return result.build(); } }.nullSafe(); }
From source file:com.facebook.buck.cxx.CxxPreprocessorInput.java
public static CxxPreprocessorInput concat(Iterable<CxxPreprocessorInput> inputs) { ImmutableSet.Builder<BuildTarget> rules = ImmutableSet.builder(); ImmutableMultimap.Builder<CxxSource.Type, String> preprocessorFlags = ImmutableMultimap.builder(); ImmutableCxxHeaders.Builder includes = ImmutableCxxHeaders.builder(); ImmutableList.Builder<Path> includeRoots = ImmutableList.builder(); ImmutableList.Builder<Path> systemIncludeRoots = ImmutableList.builder(); for (CxxPreprocessorInput input : inputs) { rules.addAll(input.getRules());/*from w ww. j a v a 2 s. co m*/ preprocessorFlags.putAll(input.getPreprocessorFlags()); includes.putAllNameToPathMap(input.getIncludes().nameToPathMap()); includes.putAllFullNameToPathMap(input.getIncludes().fullNameToPathMap()); includeRoots.addAll(input.getIncludeRoots()); systemIncludeRoots.addAll(input.getSystemIncludeRoots()); } return new CxxPreprocessorInput(rules.build(), preprocessorFlags.build(), includes.build(), includeRoots.build(), systemIncludeRoots.build()); }
From source file:org.tensorics.core.tensor.operations.OngoingMapOut.java
private static <T, C, C1 extends C> Multimap<Set<?>, Entry<Position, T>> groupBy( Iterable<Entry<Position, T>> entries, Class<C1> dimension) { ImmutableMultimap.Builder<Set<?>, Entry<Position, T>> fullEntriesBuilder = ImmutableMultimap.builder(); for (Entry<Position, T> entry : entries) { Collection<?> coordinates = entry.getKey().coordinates(); fullEntriesBuilder.put(OngoingMapOut.coordinatesExcept(coordinates, dimension), entry); }/*from ww w .ja v a2 s.c o m*/ return fullEntriesBuilder.build(); }