List of usage examples for com.google.common.collect ImmutableSortedSet naturalOrder
public static <E extends Comparable<?>> Builder<E> naturalOrder()
From source file:com.facebook.buck.core.build.engine.buildinfo.DefaultOnDiskBuildInfo.java
@Override public ImmutableSortedSet<Path> getPathsForArtifact() throws IOException { ImmutableSortedSet.Builder<Path> paths = ImmutableSortedSet.naturalOrder(); for (Path path : getOutputPaths()) { paths.add(path);/*from w w w .j a v a2s . com*/ projectFilesystem.walkRelativeFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { paths.add(dir); return super.preVisitDirectory(dir, attrs); } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { paths.add(file); return super.visitFile(file, attrs); } }, false); } return paths.build(); }
From source file:edu.mit.streamjit.impl.compiler2.Actor.java
/** * Returns the logical indices peeked or popped on the given input during * the given iterations. Note that this method may return a nonempty set * even if peeks(input) returns 0 and isPeeking() returns false. * @param input the input index/*from ww w . j a v a 2s.c om*/ * @param iterations the iteration numbers * @return the logical indices peeked or popped on the given input during * the given iterations */ public ImmutableSortedSet<Integer> peeks(int input, Set<Integer> iterations) { if (iterations.isEmpty()) return ImmutableSortedSet.of(); if (iterations instanceof ContiguousSet) return peeks(input, (ContiguousSet<Integer>) iterations); ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (int i : iterations) builder.addAll(peeks(input, i)); return builder.build(); }
From source file:org.springframework.ide.eclipse.boot.dash.model.BootProjectDashElement.java
/** * Creates a ObservableSet that is a 'summary' of some property of the children of this node. The summary * is a set of all the values of the given property on all the children. The set is sorted using the element's * natural ordering.//from w w w . j av a 2 s .c o m */ private <T extends Comparable<T>> ObservableSet<T> createSortedLiveSummary( final Function<BootDashElement, T> getter) { final ObservableSet<T> summary = new ObservableSet<T>() { @Override protected ImmutableSet<T> compute() { debug("port-summary[" + getName() + "]: compute()..."); ImmutableSet.Builder<T> builder = ImmutableSortedSet.naturalOrder(); for (BootDashElement child : getCurrentChildren()) { add(builder, child); } ImmutableSet<T> result = builder.build(); debug("port-summary[" + getName() + "]: compute() => " + result); return result; } protected void add(ImmutableSet.Builder<T> builder, BootDashElement child) { debug("port-summary[" + getName() + "]: add port for " + child); T v = getter.apply(child); debug("port-summary[" + getName() + "]: add port for " + child + " = " + v); if (v != null) { builder.add(v); } } }; final ElementStateListener elementListener = new ElementStateListener() { public void stateChanged(BootDashElement e) { summary.refresh(); } }; getBootDashModel().addElementStateListener(elementListener); summary.onDispose(new DisposeListener() { public void disposed(Disposable disposed) { getBootDashModel().removeElementStateListener(elementListener); } }); addDisposableChild(summary); return summary; }
From source file:com.opera.core.systems.OperaDesktopDriver.java
protected SortedSet<ScopeService> getRequiredServices() { ImmutableSortedSet.Builder<ScopeService> services = ImmutableSortedSet.naturalOrder(); services.addAll(super.getRequiredServices()); services.add(ScopeService.DESKTOP_WINDOW_MANAGER, ScopeService.SYSTEM_INPUT, ScopeService.DESKTOP_UTILS); return services.build(); }
From source file:com.facebook.buck.rules.AbstractNodeBuilder.java
protected <C extends Comparable<?>> ImmutableSortedSet<C> amend(ImmutableSortedSet<C> existing, C instance) { ImmutableSortedSet.Builder<C> toReturn = ImmutableSortedSet.naturalOrder(); if (existing != null) { toReturn.addAll(existing);/*from ww w . j a v a 2 s.c om*/ } toReturn.add(instance); return toReturn.build(); }
From source file:com.facebook.buck.thrift.ThriftLibraryDescription.java
/** * Create the build rules which compile the input thrift sources into their respective * language specific sources.//from w ww .ja v a2s .c om */ @VisibleForTesting protected ImmutableMap<String, ThriftCompiler> createThriftCompilerBuildRules(BuildRuleParams params, BuildRuleResolver resolver, CompilerType compilerType, ImmutableList<String> flags, String language, ImmutableSet<String> options, ImmutableMap<String, SourcePath> srcs, ImmutableSortedSet<ThriftLibrary> deps, ImmutableMap<String, ImmutableSortedSet<String>> generatedSources) { SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); Tool compiler = thriftBuckConfig.getCompiler(compilerType, resolver); // Build up the include roots to find thrift file deps and also the build rules that // generate them. ImmutableMap.Builder<Path, SourcePath> includesBuilder = ImmutableMap.builder(); ImmutableSortedSet.Builder<HeaderSymlinkTree> includeTreeRulesBuilder = ImmutableSortedSet.naturalOrder(); ImmutableList.Builder<Path> includeRootsBuilder = ImmutableList.builder(); ImmutableSet.Builder<Path> headerMapsBuilder = ImmutableSet.builder(); for (ThriftLibrary dep : deps) { includesBuilder.putAll(dep.getIncludes()); includeTreeRulesBuilder.add(dep.getIncludeTreeRule()); includeRootsBuilder.add(dep.getIncludeTreeRule().getIncludePath()); headerMapsBuilder.addAll(OptionalCompat.asSet(dep.getIncludeTreeRule().getHeaderMap())); } ImmutableMap<Path, SourcePath> includes = includesBuilder.build(); ImmutableSortedSet<HeaderSymlinkTree> includeTreeRules = includeTreeRulesBuilder.build(); ImmutableList<Path> includeRoots = includeRootsBuilder.build(); ImmutableSet<Path> headerMaps = headerMapsBuilder.build(); // For each thrift source, add a thrift compile rule to generate it's sources. ImmutableMap.Builder<String, ThriftCompiler> compileRules = ImmutableMap.builder(); for (ImmutableMap.Entry<String, SourcePath> ent : srcs.entrySet()) { String name = ent.getKey(); SourcePath source = ent.getValue(); ImmutableSortedSet<String> genSrcs = Preconditions.checkNotNull(generatedSources.get(name)); BuildTarget target = createThriftCompilerBuildTarget(params.getBuildTarget(), name); Path outputDir = getThriftCompilerOutputDir(params.getProjectFilesystem(), params.getBuildTarget(), name); compileRules.put(name, new ThriftCompiler( params.copyWithChanges(target, Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder() .addAll(compiler.getDeps(ruleFinder)) .addAll(ruleFinder.filterBuildRuleInputs(ImmutableList.<SourcePath>builder().add(source) .addAll(includes.values()).build())) .addAll(includeTreeRules).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), compiler, flags, outputDir, source, language, options, includeRoots, headerMaps, includes, genSrcs)); } return compileRules.build(); }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
/** * Returns the physical indices read from the given storage during the given * group iteration./*from w w w . j ava 2 s. c om*/ * @param s the storage being read from * @param iteration the group iteration number * @return the physical indices read */ public ImmutableSortedSet<Integer> reads(Storage s, int iteration) { ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Actor a : actors()) builder.addAll( a.reads(s, Range.closedOpen(iteration * schedule.get(a), (iteration + 1) * schedule.get(a)))); return builder.build(); }
From source file:com.facebook.buck.cxx.CxxTestDescription.java
@SuppressWarnings("PMD.PrematureDeclaration") @Override// w w w. ja v a 2 s . c om public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams inputParams, final BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException { Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget()); Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN .getValue(inputParams.getBuildTarget()); inputParams = CxxStrip.removeStripStyleFlavorInParams(inputParams, flavoredStripStyle); inputParams = LinkerMapMode.removeLinkerMapModeFlavorInParams(inputParams, flavoredLinkerMapMode); final BuildRuleParams params = inputParams; Optional<CxxPlatform> platform = cxxPlatforms.getValue(params.getBuildTarget()); CxxPlatform cxxPlatform = platform.orElse(defaultCxxPlatform); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder); if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE)) { return CxxDescriptionEnhancer.createCompilationDatabase(params, resolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, args); } if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) { return CxxDescriptionEnhancer.createUberCompilationDatabase( platform.isPresent() ? params : params.withFlavor(cxxPlatform.getFlavor()), resolver); } if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) { return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params); } // Generate the link rule that builds the test binary. final CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer .createBuildRulesForCxxBinaryDescriptionArg(params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode); // Construct the actual build params we'll use, notably with an added dependency on the // CxxLink rule above which builds the test binary. BuildRuleParams testParams = params.appendExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder)); testParams = CxxStrip.restoreStripStyleFlavorInParams(testParams, flavoredStripStyle); testParams = LinkerMapMode.restoreLinkerMapModeFlavorInParams(testParams, flavoredLinkerMapMode); // Supplier which expands macros in the passed in test environment. Supplier<ImmutableMap<String, String>> testEnv = () -> ImmutableMap .copyOf(Maps.transformValues(args.env, CxxDescriptionEnhancer.MACRO_HANDLER .getExpander(params.getBuildTarget(), params.getCellRoots(), resolver))); // Supplier which expands macros in the passed in test arguments. Supplier<ImmutableList<String>> testArgs = () -> args.args.stream().map(CxxDescriptionEnhancer.MACRO_HANDLER .getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)::apply) .collect(MoreCollectors.toImmutableList()); Supplier<ImmutableSortedSet<BuildRule>> additionalDeps = () -> { ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder(); // It's not uncommon for users to add dependencies onto other binaries that they run // during the test, so make sure to add them as runtime deps. deps.addAll(Sets.difference(params.getDeps(), cxxLinkAndCompileRules.getBinaryRule().getDeps())); // Add any build-time from any macros embedded in the `env` or `args` parameter. for (String part : Iterables.concat(args.args, args.env.values())) { try { deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractBuildTimeDeps(params.getBuildTarget(), params.getCellRoots(), resolver, part)); } catch (MacroException e) { throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage()); } } return deps.build(); }; CxxTest test; CxxTestType type = args.framework.orElse(getDefaultTestType()); switch (type) { case GTEST: { test = new CxxGtestTest(testParams, pathResolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources) .transform(SourcePaths.toSourcePath(params.getProjectFilesystem())) .toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), cxxBuckConfig.getMaximumTestOutputSize()); break; } case BOOST: { test = new CxxBoostTest(testParams, pathResolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources) .transform(SourcePaths.toSourcePath(params.getProjectFilesystem())) .toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs)); break; } default: { Preconditions.checkState(false, "Unhandled C++ test type: %s", type); throw new RuntimeException(); } } return test; }
From source file:google.registry.tools.UniformRapidSuspensionCommand.java
private ImmutableSortedSet<String> getExistingNameservers(DomainResource domain) { ImmutableSortedSet.Builder<String> nameservers = ImmutableSortedSet.naturalOrder(); for (HostResource host : ofy().load().keys(domain.getNameservers()).values()) { nameservers.add(host.getForeignKey()); }//from www . j a va 2 s .co m return nameservers.build(); }
From source file:com.facebook.buck.rules.keys.DefaultDependencyFileRuleKeyFactory.java
@Override public Pair<RuleKey, ImmutableSet<SourcePath>> build(SupportsDependencyFileRuleKey rule, ImmutableList<DependencyFileEntry> depFileEntries) throws IOException { // Create a builder which records all `SourcePath`s which are possibly used by the rule. Builder builder = newInstance(rule); Optional<ImmutableSet<SourcePath>> possibleDepFileSourcePaths = rule.getPossibleInputSourcePaths(); // TODO(jkeljo): Make this use possibleDepFileSourcePaths all the time Iterable<SourcePath> inputsSoFar = builder.getIterableInputsSoFar(); // Dep file paths come as a sorted set, which does binary search instead of hashing for // lookups, so we re-create it as a hashset. ImmutableSet<SourcePath> fastPossibleSourcePaths = possibleDepFileSourcePaths.isPresent() ? ImmutableSet.copyOf(possibleDepFileSourcePaths.get()) : ImmutableSet.of();/*w ww .ja va 2 s . co m*/ ImmutableSet<DependencyFileEntry> depFileEntriesSet = ImmutableSet.copyOf(depFileEntries); final ImmutableSet.Builder<SourcePath> depFileSourcePathsBuilder = ImmutableSet.builder(); final ImmutableSet.Builder<DependencyFileEntry> filesAccountedFor = ImmutableSet.builder(); final ImmutableSet.Builder<String> metadataFilenamesBuilder = ImmutableSortedSet.naturalOrder(); // Each existing input path falls into one of three categories: // 1) It's not covered by dep files, so we need to consider it part of the rule key // 2) It's covered by dep files and present in the dep file, so we consider it // part of the rule key // 3) It's covered by dep files but not present in the dep file, so we don't include it in // the rule key (the benefit of dep file support is that lots of things fall in this // category, so we can avoid rebuilds that would have happened with input-based rule keys) for (SourcePath input : inputsSoFar) { if (possibleDepFileSourcePaths.isPresent() && !fastPossibleSourcePaths.contains(input)) { // If this path is not a dep file path, then add it to the builder directly. // Note that if {@code possibleDepFileSourcePaths} is not present, we treat // all the input files as covered by dep file, so we'll never end up here! builder.setSourcePathDirectly(input); } else { // If this input path is covered by the dep paths, check to see if it was declared // as a real dependency by the dep file entries DependencyFileEntry entry = DependencyFileEntry.fromSourcePath(input, pathResolver); if (depFileEntriesSet.contains(entry)) { builder.setSourcePathDirectly(input); depFileSourcePathsBuilder.add(input); filesAccountedFor.add(entry); } Optional<Path> pathWithinArchive = entry.pathWithinArchive(); if (pathWithinArchive.isPresent() && pathWithinArchive.get().startsWith(METADATA_DIR)) { metadataFilenamesBuilder.add(input.toString()); } } } Sets.SetView<DependencyFileEntry> filesUnaccountedFor = Sets.difference(depFileEntriesSet, filesAccountedFor.build()); // If we don't find actual inputs in one of the rules that corresponded to the input, this // likely means that the rule changed to no longer use the input. In this case we need to // throw a `NoSuchFileException` so that the build engine handles this as a signal that the // dep file rule key cannot be used. if (!filesUnaccountedFor.isEmpty()) { throw new NoSuchFileException( String.format("%s: could not find any inputs matching the relative paths [%s]", rule.getBuildTarget(), Joiner.on(',').join(filesUnaccountedFor))); } // Annotation processors might enumerate all files under a certain path and then generate // code based on that list (without actually reading the files), making the list of files // itself a used dependency that must be part of the dependency-based key. We don't // currently have the instrumentation to detect such enumeration perfectly, but annotation // processors are most commonly looking for files under META-INF, so as a stopgap we add // the listing of META-INF to the rule key. builder.setReflectively("buck.dep_file_metadata_list", metadataFilenamesBuilder.build()); return new Pair<>(builder.build(), depFileSourcePathsBuilder.build()); }