List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:com.publictransitanalytics.scoregenerator.Main.java
private static Set<Center> getAllCenters(final Grid grid) { final ImmutableSet.Builder<Center> builder = ImmutableSet.builder(); for (final Sector sector : grid.getReachableSectors()) { builder.add(new Center(sector, grid.getGridPoints(sector))); }//from w w w . j a v a2s. c o m return builder.build(); }
From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsReflector.java
/** * Retrieve metadata for the full set of pipeline options visible within the type hierarchy * of a single {@link PipelineOptions} interface. * * @see PipelineOptionsReflector#getOptionSpecs(Iterable) *///from w w w . j ava 2 s . c om static Set<PipelineOptionSpec> getOptionSpecs(Class<? extends PipelineOptions> optionsInterface) { Iterable<Method> methods = ReflectHelpers.getClosureOfMethodsOnInterface(optionsInterface); Multimap<String, Method> propsToGetters = getPropertyNamesToGetters(methods); ImmutableSet.Builder<PipelineOptionSpec> setBuilder = ImmutableSet.builder(); for (Map.Entry<String, Method> propAndGetter : propsToGetters.entries()) { String prop = propAndGetter.getKey(); Method getter = propAndGetter.getValue(); @SuppressWarnings("unchecked") Class<? extends PipelineOptions> declaringClass = (Class<? extends PipelineOptions>) getter .getDeclaringClass(); if (!PipelineOptions.class.isAssignableFrom(declaringClass)) { continue; } if (declaringClass.isAnnotationPresent(Hidden.class)) { continue; } setBuilder.add(PipelineOptionSpec.of(declaringClass, prop, getter)); } return setBuilder.build(); }
From source file:org.apache.crunch.io.hbase.HFileUtils.java
private static <C> List<KeyValue> getSplitPoints(HTable table, PTable<C, Void> affectedRows) throws IOException { List<byte[]> startKeys; try {/* w w w . jav a 2s .co m*/ startKeys = Lists.newArrayList(table.getStartKeys()); if (startKeys.isEmpty()) { throw new AssertionError(table + " has no regions!"); } } catch (IOException e) { throw new CrunchRuntimeException(e); } Collections.sort(startKeys, Bytes.BYTES_COMPARATOR); Iterable<ByteBuffer> bufferedStartKeys = affectedRows .parallelDo(new DetermineAffectedRegionsFn(startKeys), Writables.bytes()).materialize(); // set to get rid of the potential duplicate start keys emitted ImmutableSet.Builder<KeyValue> startKeyBldr = ImmutableSet.builder(); for (final ByteBuffer bufferedStartKey : bufferedStartKeys) { startKeyBldr.add(KeyValueUtil.createFirstOnRow(bufferedStartKey.array())); } return ImmutableList.copyOf(startKeyBldr.build()); }
From source file:com.facebook.presto.operator.annotations.FunctionsParserHelper.java
@SafeVarargs public static Set<Method> findPublicMethodsWithAnnotation(Class<?> clazz, Class<? extends Annotation>... annotationClasses) { ImmutableSet.Builder<Method> methods = ImmutableSet.builder(); for (Method method : clazz.getDeclaredMethods()) { for (Annotation annotation : method.getAnnotations()) { for (Class<?> annotationClass : annotationClasses) { if (annotationClass.isInstance(annotation)) { checkArgument(Modifier.isPublic(method.getModifiers()), "Method [%s] annotated with @%s must be public", method, annotationClass.getSimpleName()); methods.add(method); }/*from ww w . j av a 2 s . c o m*/ } } } return methods.build(); }
From source file:com.facebook.presto.operator.aggregation.AggregationFromAnnotationsParser.java
private static Set<Class<?>> getStateClasses(Class<?> clazz) { ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder(); for (Method inputFunction : FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class)) { checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters"); Class<?> stateClass = AggregationImplementation.Parser.findAggregationStateParamType(inputFunction); checkArgument(AccumulatorState.class.isAssignableFrom(stateClass), "stateClass is not a subclass of AccumulatorState"); builder.add(stateClass); }//from w w w .j a va 2s . c om ImmutableSet<Class<?>> stateClasses = builder.build(); checkArgument(!stateClasses.isEmpty(), "No input functions found"); return stateClasses; }
From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.BaseRequestGenerator.java
/** * Gets the required imports that are needed to ensure that all generated models * within the this Ds3Param list are included in the request generated Java code * @param ds3Params A list of Ds3Params/*from w w w. j a va 2 s .co m*/ * @return The list of imports necessary for including all generated models within * the Ds3Params list */ protected static ImmutableSet<String> getImportsFromParamList(final ImmutableList<Ds3Param> ds3Params) { if (isEmpty(ds3Params)) { return ImmutableSet.of(); } final ImmutableSet.Builder<String> importsBuilder = ImmutableSet.builder(); for (final Ds3Param ds3Param : ds3Params) { if (!ds3Param.getName().equals("Operation") && ds3Param.getType().contains(".") && !ds3Param.getType().equals("java.lang.String")) { importsBuilder.add(ConvertType.toModelName(ds3Param.getType())); } if (ds3Param.getType().endsWith("String") || ds3Param.getType().endsWith("UUID")) { importsBuilder.add("com.google.common.net.UrlEscapers"); } } return importsBuilder.build(); }
From source file:it.unibz.inf.ontop.owlrefplatform.core.translator.SparqlAlgebraToDatalogTranslator.java
private static Term getTermForVariable(Var v, ImmutableSet.Builder<Variable> variables) { Variable var = ofac.getVariable(v.getName()); variables.add(var); return var; }
From source file:com.facebook.buck.android.CopyNativeLibraries.java
public static void copyNativeLibrary(final ProjectFilesystem filesystem, Path sourceDir, final Path destinationDir, ImmutableSet<TargetCpuType> cpuFilters, ImmutableList.Builder<Step> steps) { if (cpuFilters.isEmpty()) { steps.add(CopyStep.forDirectory(filesystem, sourceDir, destinationDir, CopyStep.DirectoryMode.CONTENTS_ONLY)); } else {//from w w w.j av a 2 s.c o m for (TargetCpuType cpuType : cpuFilters) { Optional<String> abiDirectoryComponent = getAbiDirectoryComponent(cpuType); Preconditions.checkState(abiDirectoryComponent.isPresent()); final Path libSourceDir = sourceDir.resolve(abiDirectoryComponent.get()); Path libDestinationDir = destinationDir.resolve(abiDirectoryComponent.get()); final MkdirStep mkDirStep = new MkdirStep(filesystem, libDestinationDir); final CopyStep copyStep = CopyStep.forDirectory(filesystem, libSourceDir, libDestinationDir, CopyStep.DirectoryMode.CONTENTS_ONLY); steps.add(new Step() { @Override public StepExecutionResult execute(ExecutionContext context) { // TODO(shs96c): Using a projectfilesystem here is almost definitely wrong. // This is because each library may come from different build rules, which may be in // different cells --- this check works by coincidence. if (!filesystem.exists(libSourceDir)) { return StepExecutionResult.SUCCESS; } if (mkDirStep.execute(context).isSuccess() && copyStep.execute(context).isSuccess()) { return StepExecutionResult.SUCCESS; } return StepExecutionResult.ERROR; } @Override public String getShortName() { return "copy_native_libraries"; } @Override public String getDescription(ExecutionContext context) { ImmutableList.Builder<String> stringBuilder = ImmutableList.builder(); stringBuilder.add(String.format("[ -d %s ]", libSourceDir.toString())); stringBuilder.add(mkDirStep.getDescription(context)); stringBuilder.add(copyStep.getDescription(context)); return Joiner.on(" && ").join(stringBuilder.build()); } }); } } // Rename native files named like "*-disguised-exe" to "lib*.so" so they will be unpacked // by the Android package installer. Then they can be executed like normal binaries // on the device. steps.add(new AbstractExecutionStep("rename_native_executables") { @Override public StepExecutionResult execute(ExecutionContext context) { final ImmutableSet.Builder<Path> executablesBuilder = ImmutableSet.builder(); try { filesystem.walkRelativeFileTree(destinationDir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.toString().endsWith("-disguised-exe")) { executablesBuilder.add(file); } return FileVisitResult.CONTINUE; } }); for (Path exePath : executablesBuilder.build()) { Path fakeSoPath = Paths.get(MorePaths.pathWithUnixSeparators(exePath) .replaceAll("/([^/]+)-disguised-exe$", "/lib$1.so")); filesystem.move(exePath, fakeSoPath); } } catch (IOException e) { context.logError(e, "Renaming native executables failed."); return StepExecutionResult.ERROR; } return StepExecutionResult.SUCCESS; } }); }
From source file:com.facebook.buck.rules.AndroidResourceRule.java
private static ImmutableSet<AndroidResourceRule> findAllAndroidResourceDeps(BuildRule buildRule) { final ImmutableSet.Builder<AndroidResourceRule> androidResources = ImmutableSet.builder(); AbstractDependencyVisitor visitor = new AbstractDependencyVisitor(buildRule) { @Override/*from w w w. ja va2 s. c o m*/ public boolean visit(BuildRule rule) { if (rule instanceof AndroidResourceRule) { AndroidResourceRule androidResourceRule = (AndroidResourceRule) rule; if (androidResourceRule.getRes() != null) { androidResources.add(androidResourceRule); } } // Only certain types of rules should be considered as part of this traversal. BuildRuleType type = rule.getType(); return TRAVERSABLE_TYPES.contains(type); } }; visitor.start(); return androidResources.build(); }
From source file:com.spotify.docker.client.CompressedDirectory.java
static ImmutableSet<PathMatcher> parseDockerIgnore(Path dockerIgnorePath) throws IOException { final ImmutableSet.Builder<PathMatcher> matchersBuilder = ImmutableSet.builder(); if (Files.isReadable(dockerIgnorePath) && Files.isRegularFile(dockerIgnorePath)) { for (final String line : Files.readAllLines(dockerIgnorePath, StandardCharsets.UTF_8)) { final String pattern = line.trim(); if (pattern.isEmpty()) { log.debug("Will skip '{}' - cause it's empty after trimming", line); continue; }/*ww w.ja v a 2s .c o m*/ matchersBuilder.add(goPathMatcher(dockerIgnorePath.getFileSystem(), pattern)); } } return matchersBuilder.build(); }