List of usage examples for com.google.common.collect ImmutableMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.wrmsr.kleist.util.collect.MoreCollectors.java
public static <I, K, V> Collector<I, ImmutableMultimap.Builder<K, V>, ImmutableMultimap<K, V>> toImmutableMultimap( Function<I, K> keyMapper, Function<I, V> valueMapper) { return Collector.of(ImmutableMultimap::builder, (builder, in) -> builder.put(keyMapper.apply(in), valueMapper.apply(in)), (ImmutableMultimap.Builder<K, V> left, ImmutableMultimap.Builder<K, V> right) -> left .putAll(right.build()), ImmutableMultimap.Builder::build); }
From source file:me.emily.config.ProtocolConfig.java
private Multimap<Integer, RawNumericReciever> rawRecievers() { // Multimap<Integer, RawNumericReciever> ret = Multimaps. Builder<Integer, RawNumericReciever> builder = ImmutableMultimap.builder(); String packageName = RawNumericReciever.class.getPackage().getName(); Reflections r = new Reflections( new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(packageName))); for (Class<? extends RawNumericReciever> clazz : r.getSubTypesOf(RawNumericReciever.class)) { try {//w ww . ja v a 2 s.c o m RawNumericReciever newInstance = clazz.newInstance(); RawNumeric numeric = clazz.getAnnotation(RawNumeric.class); checkState(numeric != null, "%s does not have a %s numeric definition!", clazz.getName(), RawNumeric.class.getSimpleName()); for (int num : numeric.value()) { builder.put(num, newInstance); } } catch (Exception e) { log.error("Failed to load raw numeric parser {}", clazz.getName()); Throwables.propagate(e); } } return builder.build(); }
From source file:org.sosy_lab.cpachecker.cpa.bounds.BoundsTransferRelation.java
public BoundsTransferRelation(int pLoopIterationsBeforeAbstraction, int pMaxLoopIterations, int pMaxRecursionDepth, LoopStructure pLoops) { loopIterationsBeforeAbstraction = pLoopIterationsBeforeAbstraction; this.maxLoopIterations = pMaxLoopIterations; this.maxRecursionDepth = pMaxRecursionDepth; ImmutableMultimap.Builder<CFANode, Loop> heads = ImmutableMultimap.builder(); for (Loop l : pLoops.getAllLoops()) { for (CFANode h : l.getLoopHeads()) { heads.put(h, l);//from w w w .j a v a2 s . com } } loopHeads = heads.build(); }
From source file:org.jetbrains.jet.lang.resolve.java.kotlinSignature.JavaToKotlinMethodMap.java
static void put(ImmutableMultimap.Builder<String, ClassData> builder, String javaFqName, String kotlinQualifiedName, Pair<String, String>... methods2Functions) { ImmutableMap<String, String> methods2FunctionsMap = pairs2Map(methods2Functions); ClassDescriptor kotlinClass;//ww w . j a v a2 s .c o m if (kotlinQualifiedName.contains(".")) { // Map.Entry and MutableMap.MutableEntry String[] kotlinNames = kotlinQualifiedName.split("\\."); assert kotlinNames.length == 2 : "unexpected qualified name " + kotlinQualifiedName; ClassDescriptor outerClass = KotlinBuiltIns.getInstance() .getBuiltInClassByName(Name.identifier(kotlinNames[0])); kotlinClass = DescriptorUtils.getInnerClassByName(outerClass, kotlinNames[1]); assert kotlinClass != null : "Class not found: " + kotlinQualifiedName; } else { kotlinClass = KotlinBuiltIns.getInstance().getBuiltInClassByName(Name.identifier(kotlinQualifiedName)); } builder.put(javaFqName, new ClassData(kotlinClass, methods2FunctionsMap)); }
From source file:co.cask.cdap.data.stream.service.InMemoryStreamMetaStore.java
@Override public synchronized Multimap<Id.Namespace, StreamSpecification> listStreams() throws Exception { ImmutableMultimap.Builder<Id.Namespace, StreamSpecification> builder = ImmutableMultimap.builder(); for (String namespaceId : streams.keySet()) { synchronized (streams) { Collection<String> streamNames = streams.get(namespaceId); builder.putAll(Id.Namespace.from(namespaceId), Collections2.transform(streamNames, new Function<String, StreamSpecification>() { @Nullable/*from w w w . ja v a 2 s.co m*/ @Override public StreamSpecification apply(String input) { return new StreamSpecification.Builder().setName(input).create(); } })); } } return builder.build(); }
From source file:net.minecrell.quartz.mappings.loader.Mappings.java
public static Mapper createMapper(Map<String, MappedClass> mappings) { ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); ImmutableTable.Builder<String, String, AccessTransform> accessTransforms = ImmutableTable.builder(); ImmutableMultimap.Builder<String, MethodNode> constructors = ImmutableMultimap.builder(); for (Map.Entry<String, MappedClass> entry : mappings.entrySet()) { String internalName = entry.getKey(); String className = internalName.replace('/', '.'); MappedClass mapping = entry.getValue(); String mappedName = mapping.getName(); classes.put(mappedName, internalName); if (mapping.hasMethods()) { fillTable(methods, mappedName, mapping.getMethods()); }// w ww. jav a2 s.c om if (mapping.hasFields()) { fillTable(fields, mappedName, mapping.getFields()); } if (mapping.hasAccess()) { fillTable(accessTransforms, className, mapping.getAccess()); } } return new Mapper(classes.build(), methods.build(), fields.build(), accessTransforms.build()); }
From source file:com.facebook.buck.rules.keys.DefaultDependencyFileRuleKeyBuilderFactory.java
@Override public RuleKey build(BuildRule rule, ImmutableList<Path> inputs) throws IOException { // Create a builder which records all `SourcePath`s which are possibly used by the rule. Builder builder = newInstance(rule); // Use a multi-map to gather up all the `SourcePath`s that have relative paths that are // referenced in the input list, as it's possible for multiple `SourcePath`s to have the // same relative path (but come from different cells). ImmutableSet<Path> inputSet = ImmutableSet.copyOf(inputs); ImmutableMultimap.Builder<Path, SourcePath> relativePathToSourcePathsBuilder = ImmutableMultimap.builder(); for (SourcePath input : builder.getInputsSoFar()) { Path relativePath = pathResolver.getRelativePath(input); if (inputSet.contains(relativePath)) { relativePathToSourcePathsBuilder.put(relativePath, input); }/* w w w. j a va2 s . c o m*/ } final ImmutableMultimap<Path, SourcePath> relativePathToSourcePaths = relativePathToSourcePathsBuilder .build(); // Now add the actual given inputs to the rule key using all possible `SourcePath`s they map to. // It's important that we do this by walking the `inputs` list, so that we maintain the original // ordering the duplicate handling. for (Path input : inputs) { ImmutableCollection<SourcePath> sourcePaths = relativePathToSourcePaths.get(input); // If we don't find actual inputs in the rule that correspond to this input, this likely means // that the rule changed to no longer use the input. In this case, we need to throw a // `NoSuchFileException` error so that the build engine handles this as a signal that the dep // file rule key can't be used. if (sourcePaths.isEmpty()) { throw new NoSuchFileException( String.format("%s: could not find any inputs matching the relative path `%s`", rule.getBuildTarget(), input)); } // Add each `SourcePath` using `builder.setPath()`. We can't use `builder.setSourcePath()` // here since the special `RuleKeyBuilder` sub-class that dep-file rule keys use intentionally // override `builder.setSourcePath()` to be a noop (and just record the inputs). for (SourcePath sourcePath : sourcePaths) { builder.setPath(pathResolver.getAbsolutePath(sourcePath), pathResolver.getRelativePath(sourcePath)); } } return builder.build(); }
From source file:org.gradle.internal.execution.history.impl.FileCollectionFingerprintSerializer.java
private ImmutableMultimap<String, HashCode> readRootHashes(Decoder decoder) throws IOException { int numberOfRoots = decoder.readSmallInt(); if (numberOfRoots == 0) { return ImmutableMultimap.of(); }/*from w ww. j a v a 2s . c o m*/ ImmutableMultimap.Builder<String, HashCode> builder = ImmutableMultimap.builder(); for (int i = 0; i < numberOfRoots; i++) { String absolutePath = stringInterner.intern(decoder.readString()); HashCode rootHash = hashCodeSerializer.read(decoder); builder.put(absolutePath, rootHash); } return builder.build(); }
From source file:ratpack.test.http.internal.DefaultTestHttpClient.java
@Override public TestHttpClient params(Action<? super ImmutableMultimap.Builder<String, Object>> params) { this.params = params; return this; }
From source file:co.paralleluniverse.comsat.webactors.undertow.HttpRequestWrapper.java
@Override public Multimap<String, String> getParameters() { if (params == null) { final ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); final Map<String, Deque<String>> parameters = xch.getQueryParameters(); for (final String k : parameters.keySet()) builder.putAll(k, parameters.get(k)); params = builder.build();/*from ww w . j a v a 2 s . c o m*/ } return params; }