Example usage for com.google.common.collect ImmutableSortedSet builder

List of usage examples for com.google.common.collect ImmutableSortedSet builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet builder.

Prototype

@Deprecated
    public static <E> ImmutableSortedSet.Builder<E> builder() 

Source Link

Usage

From source file:org.graylog2.indexer.IndexHelper.java

public static Set<IndexRange> determineAffectedIndicesWithRanges(IndexRangeService indexRangeService,
        Deflector deflector, TimeRange range) {
    final ImmutableSortedSet.Builder<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR);
    for (IndexRange indexRange : indexRangeService.find(range.getFrom(), range.getTo())) {
        indices.add(indexRange);//from   w w w .  ja  v  a 2  s  .  c  om
    }

    return indices.build();
}

From source file:org.openqa.selenium.buck.javascript.JavascriptSource.java

public JavascriptSource(Path path) {
    this.path = Preconditions.checkNotNull(path);

    ImmutableSortedSet.Builder<String> toProvide = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<String> toRequire = ImmutableSortedSet.naturalOrder();

    try {//w ww. j  a v  a2  s  . c om
        for (String line : Files.readAllLines(path, StandardCharsets.UTF_8)) {
            Matcher moduleMatcher = MODULE.matcher(line);
            if (moduleMatcher.find()) {
                toProvide.add(moduleMatcher.group(1));
            }

            Matcher requireMatcher = REQUIRE.matcher(line);
            if (requireMatcher.find()) {
                toRequire.add(requireMatcher.group(1));
            }

            Matcher provideMatcher = PROVIDE.matcher(line);
            if (provideMatcher.find()) {
                toProvide.add(provideMatcher.group(1));
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    this.provides = toProvide.build();
    this.requires = toRequire.build();
}

From source file:com.facebook.buck.hashing.FilePathHashLoader.java

@Override
public HashCode get(Path root) throws IOException {
    // In case the root path is a directory, collect all files contained in it and sort them before
    // hashing to avoid non-deterministic directory traversal order from influencing the hash.
    final ImmutableSortedSet.Builder<Path> files = ImmutableSortedSet.naturalOrder();
    Files.walkFileTree(defaultCellRoot.resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS),
            Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                @Override//from  ww  w .  j a va2 s. com
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                    files.add(file);
                    return FileVisitResult.CONTINUE;
                }
            });
    Hasher hasher = Hashing.sha1().newHasher();
    for (Path file : files.build()) {
        file = defaultCellRoot.resolve(file).toRealPath();
        boolean assumeModified = assumeModifiedFiles.contains(file);
        Path relativePath = MorePaths.relativize(defaultCellRoot, file);

        // For each file add its path to the hasher suffixed by whether we assume the file to be
        // modified or not. This way files with different paths always result in different hashes and
        // files that are assumed to be modified get different hashes than all unmodified files.
        StringHashing.hashStringAndLength(hasher, relativePath.toString());
        hasher.putBoolean(assumeModified);
    }
    return hasher.hash();
}

From source file:com.facebook.buck.rules.CommandTool.java

@Override
public ImmutableCollection<BuildRule> getDeps(SourcePathRuleFinder ruleFinder) {
    ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
    if (baseTool.isPresent()) {
        deps.addAll(baseTool.get().getDeps(ruleFinder));
    }// www.  j av  a 2  s  .com
    deps.addAll(ruleFinder.filterBuildRuleInputs(getInputs()));
    deps.addAll(extraDeps);
    return deps.build();
}

From source file:org.cyclop.model.QueryFavourites.java

public ImmutableSortedSet<QueryEntry> copyAsSortedSet() {
    lock.lock();/*from   w w w  .j  ava 2s.  c  o m*/
    try {
        ImmutableSortedSet.Builder<QueryEntry> builder = ImmutableSortedSet.naturalOrder();
        builder.addAll(favourites);
        ImmutableSortedSet<QueryEntry> sortedFav = builder.build();
        return sortedFav;
    } finally {
        lock.unlock();
    }
}

From source file:com.facebook.buck.apple.AppleLibraryDescriptionSwiftEnhancer.java

@SuppressWarnings("unused")
public static BuildRule createSwiftCompileRule(BuildTarget target, CellPathResolver cellRoots,
        ActionGraphBuilder graphBuilder, SourcePathRuleFinder ruleFinder, BuildRuleParams params,
        AppleNativeTargetDescriptionArg args, ProjectFilesystem filesystem, CxxPlatform platform,
        AppleCxxPlatform applePlatform, SwiftBuckConfig swiftBuckConfig,
        ImmutableSet<CxxPreprocessorInput> inputs) {

    SourcePathRuleFinder rulePathFinder = new SourcePathRuleFinder(graphBuilder);
    SwiftLibraryDescriptionArg.Builder delegateArgsBuilder = SwiftLibraryDescriptionArg.builder();
    SwiftDescriptions.populateSwiftLibraryDescriptionArg(swiftBuckConfig,
            DefaultSourcePathResolver.from(rulePathFinder), delegateArgsBuilder, args, target);
    SwiftLibraryDescriptionArg swiftArgs = delegateArgsBuilder.build();

    Preprocessor preprocessor = platform.getCpp().resolve(graphBuilder);

    ImmutableSet<BuildRule> inputDeps = RichStream.from(inputs)
            .flatMap(input -> RichStream.from(input.getDeps(graphBuilder, rulePathFinder))).toImmutableSet();

    ImmutableSortedSet.Builder<BuildRule> sortedDeps = ImmutableSortedSet.naturalOrder();
    sortedDeps.addAll(inputDeps);//  w  ww .j  av  a2  s  . c o m

    BuildRuleParams paramsWithDeps = params.withExtraDeps(sortedDeps.build());

    PreprocessorFlags.Builder flagsBuilder = PreprocessorFlags.builder();
    inputs.forEach(input -> flagsBuilder.addAllIncludes(input.getIncludes()));
    inputs.forEach(input -> flagsBuilder.addAllFrameworkPaths(input.getFrameworks()));
    PreprocessorFlags preprocessorFlags = flagsBuilder.build();

    Optional<CxxPreprocessorInput> underlyingModule = AppleLibraryDescription
            .underlyingModuleCxxPreprocessorInput(target, graphBuilder, platform);

    return SwiftLibraryDescription.createSwiftCompileRule(platform, applePlatform.getSwiftPlatform().get(),
            swiftBuckConfig, target, paramsWithDeps, graphBuilder, rulePathFinder, cellRoots, filesystem,
            swiftArgs, preprocessor, preprocessorFlags, underlyingModule.isPresent());
}

From source file:google.registry.tools.server.ListDomainsAction.java

@Override
public ImmutableSet<DomainResource> loadObjects() {
    checkArgument(!tlds.isEmpty(), "Must specify TLDs to query");
    for (String tld : tlds) {
        assertTldExists(tld);//from ww w  .j  a v  a  2 s  .c o  m
    }
    ImmutableSortedSet.Builder<DomainResource> builder = new ImmutableSortedSet.Builder<DomainResource>(
            COMPARATOR);
    for (List<String> batch : Lists.partition(tlds.asList(), MAX_NUM_SUBQUERIES)) {
        builder.addAll(queryNotDeleted(DomainResource.class, clock.nowUtc(), "tld in", batch));
    }
    return builder.build();
}

From source file:com.facebook.buck.util.hashing.FilePathHashLoader.java

@Override
public HashCode get(Path root) throws IOException {
    // In case the root path is a directory, collect all files contained in it and sort them before
    // hashing to avoid non-deterministic directory traversal order from influencing the hash.
    ImmutableSortedSet.Builder<Path> files = ImmutableSortedSet.naturalOrder();
    Files.walkFileTree(defaultCellRoot.resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS),
            Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                @Override//from ww w . ja  v a 2s. c o  m
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                    files.add(file);
                    return FileVisitResult.CONTINUE;
                }
            });
    Hasher hasher = Hashing.sha1().newHasher();
    for (Path file : files.build()) {
        file = resolvePath(file);
        boolean assumeModified = assumeModifiedFiles.contains(file);
        Path relativePath = MorePaths.relativize(defaultCellRoot, file);

        // For each file add its path to the hasher suffixed by whether we assume the file to be
        // modified or not. This way files with different paths always result in different hashes and
        // files that are assumed to be modified get different hashes than all unmodified files.
        StringHashing.hashStringAndLength(hasher, relativePath.toString());
        hasher.putBoolean(assumeModified);
    }
    return hasher.hash();
}

From source file:ch.acanda.eclipse.pmd.properties.PMDPropertyPageController.java

public void init(final IProject project) {
    this.project = project;
    final WorkspaceModel workspaceModel = PMDPlugin.getDefault().getWorkspaceModel();

    projectModel = workspaceModel.getOrCreateProject(project.getName());
    model.setInitialState(projectModel.isPMDEnabled(), projectModel.getRuleSets(), project);
    final ImmutableSortedSet.Builder<RuleSetModel> ruleSetBuilder = ImmutableSortedSet
            .orderedBy(ProjectModel.RULE_SET_COMPARATOR);
    for (final ProjectModel projectModel : workspaceModel.getProjects()) {
        ruleSetBuilder.addAll(projectModel.getRuleSets());
    }/* w w w.  j a  va2s .c om*/
    model.setRuleSets(ImmutableList.copyOf(toViewModels(ruleSetBuilder.build(), project)));
    reset();
}

From source file:com.facebook.buck.rules.JavaBinaryRule.java

@Override
protected RuleKey.Builder ruleKeyBuilder() {
    ImmutableSortedSet.Builder<String> metaInfFiles = ImmutableSortedSet.naturalOrder();
    addMetaInfContents(metaInfFiles);/*from  w  w w .j av  a2s. co m*/

    return super.ruleKeyBuilder().set("mainClass", mainClass).set("manifestFile", manifestFile)
            .set("metaInfDirectory", metaInfFiles.build());
}