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:com.ibm.common.geojson.BoundingBox.java

private static void addValues(ImmutableSortedSet.Builder<Float> xset, ImmutableSortedSet.Builder<Float> yset,
        ImmutableSortedSet.Builder<Float> zset, Iterable<Position> positions) {
    for (Position position : positions) {
        xset.add(position.northing());//from w ww . j a  va 2s . co m
        yset.add(position.easting());
        if (position.hasAltitude())
            zset.add(position.altitude());
    }
}

From source file:com.facebook.buck.util.autosparse.MmappedHgManifest.java

public MmappedHgManifest(Path rawManifestPath, int chunkSize) throws IOException {
    // Here is to hoping this is the correct codec on all platforms; Mercurial
    // doesn't care what the filesystem encoding is and just stores the raw bytes.
    String systemEncoding = System.getProperty("file.encoding");
    this.encoding = Charset.availableCharsets().getOrDefault(systemEncoding, StandardCharsets.UTF_8);

    try (FileChannel fileChannel = FileChannel.open(rawManifestPath);) {
        long longSize = fileChannel.size();

        if (longSize > MAX_FILE_SIZE) {
            // MappedByteBuffer can only handle int positions, so we can only address 2GB with a single
            // mmap. Reaching larger manifest sizes would require using multiple mmap objects and
            // added complexity.
            throw new IOException("Unable to load a manifest > 2GB");
        }/*from   w  w  w  .  j a v a2s  .c  o  m*/
        mmap = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, longSize);
        size = (int) longSize;

        Pair<Integer, ImmutableSet<String>> sizeAndDeleted = loadDeleted(size);
        lastIndex = sizeAndDeleted.getFirst().intValue();
        deletedPaths = sizeAndDeleted.getSecond();

        // build an index on which to do in-memory bisection before bisecting the mmap itself
        ImmutableSortedSet.Builder<ChunkIndexEntry> indexBuilder = ImmutableSortedSet.naturalOrder();

        for (int pos = chunkSize; pos < size; pos += chunkSize) {
            int start = findEntryStart(pos);
            int end = find(NUL, start);
            indexBuilder.add(new ChunkIndexEntry(getString(start, end), start));
        }

        chunkIndex = indexBuilder.build();
        LOG.info("Manifest mmap loaded, %d chunks, %d deleted paths, %d size", chunkIndex.size(),
                deletedPaths.size(), size);
    }
}

From source file:com.ccheptea.auto.value.node.TypeSimplifier.java

/**
 * Returns the set of types to import. We import every type that is neither in java.lang nor in
 * the package containing the AutoValue class, provided that the result refers to the type
 * unambiguously. For example, if there is a property of type java.util.Map.Entry then we will
 * import java.util.Map.Entry and refer to the property as Entry. We could also import just
 * java.util.Map in this case and refer to Map.Entry, but currently we never do that.
 *///from  w  ww.j  a  va2 s  . com
ImmutableSortedSet<String> typesToImport() {
    ImmutableSortedSet.Builder<String> typesToImport = ImmutableSortedSet.naturalOrder();
    for (Map.Entry<String, Spelling> entry : imports.entrySet()) {
        if (entry.getValue().importIt) {
            typesToImport.add(entry.getKey());
        }
    }
    return typesToImport.build();
}

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

@Override
protected Iterable<String> getInputsToCompareToOutput(BuildContext context) {
    ImmutableSortedSet.Builder<String> inputsToConsiderForCachingPurposes = ImmutableSortedSet.naturalOrder();

    // This should include the res/ and assets/ folders.
    addResContents(inputsToConsiderForCachingPurposes);
    addAssetsContents(inputsToConsiderForCachingPurposes);

    // manifest file is optional
    if (manifestFile != null) {
        inputsToConsiderForCachingPurposes.add(manifestFile);
    }//  w  w  w .  j  av  a  2s . c  o  m

    return inputsToConsiderForCachingPurposes.build();
}

From source file:com.facebook.buck.thrift.ThriftJavaEnhancer.java

@Override
public BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver,
        ThriftConstructorArg args, ImmutableMap<String, ThriftSource> sources,
        ImmutableSortedSet<BuildRule> deps) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

    if (params.getBuildTarget().getFlavors().contains(CalculateAbi.FLAVOR)) {
        BuildTarget libraryTarget = params.getBuildTarget().withoutFlavors(CalculateAbi.FLAVOR);
        resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(libraryTarget));
    }/*  ww w.j  av a 2s. c o  m*/

    // Pack all the generated sources into a single source zip that we'll pass to the
    // java rule below.
    ImmutableSortedSet.Builder<BuildRule> sourceZipsBuilder = ImmutableSortedSet.naturalOrder();
    UnflavoredBuildTarget unflavoredBuildTarget = params.getBuildTarget().getUnflavoredBuildTarget();
    for (ImmutableMap.Entry<String, ThriftSource> ent : sources.entrySet()) {
        String name = ent.getKey();
        BuildRule compilerRule = ent.getValue().getCompileRule();
        Path sourceDirectory = ent.getValue().getOutputDir().resolve("gen-java");

        BuildTarget sourceZipTarget = getSourceZipBuildTarget(unflavoredBuildTarget, name);
        Path sourceZip = getSourceZipOutputPath(params.getProjectFilesystem(), unflavoredBuildTarget, name);

        sourceZipsBuilder.add(new SrcZip(params.copyWithChanges(sourceZipTarget,
                Suppliers.ofInstance(ImmutableSortedSet.of(compilerRule)),
                Suppliers.ofInstance(ImmutableSortedSet.of())), sourceZip, sourceDirectory));
    }
    ImmutableSortedSet<BuildRule> sourceZips = sourceZipsBuilder.build();
    resolver.addAllToIndex(sourceZips);

    // Create to main compile rule.
    BuildRuleParams javaParams = params.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(unflavoredBuildTarget, getFlavor()),
            Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(sourceZips).addAll(deps)
                    .addAll(BuildRules.getExportedRules(deps))
                    .addAll(ruleFinder.filterBuildRuleInputs(templateOptions.getInputs(ruleFinder))).build()),
            Suppliers.ofInstance(ImmutableSortedSet.of()));

    BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR);

    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    return new DefaultJavaLibrary(javaParams, pathResolver, ruleFinder,
            FluentIterable.from(sourceZips).transform(SourcePaths.getToBuildTargetSourcePath())
                    .toSortedSet(Ordering.natural()),
            /* resources */ ImmutableSet.of(), templateOptions.getGeneratedSourceFolderName(),
            /* proguardConfig */ Optional.empty(), /* postprocessClassesCommands */ ImmutableList.of(),
            /* exportedDeps */ ImmutableSortedSet.of(), /* providedDeps */ ImmutableSortedSet.of(),
            /* abiJar */ abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, javaParams.getDeps()),
            templateOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.of(),
            new JavacToJarStepFactory(templateOptions, JavacOptionsAmender.IDENTITY),
            /* resourcesRoot */ Optional.empty(), /* manifest file */ Optional.empty(),
            /* mavenCoords */ Optional.empty(), /* tests */ ImmutableSortedSet.of(),
            /* classesToRemoveFromJar */ ImmutableSet.of());
}

From source file:com.publictransitanalytics.scoregenerator.geography.GeoBounds.java

public NavigableSet<GeoLongitude> getLongitudeGridlines(final int amount) {
    final Longitude westLon = bounds.getWestLon();
    final double westLonRadians = westLon.inRadians();
    final Longitude eastLon = bounds.getEastLon();
    final double eastLonRadians = eastLon.inRadians();
    final double delta = (eastLonRadians - westLonRadians) / (amount - 1);

    final ImmutableSortedSet.Builder<GeoLongitude> builder = ImmutableSortedSet.naturalOrder();
    double radians = westLonRadians;
    for (int i = 0; i < amount; i++) {
        builder.add(new GeoLongitude(radians, AngleUnit.RADIANS));
        radians += delta;/*w  ww . ja va2s  .  c o  m*/
    }
    return builder.build();
}

From source file:com.facebook.buck.core.model.targetgraph.impl.TargetNodeFactory.java

@SuppressWarnings("unchecked")
private <T, U extends BaseDescription<T>> TargetNode<T> create(U description, T constructorArg,
        ProjectFilesystem filesystem, BuildTarget buildTarget, ImmutableSet<BuildTarget> declaredDeps,
        ImmutableSet<VisibilityPattern> visibilityPatterns, ImmutableSet<VisibilityPattern> withinViewPatterns,
        CellPathResolver cellRoots) throws NoSuchBuildTargetException {

    ImmutableSortedSet.Builder<BuildTarget> extraDepsBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableSortedSet.Builder<BuildTarget> targetGraphOnlyDepsBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableSet.Builder<Path> pathsBuilder = ImmutableSet.builder();

    // Scan the input to find possible BuildTargetPaths, necessary for loading dependent rules.
    for (ParamInfo info : CoercedTypeCache.INSTANCE
            .getAllParamInfo(typeCoercerFactory, description.getConstructorArgType()).values()) {
        if (info.isDep() && info.isInput()
                && info.hasElementTypes(BuildTarget.class, SourcePath.class, Path.class)
                && !info.getName().equals("deps")) {
            detectBuildTargetsAndPathsForConstructorArg(buildTarget, cellRoots,
                    info.isTargetGraphOnlyDep() ? targetGraphOnlyDepsBuilder : extraDepsBuilder, pathsBuilder,
                    info, constructorArg);
        }/*from   www  . j  a  v a  2  s .  c  o m*/
    }

    if (description instanceof ImplicitDepsInferringDescription) {
        ((ImplicitDepsInferringDescription<T>) description).findDepsForTargetFromConstructorArgs(buildTarget,
                cellRoots, constructorArg, extraDepsBuilder, targetGraphOnlyDepsBuilder);
    }

    if (description instanceof ImplicitInputsInferringDescription) {
        pathsBuilder.addAll(((ImplicitInputsInferringDescription<T>) description)
                .inferInputsFromConstructorArgs(buildTarget.getUnflavoredBuildTarget(), constructorArg));
    }

    ImmutableSet<Path> paths = pathsBuilder.build();
    pathsChecker.checkPaths(filesystem, buildTarget, paths);

    // This method uses the TargetNodeFactory, rather than just calling withBuildTarget,
    // because
    // ImplicitDepsInferringDescriptions may give different results for deps based on flavors.
    //
    // Note that this method strips away selected versions, and may be buggy because of it.
    return ImmutableTargetNode.of(buildTarget, this, description, constructorArg, filesystem, paths,
            declaredDeps, extraDepsBuilder.build(), targetGraphOnlyDepsBuilder.build(), cellRoots,
            visibilityPatterns, withinViewPatterns, Optional.empty());
}

From source file:org.jclouds.cloudstack.filters.QuerySigner.java

@VisibleForTesting
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
    utils.logRequest(signatureLog, request, ">>");
    // encode each parameter value first,
    ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
    for (Map.Entry<String, String> entry : decodedParams.entries())
        builder.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue()));
    // then, lower case the entire query string
    String stringToSign = Joiner.on('&').join(builder.build()).toLowerCase();
    if (signatureWire.enabled())
        signatureWire.output(stringToSign);

    return stringToSign;
}

From source file:org.gradle.initialization.NotifyingBuildLoader.java

private Set<LoadProjectsBuildOperationType.Result.Project> convert(Iterable<Project> children) {
    ImmutableSortedSet.Builder<LoadProjectsBuildOperationType.Result.Project> builder = new ImmutableSortedSet.Builder<LoadProjectsBuildOperationType.Result.Project>(
            PROJECT_COMPARATOR);//from   www  .  ja va 2 s . c  o m
    for (org.gradle.api.Project child : children) {
        builder.add(convert(child));
    }
    return builder.build();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.SdkMavenRepository.java

/**
 * Parses a set of maven repository directory trees looking for and parsing .pom files.
 *///from  ww w .j  a  v  a 2 s  .  c om
static SdkMavenRepository create(Iterable<Path> mavenRepositories) throws IOException {
    Collection<Path> pomPaths = new ArrayList<>();
    for (Path mavenRepository : mavenRepositories) {
        pomPaths.addAll(FileSystemUtils.traverseTree(mavenRepository, new Predicate<Path>() {
            @Override
            public boolean apply(@Nullable Path path) {
                return path.toString().endsWith(".pom");
            }
        }));
    }

    ImmutableSortedSet.Builder<Pom> poms = new ImmutableSortedSet.Builder<>(Ordering.usingToString());
    for (Path pomPath : pomPaths) {
        try {
            Pom pom = Pom.parse(pomPath);
            if (pom != null) {
                poms.add(pom);
            }
        } catch (ParserConfigurationException | SAXException e) {
            throw new IOException(e);
        }
    }
    return new SdkMavenRepository(poms.build());
}