List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:google.registry.tools.GetLrpTokenCommand.java
@Override public void run() throws Exception { checkArgument((tokenString == null) == (assignee != null), "Exactly one of either token or assignee must be specified."); ImmutableSet.Builder<LrpTokenEntity> tokensBuilder = new ImmutableSet.Builder<>(); if (tokenString != null) { LrpTokenEntity token = ofy().load().key(Key.create(LrpTokenEntity.class, tokenString)).now(); if (token != null) { tokensBuilder.add(token);/*from w ww.j a v a 2 s . c om*/ } } else { tokensBuilder.addAll(ofy().load().type(LrpTokenEntity.class).filter("assignee", assignee)); } ImmutableSet<LrpTokenEntity> tokens = tokensBuilder.build(); if (!tokens.isEmpty()) { for (LrpTokenEntity token : tokens) { System.out.println(token); if (includeHistory && token.getRedemptionHistoryEntry() != null) { System.out .println(ofy().load().key(token.getRedemptionHistoryEntry()).now().toHydratedString()); } } } else { System.out.println("Token not found."); } }
From source file:com.google.devtools.build.lib.runtime.CommandNameCacheImpl.java
@Override public ImmutableSet<String> get(String commandName) { ImmutableSet<String> cachedResult = cache.get(commandName); if (cachedResult != null) { return cachedResult; }//w w w . j av a2 s .c o m ImmutableSet.Builder<String> builder = ImmutableSet.builder(); Command command = Preconditions.checkNotNull(commandMap.get(commandName), commandName); Set<Command> visited = new HashSet<>(); visited.add(command); Queue<Command> queue = new ArrayDeque<>(); queue.add(command); while (!queue.isEmpty()) { Command cur = queue.remove(); builder.add(cur.name()); for (Class<? extends BlazeCommand> clazz : cur.inherits()) { Command parent = clazz.getAnnotation(Command.class); if (visited.add(parent)) { queue.add(parent); } } } cachedResult = builder.build(); cache.put(commandName, cachedResult); return cachedResult; }
From source file:org.apache.sentry.provider.file.Roles.java
public ImmutableSet<String> getRoles(@Nullable String database, String group, Boolean isURI) { ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder(); String allowURIPerDbFile = System.getProperty(SimplePolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE); Boolean consultPerDbRolesForURI = isURI && ("true".equalsIgnoreCase(allowURIPerDbFile)); if (database != null) { ImmutableSetMultimap<String, String> dbPolicies = perDatabaseRoles.get(database); if (dbPolicies != null && dbPolicies.containsKey(group)) { resultBuilder.addAll(dbPolicies.get(group)); }// ww w. ja v a 2 s . c o m } if (consultPerDbRolesForURI) { for (String db : perDatabaseRoles.keySet()) { ImmutableSetMultimap<String, String> dbPolicies = perDatabaseRoles.get(db); if (dbPolicies != null && dbPolicies.containsKey(group)) { resultBuilder.addAll(dbPolicies.get(group)); } } } if (globalRoles.containsKey(group)) { resultBuilder.addAll(globalRoles.get(group)); } ImmutableSet<String> result = resultBuilder.build(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Database {}, Group {}, Result {}", new Object[] { database, group, result }); } return result; }
From source file:com.opengamma.strata.finance.rate.FixedRateObservation.java
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { // no indices to add }
From source file:at.ac.univie.isc.asio.security.FilterAuthorities.java
/** * Remove all authorities, that have been excluded. Note: <strong>Always</strong> returns an * immutable copy of the input with {@link java.util.Set} semantics. * * @param authorities original set of authorities * @return all elements of authorities, that are not excluded */// ww w. j a v a 2 s. com @Override public Set<GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) { final ImmutableSet.Builder<GrantedAuthority> filtered = ImmutableSet.builder(); for (final GrantedAuthority each : authorities) { if (!excluded.contains(each)) { filtered.add(each); } } return filtered.build(); }
From source file:org.jclouds.aws.ec2.xml.DescribeInternetGatewaysResponseHandler.java
@Override public FluentIterable<InternetGateway> getResult() { try {//from w ww . j ava 2 s.c o m return FluentIterable.from(gateways.build()); } finally { gateways = ImmutableSet.builder(); } }
From source file:com.publictransitanalytics.scoregenerator.Main.java
public static void main(String[] args) throws FileNotFoundException, IOException, ArgumentParserException, InterruptedException, ExecutionException, InEnvironmentDetectorException { final Gson serializer = new GsonBuilder().setPrettyPrinting().create(); final ArgumentParser parser = ArgumentParsers.newArgumentParser("ScoreGenerator").defaultHelp(true) .description("Generate isochrone map data."); parser.addArgument("-l", "--tripLengths").action(Arguments.append()); parser.addArgument("-i", "--samplingInterval"); parser.addArgument("-s", "--span"); parser.addArgument("-d", "--baseDirectory"); parser.addArgument("-k", "--backward").action(Arguments.storeTrue()); parser.addArgument("-n", "--inMemCache").action(Arguments.storeTrue()); parser.addArgument("-t", "--interactive").action(Arguments.storeTrue()); parser.addArgument("-b", "--baseFile"); parser.addArgument("-u", "--bounds"); parser.addArgument("-c", "--comparisonFile"); parser.addArgument("-o", "--outputName"); final Subparsers subparsers = parser.addSubparsers().dest("command"); subparsers.addParser("generateNetworkAccessibility"); final Subparser generateSampledNetworkAccessibilityParser = subparsers .addParser("generateSampledNetworkAccessibility"); generateSampledNetworkAccessibilityParser.addArgument("-m", "--samples"); final Subparser generatePointAccessibilityParser = subparsers.addParser("generatePointAccessibility"); generatePointAccessibilityParser.addArgument("-c", "--coordinate"); final Namespace namespace = parser.parseArgs(args); final List<String> durationMinuteStrings = namespace.getList("tripLengths"); final NavigableSet<Duration> durations = new TreeSet<>(); for (String durationMinuteString : durationMinuteStrings) { final Duration duration = Duration.ofMinutes(Integer.valueOf(durationMinuteString)); durations.add(duration);/* w w w .j a v a 2s. c o m*/ } final String baseDirectoryString = namespace.get("baseDirectory"); final Path root = Paths.get(baseDirectoryString); final String baseFile = namespace.get("baseFile"); final OperationDescription baseDescription = serializer.fromJson( new String(Files.readAllBytes(Paths.get(baseFile)), StandardCharsets.UTF_8), OperationDescription.class); final String comparisonFile = namespace.get("comparisonFile"); final OperationDescription comparisonDescription = (comparisonFile == null) ? null : serializer.fromJson( new String(Files.readAllBytes(Paths.get(comparisonFile)), StandardCharsets.UTF_8), OperationDescription.class); final Boolean backwardObject = namespace.getBoolean("backward"); final boolean backward = (backwardObject == null) ? false : backwardObject; final Boolean interactiveObject = namespace.getBoolean("interactive"); final boolean interactive = (interactiveObject == null) ? false : interactiveObject; final NetworkConsoleFactory consoleFactory; if (interactive) { consoleFactory = (network, stopIdMap) -> new InteractiveNetworkConsole(network, stopIdMap); } else { consoleFactory = (network, stopIdMap) -> new DummyNetworkConsole(); } final String samplingIntervalString = namespace.get("samplingInterval"); final Duration samplingInterval = (samplingIntervalString != null) ? Duration.ofMinutes(Long.valueOf(samplingIntervalString)) : null; final String spanString = namespace.get("span"); final Duration span = (spanString != null) ? Duration.parse(spanString) : null; final String outputName = namespace.get("outputName"); final String command = namespace.get("command"); final LocalFilePublisher publisher = new LocalFilePublisher(); final ImmutableSet.Builder<String> fileNamesBuilder = ImmutableSet.builder(); fileNamesBuilder.add(baseDescription.getFiles()); if (comparisonDescription != null) { fileNamesBuilder.add(comparisonDescription.getFiles()); } final Set<String> fileNames = fileNamesBuilder.build(); final Boolean inMemCacheObject = namespace.getBoolean("inMemCache"); final StoreFactory storeFactory = (inMemCacheObject == null || inMemCacheObject == false) ? new NoCacheStoreFactory() : new UnboundedCacheStoreFactory(); final Map<String, ServiceDataDirectory> serviceDirectoriesMap = new HashMap<>(); for (final String fileName : fileNames) { if (!serviceDirectoriesMap.containsKey(fileName)) { final ServiceDataDirectory directory = new ServiceDataDirectory(root, fileName, storeFactory); serviceDirectoriesMap.put(fileName, directory); } } final String boundsString = namespace.get("bounds"); final GeoBounds bounds = parseBounds(boundsString); final Grid grid = getGrid(root, bounds, storeFactory); final MapGenerator mapGenerator = new MapGenerator(); final TimeTracker timeTracker; if (!backward) { timeTracker = new ForwardTimeTracker(); } else { timeTracker = new BackwardTimeTracker(); } if ("generatePointAccessibility".equals(command)) { generatePointAccessibility(namespace, baseDescription, backward, samplingInterval, span, durations, grid, serviceDirectoriesMap, comparisonDescription, publisher, serializer, mapGenerator, outputName, consoleFactory); } else if ("generateNetworkAccessibility".equals(command)) { final ScoreCardFactory scoreCardFactory = new CountScoreCardFactory(); final Set<Center> centers = getAllCenters(grid); final BiMap<OperationDescription, Calculation<ScoreCard>> result = Main.<ScoreCard>runComparison( baseDescription, scoreCardFactory, centers, samplingInterval, span, backward, timeTracker, grid, serviceDirectoriesMap, durations.last(), comparisonDescription, consoleFactory); final Set<Sector> sectors = grid.getReachableSectors(); publishNetworkAccessibility(baseDescription, comparisonDescription, result, grid, sectors, false, durations, span, samplingInterval, backward, publisher, serializer, mapGenerator, outputName); } else if ("generateSampledNetworkAccessibility".equals(command)) { final ScoreCardFactory scoreCardFactory = new CountScoreCardFactory(); final int samples = Integer.valueOf(namespace.get("samples")); final Set<Sector> allReachableSectors = grid.getReachableSectors(); final List<Sector> sectorList = new ArrayList<>(allReachableSectors); Collections.shuffle(sectorList); final Set<Sector> sampleSectors = ImmutableSet.copyOf(sectorList.subList(0, samples)); final Set<Center> centers = getSampleCenters(sampleSectors, grid); final BiMap<OperationDescription, Calculation<ScoreCard>> result = Main.<ScoreCard>runComparison( baseDescription, scoreCardFactory, centers, samplingInterval, span, backward, timeTracker, grid, serviceDirectoriesMap, durations.last(), comparisonDescription, consoleFactory); publishNetworkAccessibility(baseDescription, comparisonDescription, result, grid, sampleSectors, true, durations, span, samplingInterval, backward, publisher, serializer, mapGenerator, outputName); } }
From source file:rx.transformer.GuavaTransformers.java
/** * Returns a Transformer<T,ImmutableSet<T>> that maps an Observable<T> to an Observable<ImmutableSet<T>> *///from w w w.ja v a2 s . c o m public static <T> Observable.Transformer<T, ImmutableSet<T>> toImmutableSet() { return new Observable.Transformer<T, ImmutableSet<T>>() { @Override public Observable<ImmutableSet<T>> call(Observable<T> source) { return source.collect(new Func0<ImmutableSet.Builder<T>>() { @Override public ImmutableSet.Builder<T> call() { return ImmutableSet.builder(); } }, new Action2<ImmutableSet.Builder<T>, T>() { @Override public void call(ImmutableSet.Builder<T> builder, T t) { builder.add(t); } }).map(new Func1<ImmutableSet.Builder<T>, ImmutableSet<T>>() { @Override public ImmutableSet<T> call(ImmutableSet.Builder<T> builder) { return builder.build(); } }); } }; }
From source file:com.facebook.buck.ocaml.OcamlDepToolStep.java
@Override protected void addOptions(ExecutionContext context, ImmutableSet.Builder<ProcessExecutor.Option> options) { // We need this else we get output with color codes which confuses parsing options.add(ProcessExecutor.Option.EXPECTING_STD_ERR); options.add(ProcessExecutor.Option.EXPECTING_STD_OUT); }
From source file:com.publictransitanalytics.scoregenerator.geography.GeoJsonInEnvironmentDetector.java
public GeoJsonInEnvironmentDetector(final Path geoJsonBorderFile, final Path geoJsonWaterFile) throws IOException, InEnvironmentDetectorException { final ImmutableSet.Builder<Geometry> builder = ImmutableSet.builder(); Files.lines(geoJsonWaterFile, StandardCharsets.UTF_8).map(line -> convertToGeometry(line)) .forEach(builder::add);/*from w ww . jav a2s .c o m*/ waterGeometry = builder.build(); final String borderJson = new String(Files.readAllBytes(geoJsonBorderFile), StandardCharsets.UTF_8); borderGeometry = convertToGeometry(borderJson); }