List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:org.lanternpowered.server.text.selector.SelectorResolver.java
private void addTeamFilters(List<Predicate<Entity>> filters) { Selector sel = this.selector; Optional<Invertible<String>> teamOpt = sel.getArgument(ArgumentTypes.TEAM); if (teamOpt.isPresent()) { Invertible<String> teamArg = teamOpt.get(); final boolean inverted = teamArg.isInverted(); final Collection<Team> teams = Sponge.getGame().getServer().getServerScoreboard().get().getTeams(); filters.add(new Predicate<Entity>() { @Override//w w w . j av a 2 s . c om public boolean test(Entity input) { if (input instanceof TeamMember) { return inverted ^ collectMembers(teams).contains(((TeamMember) input).getTeamRepresentation()); } return false; } private Collection<Text> collectMembers(Collection<Team> teams) { ImmutableSet.Builder<Text> users = ImmutableSet.builder(); for (Team t : teams) { users.addAll(t.getMembers()); } return users.build(); } }); } }
From source file:com.facebook.buck.features.python.CxxPythonExtensionDescription.java
private ImmutableSet<BuildRule> getPlatformDeps(BuildRuleResolver ruleResolver, PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, CxxPythonExtensionDescriptionArg args) { ImmutableSet.Builder<BuildRule> rules = ImmutableSet.builder(); // Add declared deps. rules.addAll(args.getCxxDeps().get(ruleResolver, cxxPlatform)); // Add platform specific deps. rules.addAll(ruleResolver.getAllRules( Iterables.concat(args.getPlatformDeps().getMatchingValues(pythonPlatform.getFlavor().toString())))); // Add a dep on the python C/C++ library. if (pythonPlatform.getCxxLibrary().isPresent()) { rules.add(ruleResolver.getRule(pythonPlatform.getCxxLibrary().get())); }/* www .ja va 2 s .c o m*/ return rules.build(); }
From source file:com.facebook.buck.io.ExecutableFinder.java
private ImmutableSet<Path> getPaths(ImmutableMap<String, String> env) { ImmutableSet.Builder<Path> paths = ImmutableSet.builder(); // Add the empty path so that when we iterate over it, we can check for the suffixed version of // a given path, be it absolute or not. paths.add(Paths.get("")); String pathEnv = env.get("PATH"); if (pathEnv != null) { pathEnv = pathEnv.trim();/* w ww . j a va 2s.c om*/ paths.addAll(StreamSupport .stream(Splitter.on(pathSeparator).omitEmptyStrings().split(pathEnv).spliterator(), false) .map(Paths::get).iterator()); } if (platform == Platform.MACOS) { Path osXPaths = Paths.get("/etc/paths"); if (Files.exists(osXPaths)) { try { paths.addAll(Files.readAllLines(osXPaths, Charset.defaultCharset()).stream().map(Paths::get) .iterator()); } catch (IOException e) { LOG.warn("Unable to read mac-specific paths. Skipping"); } } } return paths.build(); }
From source file:org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain.java
/** * Creates a command that will merge all non-conflicting differences in the given direction. * <p>/* w ww.j ava 2 s.c o m*/ * A "non-conflicting" difference is any difference that is not in a real conflict with another <u>and</u> * that does not, directly or indirectly, depend on the merge of a difference that is in conflict itself. * </p> * <p> * Note that only the differences originating from the "source" side of the chosen merge direction will be * considered. * </p> * * @param comparison * The comparison which differences to merge. * @param leftToRight * The direction in which we should merge the differences. * @param mergerRegistry * The registry to query for specific mergers for each difference. * @param runnable * the runnable to execute for the actual merge operation. * @return The copy command, ready for use. * @since 4.1 */ public ICompareCopyCommand createCopyAllNonConflictingCommand(Comparison comparison, boolean leftToRight, IMerger.Registry mergerRegistry, IMergeAllNonConflictingRunnable runnable) { ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder(); notifiersBuilder.add(comparison); ImmutableSet<Notifier> notifiers = notifiersBuilder.addAll(fNotifiers).build(); return new MergeAllNonConflictingCommand(fChangeRecorder, notifiers, comparison, leftToRight, mergerRegistry, runnable); }
From source file:com.facebook.buck.apple.AppleTestDescription.java
private TestHostInfo createTestHostInfo(BuildRuleParams params, BuildRuleResolver resolver, BuildTarget testHostAppBuildTarget, AppleDebugFormat debugFormat, Iterable<Flavor> additionalFlavors, ImmutableList<CxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException { BuildRule rule = resolver.requireRule(BuildTarget.builder(testHostAppBuildTarget) .addAllFlavors(additionalFlavors).addFlavors(debugFormat.getFlavor()) .addFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor()).build()); if (!(rule instanceof AppleBundle)) { throw new HumanReadableException("Apple test rule '%s' has test_host_app '%s' not of type '%s'.", params.getBuildTarget(), testHostAppBuildTarget, Description.getBuildRuleType(AppleBundleDescription.class)); }//from w ww. j a v a2 s.c o m AppleBundle testHostApp = (AppleBundle) rule; SourcePath testHostAppBinarySourcePath = new BuildTargetSourcePath( testHostApp.getBinaryBuildRule().getBuildTarget()); ImmutableMap<BuildTarget, NativeLinkable> roots = NativeLinkables .getNativeLinkableRoots(testHostApp.getBinary().get().getDeps(), x -> true); // Union the blacklist of all the platforms. This should give a superset for each particular // platform, which should be acceptable as items in the blacklist thare are unmatched are simply // ignored. ImmutableSet.Builder<BuildTarget> blacklistBuilder = ImmutableSet.builder(); for (CxxPlatform platform : cxxPlatforms) { blacklistBuilder .addAll(NativeLinkables.getTransitiveNativeLinkables(platform, roots.values()).keySet()); } return TestHostInfo.of(testHostApp, testHostAppBinarySourcePath, blacklistBuilder.build()); }
From source file:com.facebook.buck.apple.AppleBinaryDescription.java
@Override public Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains() { ImmutableSet.Builder<FlavorDomain<?>> builder = ImmutableSet.builder(); ImmutableSet<FlavorDomain<?>> localDomains = ImmutableSet.of(AppleDebugFormat.FLAVOR_DOMAIN); builder.addAll(localDomains); delegate.flavorDomains().ifPresent(domains -> builder.addAll(domains)); swiftDelegate.flavorDomains().ifPresent(domains -> builder.addAll(domains)); ImmutableSet<FlavorDomain<?>> result = builder.build(); // Drop StripStyle because it's overridden by AppleDebugFormat result = result.stream().filter(domain -> !domain.equals(StripStyle.FLAVOR_DOMAIN)) .collect(MoreCollectors.toImmutableSet()); return Optional.of(result); }
From source file:org.voltdb.dtxn.SiteTracker.java
public SiteTracker(int hostId, Map<MailboxType, List<MailboxNodeContent>> mailboxes, int version) { m_version = version;/* w ww. java2 s. co m*/ m_hostId = hostId; Map<Integer, List<Long>> hostsToSites = new HashMap<Integer, List<Long>>(); Map<Integer, List<Integer>> hostsToPartitions = new HashMap<Integer, List<Integer>>(); Map<Integer, List<Long>> partitionsToSites = new HashMap<Integer, List<Long>>(); ImmutableMap.Builder<Long, Integer> sitesToPartitions = ImmutableMap.<Long, Integer>builder(); Map<Integer, List<Long>> hostsToInitiators = new HashMap<Integer, List<Long>>(); Map<MailboxType, List<Long>> otherHSIds = new HashMap<MailboxType, List<Long>>(); ImmutableSet.Builder<Integer> allHosts = ImmutableSet.<Integer>builder(); ImmutableSet.Builder<Long> allExecutionSites = ImmutableSet.<Long>builder(); ImmutableSet.Builder<Long> allInitiators = ImmutableSet.<Long>builder(); Map<MailboxType, Map<Integer, List<Long>>> hostsToOtherHSIds = new HashMap<MailboxType, Map<Integer, List<Long>>>(); for (Entry<MailboxType, List<MailboxNodeContent>> e : mailboxes.entrySet()) { if (e.getKey().equals(MailboxType.ExecutionSite)) { populateSites(e.getValue(), hostsToSites, hostsToPartitions, partitionsToSites, sitesToPartitions, allHosts, allExecutionSites); } else if (e.getKey().equals(MailboxType.Initiator)) { populateInitiators(e.getValue(), hostsToInitiators, allInitiators); } else if (e.getKey().equals(MailboxType.StatsAgent)) { populateStatsAgents(e.getValue()); } else { populateOtherHSIds(e.getKey(), e.getValue(), otherHSIds, hostsToOtherHSIds); } } m_hostsToSitesImmutable = CoreUtils.unmodifiableMapCopy(hostsToSites); m_hostsToPartitionsImmutable = CoreUtils.unmodifiableMapCopy(hostsToPartitions); m_partitionsToSitesImmutable = CoreUtils.unmodifiableMapCopy(partitionsToSites); m_sitesToPartitionsImmutable = sitesToPartitions.build(); m_hostsToInitiatorsImmutable = CoreUtils.unmodifiableMapCopy(hostsToInitiators); m_otherHSIdsImmutable = CoreUtils.unmodifiableMapCopy(otherHSIds); m_allInitiatorsImmutable = allInitiators.build(); m_allExecutionSitesImmutable = allExecutionSites.build(); m_allHostsImmutable = allHosts.build(); ImmutableMap.Builder<MailboxType, ImmutableMap<Integer, ImmutableList<Long>>> hostsToOtherHSIdsReplacement = ImmutableMap .<MailboxType, ImmutableMap<Integer, ImmutableList<Long>>>builder(); for (Map.Entry<MailboxType, Map<Integer, List<Long>>> e : hostsToOtherHSIds.entrySet()) { hostsToOtherHSIdsReplacement.put(e.getKey(), CoreUtils.unmodifiableMapCopy(e.getValue())); } m_hostsToOtherHSIdsImmutable = hostsToOtherHSIdsReplacement.build(); m_allExecutionSitesArray = new long[m_allExecutionSitesImmutable.size()]; int ii = 0; for (Long site : m_allExecutionSitesImmutable) { m_allExecutionSitesArray[ii++] = site; } m_numberOfPartitions = m_partitionsToSitesImmutable.keySet().size(); m_numberOfHosts = m_hostsToSitesImmutable.keySet().size(); m_numberOfExecutionSites = m_sitesToPartitionsImmutable.keySet().size(); m_allPartitions = new int[m_numberOfPartitions]; ii = 0; for (Integer partition : m_partitionsToSitesImmutable.keySet()) { m_allPartitions[ii++] = partition; } ImmutableSet.Builder<Long> allSites = ImmutableSet.<Long>builder(); allSites.addAll(m_allExecutionSitesImmutable); allSites.addAll(m_allInitiatorsImmutable); for (List<Long> siteIds : otherHSIds.values()) { allSites.addAll(siteIds); } m_allSitesImmutable = allSites.build(); }
From source file:com.facebook.presto.sql.planner.iterative.rule.PruneWindowColumns.java
@Override protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, WindowNode windowNode, Set<Symbol> referencedOutputs) { Map<Symbol, WindowNode.Function> referencedFunctions = Maps.filterKeys(windowNode.getWindowFunctions(), referencedOutputs::contains); if (referencedFunctions.isEmpty()) { return Optional.of(windowNode.getSource()); }/*from w w w . j av a2 s. c o m*/ ImmutableSet.Builder<Symbol> referencedInputs = ImmutableSet .<Symbol>builder().addAll(windowNode.getSource().getOutputSymbols().stream() .filter(referencedOutputs::contains).iterator()) .addAll(windowNode.getPartitionBy()).addAll(windowNode.getOrderBy()); windowNode.getHashSymbol().ifPresent(referencedInputs::add); for (WindowNode.Function windowFunction : referencedFunctions.values()) { referencedInputs.addAll(SymbolsExtractor.extractUnique(windowFunction.getFunctionCall())); windowFunction.getFrame().getStartValue().ifPresent(referencedInputs::add); windowFunction.getFrame().getEndValue().ifPresent(referencedInputs::add); } PlanNode prunedWindowNode = new WindowNode(windowNode.getId(), restrictOutputs(idAllocator, windowNode.getSource(), referencedInputs.build()) .orElse(windowNode.getSource()), windowNode.getSpecification(), referencedFunctions, windowNode.getHashSymbol(), windowNode.getPrePartitionedInputs(), windowNode.getPreSortedOrderPrefix()); if (prunedWindowNode.getOutputSymbols().size() == windowNode.getOutputSymbols().size()) { // Neither function pruning nor input pruning was successful. return Optional.empty(); } return Optional.of(prunedWindowNode); }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
private Set<Storage> allEdges() { ImmutableSet.Builder<Storage> builder = ImmutableSet.builder(); for (Actor a : actors) { builder.addAll(a.inputs()); builder.addAll(a.outputs());/*from w w w . j a va 2 s . co m*/ } return builder.build(); }
From source file:io.prestosql.plugin.mongodb.MongoSession.java
public Set<String> getAllTables(String schema) throws SchemaNotFoundException { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); builder.addAll(ImmutableList.copyOf(client.getDatabase(schema).listCollectionNames()).stream() .filter(name -> !name.equals(schemaCollection)).filter(name -> !SYSTEM_TABLES.contains(name)) .collect(toSet()));/*from w w w . j a va2s . co m*/ builder.addAll(getTableMetadataNames(schema)); return builder.build(); }