List of usage examples for com.google.common.collect ImmutableSetMultimap builder
public static <K, V> Builder<K, V> builder()
From source file:com.bitranger.parknshop.common.recommend.util.ClassDirectory.java
public static ClassDirectory forClassLoader(ClassLoader loader) { ImmutableSetMultimap.Builder<String, String> mapping = ImmutableSetMultimap.builder(); try {/*from w ww .j a v a 2 s . c om*/ Enumeration<URL> urls = loader.getResources("WEB-INF/classes.lst"); // while (urls.hasMoreElements()) { // URL url = urls.nextElement(); // Double closer = Closer.create(); // try { // InputStream stream = closer.register(url.openStream()); // Reader rdr = closer.register(new InputStreamReader(stream, "UTF-8")); // BufferedReader buf = closer.register(new BufferedReader(rdr)); // String line = buf.readLine(); // while (line != null) { // int idx = line.lastIndexOf('.'); // if (idx >= 0) { // String name = line.substring(idx + 1); // String pkg = line.substring(0, idx); // mapping.put(name, pkg); // } // line = buf.readLine(); // } // } catch (Throwable th) { // throw closer.rethrow(th); // } finally { // closer.close(); // } // } } catch (IOException e) { throw new RuntimeException("Error loading class lists", e); } return new ClassDirectory(mapping.build()); }
From source file:com.facebook.buck.java.JavaLibraryClasspathProvider.java
public static ImmutableSetMultimap<JavaLibrary, Path> getOutputClasspathEntries( DefaultJavaLibrary javaLibraryRule, Optional<Path> outputJar) { ImmutableSetMultimap.Builder<JavaLibrary, Path> outputClasspathBuilder = ImmutableSetMultimap.builder(); Iterable<JavaLibrary> javaExportedLibraryDeps = getJavaLibraryDeps(javaLibraryRule.getExportedDeps()); for (JavaLibrary rule : javaExportedLibraryDeps) { outputClasspathBuilder.putAll(rule, rule.getOutputClasspathEntries().values()); // If we have any exported deps, add an entry mapping ourselves to to their, // classpaths so when suggesting libraries to add we know that adding this library // would pull in it's deps. outputClasspathBuilder.putAll(javaLibraryRule, rule.getOutputClasspathEntries().values()); }//from ww w .j a v a 2 s. c om if (outputJar.isPresent()) { outputClasspathBuilder.put(javaLibraryRule, outputJar.get()); } return outputClasspathBuilder.build(); }
From source file:com.codingopus.guava.custom.collectors.ImmutableSetMultimapCollector.java
public static <T, K, V> Collector<T, ?, ImmutableSetMultimap<K, V>> toImmutableSetMultimapCollector( final Function<? super T, ? extends K> keyExtractor, final Function<? super T, ? extends V> valueExtractor) { return Collector.of(ImmutableSetMultimap::builder, (map, val) -> map.put(keyExtractor.apply(val), valueExtractor.apply(val)), (l, r) -> l.putAll(r.build()), ImmutableSetMultimap.Builder<K, V>::build); }
From source file:com.facebook.buck.jvm.java.ClassUsageFile.java
private static ImmutableSetMultimap<Path, Path> relativizeMap(ImmutableSetMultimap<Path, Path> classUsageMap, ProjectFilesystem filesystem) {/*from w ww . ja va 2s.c o m*/ final ImmutableSetMultimap.Builder<Path, Path> builder = ImmutableSetMultimap.builder(); for (Map.Entry<Path, Collection<Path>> jarClassesEntry : classUsageMap.asMap().entrySet()) { Path jarAbsolutePath = jarClassesEntry.getKey(); Path jarRelativePath = filesystem.getRelativizer().apply(jarAbsolutePath); // Don't include jars that are outside of the filesystem if (jarRelativePath.startsWith("..")) { continue; } builder.putAll(jarRelativePath, jarClassesEntry.getValue()); } return builder.build(); }
From source file:com.facebook.buck.rules.Classpaths.java
/** * Include the classpath entries from all JavaLibraryRules that have a direct line of lineage * to this rule through other JavaLibraryRules. For example, in the following dependency graph: * * A/*from ww w . j a va 2 s . c o m*/ * / \ * B C * / \ / \ * D E F G * * If all of the nodes correspond to BuildRules that implement JavaLibraryRule except for * B (suppose B is a Genrule), then A's classpath will include C, F, and G, but not D and E. * This is because D and E are used to generate B, but do not contribute .class files to things * that depend on B. However, if C depended on E as well as F and G, then E would be included in * A's classpath. */ public static ImmutableSetMultimap<BuildRule, String> getClasspathEntries(Set<BuildRule> deps) { final ImmutableSetMultimap.Builder<BuildRule, String> classpathEntries = ImmutableSetMultimap.builder(); for (BuildRule dep : deps) { if (dep instanceof JavaLibraryRule) { JavaLibraryRule libraryRule = (JavaLibraryRule) dep; classpathEntries.putAll(libraryRule.getTransitiveClasspathEntries()); } } return classpathEntries.build(); }
From source file:io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaSetMultimapBuilder.java
ImmutableGuavaSetMultimapBuilder() {
mapContent = ImmutableSetMultimap.builder();
constructedMap = null;
}
From source file:com.facebook.buck.java.Classpaths.java
/** * Include the classpath entries from all JavaLibraryRules that have a direct line of lineage * to this rule through other JavaLibraryRules. For example, in the following dependency graph: * * A/* w ww . j a v a 2 s .c o m*/ * / \ * B C * / \ / \ * D E F G * * If all of the nodes correspond to BuildRules that implement JavaLibraryRule except for * B (suppose B is a Genrule), then A's classpath will include C, F, and G, but not D and E. * This is because D and E are used to generate B, but do not contribute .class files to things * that depend on B. However, if C depended on E as well as F and G, then E would be included in * A's classpath. */ public static ImmutableSetMultimap<JavaLibrary, Path> getClasspathEntries(Set<BuildRule> deps) { final ImmutableSetMultimap.Builder<JavaLibrary, Path> classpathEntries = ImmutableSetMultimap.builder(); for (BuildRule dep : deps) { JavaLibrary library = null; if (dep.getBuildable() instanceof JavaLibrary) { library = (JavaLibrary) dep.getBuildable(); } else if (dep instanceof JavaLibrary) { library = (JavaLibrary) dep; } if (library != null) { classpathEntries.putAll(library.getTransitiveClasspathEntries()); } } return classpathEntries.build(); }
From source file:com.facebook.buck.jvm.java.Classpaths.java
/** * Include the classpath entries from all JavaLibraryRules that have a direct line of lineage * to this rule through other JavaLibraryRules. For example, in the following dependency graph: * * A/*from w ww.j ava2s. com*/ * / \ * B C * / \ / \ * D E F G * * If all of the nodes correspond to BuildRules that implement JavaLibraryRule except for * B (suppose B is a Genrule), then A's classpath will include C, F, and G, but not D and E. * This is because D and E are used to generate B, but do not contribute .class files to things * that depend on B. However, if C depended on E as well as F and G, then E would be included in * A's classpath. */ public static ImmutableSetMultimap<JavaLibrary, Path> getClasspathEntries(Set<BuildRule> deps) { final ImmutableSetMultimap.Builder<JavaLibrary, Path> classpathEntries = ImmutableSetMultimap.builder(); for (BuildRule dep : deps) { JavaLibrary library = null; if (dep instanceof JavaLibrary) { library = (JavaLibrary) dep; } if (library != null) { classpathEntries.putAll(library.getTransitiveClasspathEntries()); } } return classpathEntries.build(); }
From source file:com.google.devtools.build.xcode.xcodegen.Xcdatamodels.java
public static Xcdatamodels fromTargetControls(FileSystem fileSystem, PBXBuildFiles pbxBuildFiles, Iterable<TargetControl> targetControls) { ImmutableSetMultimap.Builder<TargetControl, PBXBuildFile> targetLabelToBuildFiles = new ImmutableSetMultimap.Builder<>(); for (TargetControl targetControl : targetControls) { Iterable<PBXBuildFile> targetBuildFiles = pbxBuildFiles.get(AggregateReferenceType.XCVersionGroup, RelativePaths.fromStrings(fileSystem, targetControl.getXcdatamodelList())); // If this target is not a static library, save the build files. If it's a static lib, we // don't need them. The file references we generated with fileObjects will be added to the // main group later. if (!Equaling.of(ProductType.STATIC_LIBRARY, XcodeprojGeneration.productType(targetControl))) { targetLabelToBuildFiles.putAll(targetControl, targetBuildFiles); }//from www .jav a2s .c om } return new Xcdatamodels(targetLabelToBuildFiles.build()); }
From source file:org.immutables.value.processor.meta.CaseStructure.java
private static SetMultimap<String, ValueType> buildSubtyping(List<ValueType> implementationTypes) { ImmutableSetMultimap.Builder<String, ValueType> builder = ImmutableSetMultimap.builder(); for (ValueType type : implementationTypes) { String abstractValueTypeName = type.typeAbstract().toString(); builder.put(abstractValueTypeName, type); for (String className : type.getExtendedClassesNames()) { if (!className.equals(abstractValueTypeName)) { builder.put(className, type); }//from www . j av a 2 s . com } for (String interfaceName : type.getImplementedInterfacesNames()) { if (!interfaceName.equals(abstractValueTypeName)) { builder.put(interfaceName, type); } } } return builder.build(); }