List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:io.airlift.event.client.EventTypeMetadata.java
public static Set<EventTypeMetadata<?>> getValidEventTypeMetaDataSet(Class<?>... eventClasses) { ImmutableSet.Builder<EventTypeMetadata<?>> set = ImmutableSet.builder(); for (Class<?> eventClass : eventClasses) { set.add(getValidEventTypeMetadata(eventClass)); }/*from w ww . j a v a2s . c o m*/ return set.build(); }
From source file:com.facebook.buck.query.QueryTargetAccessor.java
public static <T> ImmutableSet<QueryTarget> getTargetsInAttribute(TargetNode<T, ?> node, String attribute) { try {// ww w.j a va 2s . com final ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder(); Class<?> constructorArgClass = node.getConstructorArg().getClass(); Field field = constructorArgClass.getField(attribute); ParamInfo info = new ParamInfo(typeCoercerFactory, constructorArgClass, field); info.traverse(value -> { if (value instanceof Path) { builder.add(QueryFileTarget.of((Path) value)); } else if (value instanceof SourcePath) { builder.add(extractSourcePath((SourcePath) value)); } else if (value instanceof HasBuildTarget) { builder.add(extractBuildTargetContainer((HasBuildTarget) value)); } }, node.getConstructorArg()); return builder.build(); } catch (NoSuchFieldException e) { // Ignore if the field does not exist in this rule. return ImmutableSet.of(); } }
From source file:com.google.errorprone.bugpatterns.MutableMethodReturnType.java
private static ImmutableSet<ClassType> getMethodReturnTypes(MethodTree methodTree) { ImmutableSet.Builder<ClassType> returnTypes = ImmutableSet.builder(); methodTree.accept(new TreeScanner<Void, Void>() { @Override//from w w w .ja v a 2 s . c om public Void visitReturn(ReturnTree node, Void unused) { Type type = ASTHelpers.getType(node.getExpression()); if (type instanceof ClassType) { returnTypes.add((ClassType) type); } return null; } @Override public Void visitClass(ClassTree tree, Void unused) { // Don't continue into nested classes. return null; } @Override public Void visitLambdaExpression(LambdaExpressionTree tree, Void unused) { // Don't continue into nested lambdas. return null; } }, null /* unused */); return returnTypes.build(); }
From source file:com.google.devtools.build.lib.rules.objc.Xcdatamodels.java
static Iterable<Xcdatamodel> xcdatamodels(IntermediateArtifacts intermediateArtifacts, Iterable<Artifact> xcdatamodels) { ImmutableSet.Builder<Xcdatamodel> result = new ImmutableSet.Builder<>(); Multimap<PathFragment, Artifact> artifactsByContainer = byContainer(xcdatamodels); for (Map.Entry<PathFragment, Collection<Artifact>> modelDirEntry : artifactsByContainer.asMap() .entrySet()) {//from www . jav a 2s .c om PathFragment container = modelDirEntry.getKey(); Artifact outputZip = intermediateArtifacts.compiledMomZipArtifact(container); result.add(new Xcdatamodel(outputZip, ImmutableSet.copyOf(modelDirEntry.getValue()), container)); } return result.build(); }
From source file:org.apache.drill.exec.client.ServerMethod.java
/** * Returns the list of methods supported by the server based on its advertised information. * * @param serverInfos the server information * @return a immutable set of capabilities */// www . ja va2s . c o m static final Set<ServerMethod> getSupportedMethods(Iterable<RpcType> supportedMethods, RpcEndpointInfos serverInfos) { ImmutableSet.Builder<ServerMethod> builder = ImmutableSet.builder(); for (RpcType supportedMethod : supportedMethods) { ServerMethod method = REVERSE_MAPPING.get(supportedMethod); if (method == null) { // The server might have newer methods we don't know how to handle yet. continue; } builder.add(method); } // Fallback to version detection to cover the gap between Drill 1.8.0 and Drill 1.10.0 if (serverInfos == null) { return Sets.immutableEnumSet(builder.build()); } Version serverVersion = UserRpcUtils.getVersion(serverInfos); for (ServerMethod capability : ServerMethod.values()) { if (serverVersion.compareTo(capability.getMinVersion()) >= 0) { builder.add(capability); } } return Sets.immutableEnumSet(builder.build()); }
From source file:org.killbill.billing.plugin.simpletax.config.ConvertionHelpers.java
/** * Converts tax codes to their definitions, preserving the order in which * the are specified.//from ww w. j av a2 s . c o m * * @param names * The comma-separated list of tax codes, identified by their * names. Must not be {@code null}. * @return The set of tax codes names, without any duplicates, in the order * they were listed. May be empty, but never {@code null}. * @throws NullPointerException * when {@code names} is {@code null}. */ @Nonnull public static Set<String> splitTaxCodes(@Nonnull String names) { ImmutableSet.Builder<String> taxCodes = ImmutableSet.builder(); for (String name : split(names, TAX_CODES_SPLIT_SEPARATORS)) { taxCodes.add(name); } return taxCodes.build(); }
From source file:org.caleydo.view.domino.api.model.typed.TypedSets.java
private static MultiTypedSet setOperation(TypedSet[] sets, boolean union, final LoadingCache<Pair<IDType, IDType>, IIDTypeMapper<Integer, Integer>> cache) { if (sets.length == 0) { return new MultiTypedSet(new IDType[0], Collections.<int[]>emptySet()); }/*from w w w . j av a 2 s. c o m*/ final int l = sets.length; Set<List<Integer>> r = new HashSet<>(); IDType[] t = new IDType[l]; for (int i = 0; i < sets.length; ++i) { t[i] = sets[i].getIdType(); fill(sets, i, cache, r, union); } // convert to right structure ImmutableSet.Builder<int[]> r_s = ImmutableSet.builder(); for (List<Integer> ri : r) r_s.add(Ints.toArray(ri)); return new MultiTypedSet(t, r_s.build()); }
From source file:com.facebook.buck.android.AndroidPlatformTarget.java
/** * Given the path to the Android SDK as well as the platform path within the Android SDK, * find all the files needed to create the {@link AndroidPlatformTarget}, assuming that the * organization of the Android SDK conforms to the ordinary directory structure. */// ww w. j a v a2s . c om @VisibleForTesting static AndroidPlatformTarget createFromDefaultDirectoryStructure(String name, AndroidDirectoryResolver androidDirectoryResolver, String platformDirectoryPath, Set<Path> additionalJarPaths, Optional<Path> aaptOverride) { Path androidSdkDir = androidDirectoryResolver.getSdkOrThrow(); if (!androidSdkDir.isAbsolute()) { throw new HumanReadableException("Path to Android SDK must be absolute but was: %s.", androidSdkDir); } Path platformDirectory = androidSdkDir.resolve(platformDirectoryPath); Path androidJar = platformDirectory.resolve("android.jar"); // Add any libraries found in the optional directory under the Android SDK directory. These // go at the head of the bootclasspath before any additional jars. File optionalDirectory = platformDirectory.resolve("optional").toFile(); if (optionalDirectory.exists() && optionalDirectory.isDirectory()) { String[] optionalDirList = optionalDirectory.list(new AddonFilter()); if (optionalDirList != null) { Arrays.sort(optionalDirList); ImmutableSet.Builder<Path> additionalJars = ImmutableSet.builder(); for (String file : optionalDirList) { additionalJars.add(optionalDirectory.toPath().resolve(file)); } additionalJars.addAll(additionalJarPaths); additionalJarPaths = additionalJars.build(); } } LinkedList<Path> bootclasspathEntries = Lists.newLinkedList(additionalJarPaths); // Make sure android.jar is at the front of the bootclasspath. bootclasspathEntries.addFirst(androidJar); // This is the directory under the Android SDK directory that contains the dx script, jack, // jill, and binaries. Path buildToolsDir = androidDirectoryResolver.getBuildToolsOrThrow(); // This is the directory under the Android SDK directory that contains the aapt, aidl, and // zipalign binaries. Before Android SDK Build-tools 23.0.0_rc1, this was the same as // buildToolsDir above. Path buildToolsBinDir; if (buildToolsDir.resolve("bin").toFile().exists()) { // Android SDK Build-tools >= 23.0.0_rc1 have executables under a new bin directory. buildToolsBinDir = buildToolsDir.resolve("bin"); } else { // Android SDK Build-tools < 23.0.0_rc1 have executables under the build-tools directory. buildToolsBinDir = buildToolsDir; } Path zipAlignExecutable = androidSdkDir.resolve("tools/zipalign").toAbsolutePath(); if (!zipAlignExecutable.toFile().exists()) { // Android SDK Build-tools >= 19.1.0 have zipalign under the build-tools directory. zipAlignExecutable = androidSdkDir.resolve(buildToolsBinDir).resolve("zipalign").toAbsolutePath(); } Path androidFrameworkIdlFile = platformDirectory.resolve("framework.aidl"); Path proguardJar = androidSdkDir.resolve("tools/proguard/lib/proguard.jar"); Path proguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android.txt"); Path optimizedProguardConfig = androidSdkDir.resolve("tools/proguard/proguard-android-optimize.txt"); return new AndroidPlatformTarget(name, androidJar.toAbsolutePath(), bootclasspathEntries, aaptOverride.orElse(androidSdkDir.resolve(buildToolsBinDir).resolve("aapt").toAbsolutePath()), androidSdkDir.resolve("platform-tools/adb").toAbsolutePath(), androidSdkDir.resolve(buildToolsBinDir).resolve("aidl").toAbsolutePath(), zipAlignExecutable, buildToolsDir.resolve(Platform.detect() == Platform.WINDOWS ? "dx.bat" : "dx").toAbsolutePath(), androidFrameworkIdlFile, proguardJar, proguardConfig, optimizedProguardConfig, androidDirectoryResolver); }
From source file:com.facebook.buck.cli.PathArguments.java
/** * Filter files under the project root, and convert to canonical relative path style. * For example, the project root is /project, * 1. file path /project/./src/com/facebook/./test/../Test.java will be converted to * src/com/facebook/Test.java/*from www.j a va 2 s . c om*/ * 2. file path /otherproject/src/com/facebook/Test.java will be ignored. */ static ReferencedFiles getCanonicalFilesUnderProjectRoot(Path projectRoot, Iterable<String> nonCanonicalFilePaths) throws IOException { // toRealPath() is used throughout to resolve symlinks or else the Path.startsWith() check will // not be reliable. ImmutableSet.Builder<Path> projectFiles = ImmutableSet.builder(); ImmutableSet.Builder<Path> nonProjectFiles = ImmutableSet.builder(); Path normalizedRoot = projectRoot.toRealPath(); for (String filePath : nonCanonicalFilePaths) { Path canonicalFullPath = Paths.get(filePath); if (!canonicalFullPath.isAbsolute()) { canonicalFullPath = projectRoot.resolve(canonicalFullPath); } if (!canonicalFullPath.toFile().exists()) { nonProjectFiles.add(canonicalFullPath); continue; } canonicalFullPath = canonicalFullPath.toRealPath(); // Ignore files that aren't under project root. if (canonicalFullPath.startsWith(normalizedRoot)) { Path relativePath = canonicalFullPath.subpath(normalizedRoot.getNameCount(), canonicalFullPath.getNameCount()); projectFiles.add(relativePath); } else { nonProjectFiles.add(canonicalFullPath); } } return new ReferencedFiles(projectFiles.build(), nonProjectFiles.build()); }
From source file:org.graylog2.indexer.results.HighlightParser.java
private static Set<Range<Integer>> extractRange(List<String> highlights) { final ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder(); highlights.forEach(highlight -> { final Matcher matcher = highlightPattern.matcher(highlight); Integer count = -1;/*from w ww . ja va 2s. c om*/ while (matcher.find()) { count++; final Integer start = matcher.start() - count * (startTokenLength + endTokenLength); final Integer end = start + (matcher.end(1) - matcher.start(1)); builder.add(Range.closed(start, end)); } }); return builder.build(); }