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.features.go.GoTestDescription.java
@Override public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget, BuildRuleParams params, GoTestDescriptionArg args) { GoPlatform platform = GoDescriptors.getPlatformForRule(getGoToolchain(), this.goBuckConfig, buildTarget, args);/*from w ww .j av a 2 s . co m*/ ActionGraphBuilder graphBuilder = context.getActionGraphBuilder(); SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder); SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder); ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); GoTestCoverStep.Mode coverageMode; ImmutableSortedSet.Builder<BuildRule> extraDeps = ImmutableSortedSet.naturalOrder(); ImmutableSet.Builder<SourcePath> srcs; ImmutableMap<String, Path> coverVariables; ImmutableSet.Builder<SourcePath> rawSrcs = ImmutableSet.builder(); rawSrcs.addAll(args.getSrcs()); if (args.getLibrary().isPresent()) { GoLibraryDescriptionArg libraryArg = graphBuilder .requireMetadata(args.getLibrary().get(), GoLibraryDescriptionArg.class).get(); rawSrcs.addAll(libraryArg.getSrcs()); } if (args.getCoverageMode().isPresent()) { coverageMode = args.getCoverageMode().get(); GoTestCoverStep.Mode coverage = coverageMode; GoTestCoverSource coverSource = (GoTestCoverSource) graphBuilder.computeIfAbsent( buildTarget.withAppendedFlavors(InternalFlavor.of("gen-cover")), target -> new GoTestCoverSource(target, projectFilesystem, ruleFinder, pathResolver, platform, rawSrcs.build(), platform.getCover(), coverage)); coverVariables = coverSource.getVariables(); srcs = ImmutableSet.builder(); srcs.addAll(coverSource.getCoveredSources()).addAll(coverSource.getTestSources()); extraDeps.add(coverSource); } else { srcs = rawSrcs; coverVariables = ImmutableMap.of(); coverageMode = GoTestCoverStep.Mode.NONE; } if (buildTarget.getFlavors().contains(TEST_LIBRARY_FLAVOR)) { return createTestLibrary(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()), graphBuilder, srcs.build(), args, platform); } GoBinary testMain = createTestMainRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()), graphBuilder, srcs.build(), coverVariables, coverageMode, args, platform); graphBuilder.addToIndex(testMain); StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.builder().setBuildTarget(buildTarget) .setCellPathResolver(context.getCellPathResolver()).setExpanders(MACRO_EXPANDERS).build(); return new GoTest(buildTarget, projectFilesystem, params.withDeclaredDeps(ImmutableSortedSet.of(testMain)).withoutExtraDeps(), testMain, args.getLabels(), args.getContacts(), args.getTestRuleTimeoutMs().map(Optional::of).orElse( goBuckConfig.getDelegate().getView(TestBuckConfig.class).getDefaultTestRuleTimeoutMs()), ImmutableMap .copyOf(Maps.transformValues(args.getEnv(), x -> macrosConverter.convert(x, graphBuilder))), args.getRunTestSeparately(), args.getResources(), coverageMode); }
From source file:edu.mit.streamjit.impl.compiler2.Actor.java
/** * Returns the logical indices popped on the given input during the given * iteration./*from w ww . j a v a 2s.c om*/ * @param input the input index * @param iterations the iteration numbers * @return the logical indices popped on the given input during the given * iterations */ public ImmutableSortedSet<Integer> pops(int input, Set<Integer> iterations) { if (iterations.isEmpty()) return ImmutableSortedSet.of(); if (iterations instanceof ContiguousSet) return pops(input, (ContiguousSet<Integer>) iterations); ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (int i : iterations) builder.addAll(pops(input, i)); return builder.build(); }
From source file:com.facebook.buck.apple.AppleDescriptions.java
public static void populateCxxConstructorArg(SourcePathResolver resolver, CxxConstructorArg output, AppleNativeTargetDescriptionArg arg, BuildTarget buildTarget) { Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix(arg, buildTarget); // The resulting cxx constructor arg will have no exported headers and both headers and exported // headers specified in the apple arg will be available with both public and private include // styles./*from w ww . ja v a 2 s.c o m*/ ImmutableSortedMap<String, SourcePath> headerMap = ImmutableSortedMap.<String, SourcePath>naturalOrder() .putAll(convertAppleHeadersToPublicCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)) .putAll(convertAppleHeadersToPrivateCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)) .build(); ImmutableSortedSet.Builder<SourceWithFlags> nonSwiftSrcs = ImmutableSortedSet.naturalOrder(); for (SourceWithFlags src : arg.srcs) { if (!MorePaths.getFileExtension(resolver.getAbsolutePath(src.getSourcePath())) .equalsIgnoreCase(SWIFT_EXTENSION)) { nonSwiftSrcs.add(src); } } output.srcs = nonSwiftSrcs.build(); output.platformSrcs = arg.platformSrcs; output.headers = SourceList.ofNamedSources(headerMap); output.platformHeaders = arg.platformHeaders; output.prefixHeader = arg.prefixHeader; output.compilerFlags = arg.compilerFlags; output.platformCompilerFlags = arg.platformCompilerFlags; output.langCompilerFlags = arg.langCompilerFlags; output.preprocessorFlags = arg.preprocessorFlags; output.platformPreprocessorFlags = arg.platformPreprocessorFlags; output.langPreprocessorFlags = arg.langPreprocessorFlags; output.linkerFlags = arg.linkerFlags; output.platformLinkerFlags = arg.platformLinkerFlags; output.frameworks = arg.frameworks; output.libraries = arg.libraries; output.deps = arg.deps; // This is intentionally an empty string; we put all prefixes into // the header map itself. output.headerNamespace = Optional.of(""); output.cxxRuntimeType = arg.cxxRuntimeType; output.tests = arg.tests; output.precompiledHeader = arg.precompiledHeader; }
From source file:com.google.template.soy.soyparse.PluginResolver.java
private static Set<Integer> getValidArgsSizes(Signature[] signatures) { ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Signature signature : signatures) { builder.add(signature.parameterTypes().length); }//from w ww . j a v a 2 s . c o m return builder.build(); }
From source file:com.facebook.buck.cli.MissingSymbolsHandler.java
/** * Get a list of missing dependencies from {@link #getNeededDependencies} and print it to the * console in a list-of-Python-strings way that's easy to copy and paste. *///from w w w .java 2 s. c o m private void printNeededDependencies(Collection<MissingSymbolEvent> missingSymbolEvents) throws InterruptedException { ImmutableSetMultimap<BuildTarget, BuildTarget> neededDependencies; try { neededDependencies = getNeededDependencies(missingSymbolEvents); } catch (IOException e) { LOG.warn(e, "Could not find missing deps"); print("Could not find missing deps because of an IOException: " + e.getMessage()); return; } ImmutableSortedSet.Builder<String> samePackageDeps = ImmutableSortedSet.naturalOrder(); ImmutableSortedSet.Builder<String> otherPackageDeps = ImmutableSortedSet.naturalOrder(); for (BuildTarget target : neededDependencies.keySet()) { print(formatTarget(target) + " is missing deps:"); Set<BuildTarget> sortedDeps = ImmutableSortedSet.copyOf(neededDependencies.get(target)); for (BuildTarget neededDep : sortedDeps) { if (neededDep.getBaseName().equals(target.getBaseName())) { samePackageDeps.add(":" + neededDep.getShortName()); } else { otherPackageDeps.add(neededDep.toString()); } } } String format = " '%s',"; for (String dep : samePackageDeps.build()) { print(String.format(format, dep)); } for (String dep : otherPackageDeps.build()) { print(String.format(format, dep)); } }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
/** * Returns the physical indices written to the given storage during the * given group iteration.// ww w.ja v a2 s. c o m * @param s the storage being written to * @param iterations the group iterations * @return the physical indices written */ public ImmutableSortedSet<Integer> writes(Storage s, Range<Integer> iterations) { ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Actor a : actors()) builder.addAll(a.writes(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a), iterations.upperEndpoint() * schedule.get(a)))); return builder.build(); }
From source file:org.pircbotx.UserChannelDao.java
/** * Gets all currently known levels (op/voice/etc) a user holds in the * channel. A {@link UserListEvent} for the channel must of been dispatched * before this method will return complete results * * @param channel Known channel/* ww w . j a v a 2 s . c om*/ * @param user Known user * @return An immutable sorted set of UserLevels */ @Synchronized("accessLock") public ImmutableSortedSet<UserLevel> getLevels(@NonNull C channel, @NonNull U user) { ImmutableSortedSet.Builder<UserLevel> builder = ImmutableSortedSet.naturalOrder(); for (Map.Entry<UserLevel, UserChannelMap<U, C>> curEntry : levelsMap.entrySet()) if (curEntry.getValue().containsEntry(user, channel)) builder.add(curEntry.getKey()); return builder.build(); }
From source file:com.facebook.buck.features.d.DDescriptionUtils.java
/** * Ensures that a DCompileBuildRule exists for the given target, creating a DCompileBuildRule if * neccesary./* w ww .ja v a2s. c o m*/ * * @param baseParams build parameters for the rule * @param graphBuilder BuildRuleResolver the rule should be in * @param src the source file to be compiled * @param compilerFlags flags to pass to the compiler * @param compileTarget the target the rule should be for * @param dBuckConfig the Buck configuration for D * @return the build rule */ public static DCompileBuildRule requireBuildRule(BuildTarget compileTarget, BuildTarget baseBuildTarget, ProjectFilesystem projectFilesystem, BuildRuleParams baseParams, ActionGraphBuilder graphBuilder, SourcePathRuleFinder ruleFinder, DBuckConfig dBuckConfig, ImmutableList<String> compilerFlags, String name, SourcePath src, DIncludes includes) { return (DCompileBuildRule) graphBuilder.computeIfAbsent(compileTarget, ignored -> { Tool compiler = dBuckConfig.getDCompiler(); Map<BuildTarget, DIncludes> transitiveIncludes = new TreeMap<>(); transitiveIncludes.put(baseBuildTarget, includes); for (Map.Entry<BuildTarget, DLibrary> library : getTransitiveDLibraryRules(baseParams.getBuildDeps()) .entrySet()) { transitiveIncludes.put(library.getKey(), library.getValue().getIncludes()); } ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder(); depsBuilder.addAll(BuildableSupport.getDepsCollection(compiler, ruleFinder)); depsBuilder.addAll(ruleFinder.filterBuildRuleInputs(src)); for (DIncludes dIncludes : transitiveIncludes.values()) { depsBuilder.addAll(dIncludes.getDeps(ruleFinder)); } ImmutableSortedSet<BuildRule> deps = depsBuilder.build(); return new DCompileBuildRule(compileTarget, projectFilesystem, baseParams.withDeclaredDeps(deps).withoutExtraDeps(), compiler, ImmutableList.<String>builder().addAll(dBuckConfig.getBaseCompilerFlags()).addAll(compilerFlags) .build(), name, ImmutableSortedSet.of(src), ImmutableList.copyOf(transitiveIncludes.values())); }); }
From source file:com.facebook.buck.rules.AndroidResourceRule.java
@Override protected RuleKey.Builder ruleKeyBuilder() { ImmutableSortedSet.Builder<String> resFiles = ImmutableSortedSet.naturalOrder(); addResContents(resFiles);//from ww w . ja va 2 s . c o m ImmutableSortedSet.Builder<String> assetsFiles = ImmutableSortedSet.naturalOrder(); addAssetsContents(assetsFiles); return super.ruleKeyBuilder().set("res", resFiles.build()).set("assets", assetsFiles.build()); }
From source file:simpleserver.config.DTDEntityResolver.java
private ImmutableSet<Integer> parseGroups(String idString) { String[] segments = idString.split(","); ImmutableSortedSet.Builder<Integer> groups = ImmutableSortedSet.naturalOrder(); for (String segment : segments) { if (segment.matches("^\\s*$")) { continue; }/* w w w. j a v a2 s .c om*/ try { groups.add(Integer.valueOf(segment)); continue; } catch (NumberFormatException e) { } if (segment.indexOf('+') == segment.length() - 1) { int num = 0; try { num = Integer.valueOf(segment.split("\\+")[0]); } catch (NumberFormatException e) { System.out.println("Unable to parse group: " + segment); continue; } List ids = config.getList("/groups/group/@id"); for (int j = 0; j < ids.size(); j++) { int n = Integer.valueOf(ids.get(j).toString()); if (n >= num) { groups.add(n); } } continue; } String[] range = segment.split("-"); if (range.length != 2) { System.out.println("Unable to parse group: " + segment); continue; } int low; int high; try { low = Integer.valueOf(range[0]); high = Integer.valueOf(range[1]); } catch (NumberFormatException e) { System.out.println("Unable to parse group: " + segment); continue; } if (low > high) { System.out.println("Unable to parse group: " + segment); continue; } for (int k = low; k <= high; ++k) { groups.add(k); } } return groups.build(); }