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

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
    public static <E> ImmutableSortedSet<E> of() 

Source Link

Usage

From source file:com.facebook.buck.io.file.PathListing.java

private static ImmutableSortedSet<Path> subSet(ImmutableSortedSet<Path> paths, FilterMode filterMode,
        int limitIndex) {
    // This doesn't copy the contents of the ImmutableSortedSet. We use it
    // as a simple way to get O(1) access to the set's contents, as otherwise
    // we would have to iterate to find the Nth element.
    ImmutableList<Path> pathsList = paths.asList();
    boolean fullSet = limitIndex == paths.size();
    switch (filterMode) {
    case INCLUDE:
        // Make sure we don't call pathsList.get(pathsList.size()).
        if (!fullSet) {
            paths = paths.headSet(pathsList.get(limitIndex));
        }/*  ww w. j  a va2s.c  o m*/
        break;
    case EXCLUDE:
        if (fullSet) {
            // Make sure we don't call pathsList.get(pathsList.size()).
            paths = ImmutableSortedSet.of();
        } else {
            paths = paths.tailSet(pathsList.get(limitIndex));
        }
        break;
    }
    return paths;
}

From source file:org.geoserver.security.iride.IrideRoleService.java

/**
 * Returns an immutable empty {@link ImmutableSortedSet} instance.
 *//*w ww  . jav  a 2  s  .c  o  m*/
@Override
public SortedSet<String> getUserNamesForRole(GeoServerRole role) throws IOException {
    LOGGER.trace("Role: {}", role);

    return ImmutableSortedSet.of();
}

From source file:com.facebook.buck.jvm.groovy.GroovyTestDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

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

    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

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

    JavacOptions javacOptions = JavacOptionsFactory
            .create(defaultJavacOptions, params, resolver, ruleFinder, args)
            // groovyc may or may not play nice with generating ABIs from source, so disabling for now
            .withAbiGenerationMode(JavacOptions.AbiGenerationMode.CLASS);
    GroovycToJarStepFactory stepFactory = new GroovycToJarStepFactory(
            groovyBuckConfig.getGroovyCompiler().get(), Optional.of(args.extraGroovycArguments), javacOptions);

    BuildRuleParams testsLibraryParams = params
            .appendExtraDeps(Iterables.concat(
                    BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(),
                            resolver.getAllRules(args.providedDeps))),
                    ruleFinder.filterBuildRuleInputs(defaultJavacOptions.getInputs(ruleFinder))))
            .withFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver
            .addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs,
                    ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(),
                            args.resources),
                    defaultJavacOptions.getGeneratedSourceFolderName(), /* proguardConfig */ Optional.empty(),
                    /* postprocessClassesCommands */ ImmutableList.of(),
                    /* exportDeps */ ImmutableSortedSet.of(), /* providedDeps */ ImmutableSortedSet.of(),
                    abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()),
                    /* trackClassUsage */ false, /* additionalClasspathEntries */ ImmutableSet.of(),
                    stepFactory, /* resourcesRoot */ Optional.empty(), /* manifest file */ Optional.empty(),
                    /* mavenCoords */ Optional.empty(), /* tests */ ImmutableSortedSet.of(),
                    /* classesToRemoveFromJar */ ImmutableSet.of()));

    return new JavaTest(
            params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            pathResolver, testsLibrary, /* additionalClasspathEntries */ ImmutableSet.of(), args.labels,
            args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(),
            args.vmArgs, /* nativeLibsEnvironment */ ImmutableMap.of(),
            args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs,
            args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel,
            args.stdErrLogLevel);
}

From source file:com.facebook.buck.python.PythonTestDescription.java

/**
 * Return a {@link BuildRule} that constructs the source file which contains the list
 * of test modules this python test rule will run.  Setting up a separate build rule
 * for this allows us to use the existing python binary rule without changes to account
 * for the build-time creation of this file.
 *//* w w  w .jav a  2  s. co  m*/
private static BuildRule createTestModulesSourceBuildRule(BuildRuleParams params, Path outputPath,
        ImmutableSet<String> testModules) {

    // Modify the build rule params to change the target, type, and remove all deps.
    BuildRuleParams newParams = params.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(params.getBuildTarget().checkUnflavored(),
                    ImmutableFlavor.of("test_module")),
            Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));

    String contents = getTestModulesListContents(testModules);

    return new WriteFile(newParams, contents, outputPath, /* executable */ false);
}

From source file:sg.atom.logic.fuzzy.variables.Variable.java

public double unfuzzy(Map<L, Double> confidences) throws IllegalRangeException {
    Set<PointMembership> points = ImmutableSortedSet.of();

    for (Entry<L, Double> confidence : checkNotNull(confidences, "Confidence values cannot be null")
            .entrySet()) {/*from   ww  w.j  av  a 2s  .  com*/
        points.add(newPoint(members.get(confidence.getKey()).unfuzzy(confidence.getValue()),
                confidence.getValue()));
    }
    return DEFAULT.solve(newArrayList(points)).x();
}

From source file:com.facebook.buck.jvm.java.JavaLibraryDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = params.getBuildTarget();

    // We know that the flavour we're being asked to create is valid, since the check is done when
    // creating the action graph from the target graph.

    ImmutableSortedSet<Flavor> flavors = target.getFlavors();

    if (flavors.contains(Javadoc.DOC_JAR)) {
        BuildTarget unflavored = BuildTarget.of(target.getUnflavoredBuildTarget());
        BuildRule baseLibrary = resolver.requireRule(unflavored);

        JarShape shape = params.getBuildTarget().getFlavors().contains(JavaLibrary.MAVEN_JAR) ? JarShape.MAVEN
                : JarShape.SINGLE;/*from   w w  w  . j  a  va2 s.  c o  m*/

        JarShape.Summary summary = shape.gatherDeps(baseLibrary);
        ImmutableSet<SourcePath> sources = summary.getPackagedRules().stream()
                .filter(HasSources.class::isInstance).map(rule -> ((HasSources) rule).getSources())
                .flatMap(Collection::stream).collect(MoreCollectors.toImmutableSet());

        // In theory, the only deps we need are the ones that contribute to the sourcepaths. However,
        // javadoc wants to have classes being documented have all their deps be available somewhere.
        // Ideally, we'd not build everything, but then we're not able to document any classes that
        // rely on auto-generated classes, such as those created by the Immutables library. Oh well.
        // Might as well add them as deps. *sigh*
        ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
        // Sourcepath deps
        deps.addAll(ruleFinder.filterBuildRuleInputs(sources));
        // Classpath deps
        deps.add(baseLibrary);
        deps.addAll(summary.getClasspath().stream()
                .filter(rule -> HasClasspathEntries.class.isAssignableFrom(rule.getClass()))
                .flatMap(rule -> rule.getTransitiveClasspathDeps().stream()).iterator());
        BuildRuleParams emptyParams = params.copyWithDeps(Suppliers.ofInstance(deps.build()),
                Suppliers.ofInstance(ImmutableSortedSet.of()));

        return new Javadoc(emptyParams, pathResolver, args.mavenCoords, args.mavenPomTemplate,
                summary.getMavenDeps(), sources);
    }

    if (flavors.contains(CalculateAbi.FLAVOR)) {
        BuildTarget libraryTarget = target.withoutFlavors(CalculateAbi.FLAVOR);
        resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(libraryTarget));
    }

    BuildRuleParams paramsWithMavenFlavor = null;
    if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
        paramsWithMavenFlavor = params;

        // Maven rules will depend upon their vanilla versions, so the latter have to be constructed
        // without the maven flavor to prevent output-path conflict
        params = params.copyWithBuildTarget(
                params.getBuildTarget().withoutFlavors(ImmutableSet.of(JavaLibrary.MAVEN_JAR)));
    }

    if (flavors.contains(JavaLibrary.SRC_JAR)) {
        args.mavenCoords = args.mavenCoords
                .map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));

        if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
            return new JavaSourceJar(params, pathResolver, args.srcs, args.mavenCoords);
        } else {
            return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor),
                    pathResolver, args.srcs, args.mavenCoords, args.mavenPomTemplate);
        }
    }

    JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);

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

    ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
    BuildRuleParams javaLibraryParams = params.appendExtraDeps(Iterables.concat(
            BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps,
                    resolver.getAllRules(args.providedDeps))),
            ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
    DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder,
            args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources),
            javacOptions.getGeneratedSourceFolderName(),
            args.proguardConfig.map(SourcePaths.toSourcePath(params.getProjectFilesystem())::apply),
            args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps),
            abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()),
            javacOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.of(),
            new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot,
            args.manifestFile, args.mavenCoords, args.tests, javacOptions.getClassesToRemoveFromJar());

    if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
        return defaultJavaLibrary;
    } else {
        return MavenUberJar.create(defaultJavaLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor),
                pathResolver, args.mavenCoords, args.mavenPomTemplate);
    }
}

From source file:org.cyclop.service.cassandra.intern.QueryServiceImpl.java

@Override
public ImmutableSortedSet<CqlTable> findTableNames(Optional<CqlKeySpace> keySpace) {

    StringBuilder cql = new StringBuilder("select columnfamily_name from system.schema_columnfamilies");
    if (keySpace.isPresent()) {
        cql.append(" where keyspace_name='").append(keySpace.get().partLc).append("'");
    }/*from  w  w w.j av a2 s. c  o  m*/
    Optional<ResultSet> result = executeSilent(cql.toString());
    if (!result.isPresent()) {
        LOG.debug("No table names found for keyspace: " + keySpace);
        return ImmutableSortedSet.of();
    }

    ImmutableSortedSet<CqlTable> res = map(result, "columnfamily_name", CqlTable::new);
    return res;
}

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

@Override
public PythonLibrary createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver resolver, ThriftConstructorArg args, ImmutableMap<String, ThriftSource> sources,
        ImmutableSortedSet<BuildRule> deps) {

    ImmutableMap.Builder<Path, SourcePath> modulesBuilder = ImmutableMap.builder();

    // Iterate over all the thrift source, finding the python modules they generate and
    // building up a map of them.
    for (ImmutableMap.Entry<String, ThriftSource> ent : sources.entrySet()) {
        ThriftSource source = ent.getValue();
        Path outputDir = source.getOutputDir();

        for (String module : getGeneratedSources(params.getBuildTarget(), args, ent.getKey(),
                source.getServices())) {
            Path path = outputDir.resolve("gen-" + getLanguage()).resolve(module);
            modulesBuilder.put(Paths.get(module.endsWith(".py") ? module : module + ".py"),
                    new BuildTargetSourcePath(source.getCompileRule().getBuildTarget(), path));
        }/* w w w .  j  a va 2s  .  c o m*/

    }

    ImmutableMap<Path, SourcePath> modules = modulesBuilder.build();

    // Create params which only use the language specific deps.
    BuildRuleParams langParams = params.copyWithChanges(params.getBuildTarget(), Suppliers.ofInstance(deps),
            Suppliers.ofInstance(ImmutableSortedSet.of()));

    // Construct a python library and return it as our language specific build rule.  Dependents
    // will use this to pull the generated sources into packages/PEXs.
    Function<? super PythonPlatform, ImmutableMap<Path, SourcePath>> resources = Functions
            .constant(ImmutableMap.<Path, SourcePath>of());
    return new PythonLibrary(langParams, new SourcePathResolver(new SourcePathRuleFinder(resolver)),
            Functions.constant(modules), resources, Optional.of(true));
}

From source file:com.facebook.buck.jvm.java.JavaTestDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params,
        BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

    if (params.getBuildTarget().getFlavors().contains(CalculateAbi.FLAVOR)) {
        BuildTarget testTarget = params.getBuildTarget().withoutFlavors(CalculateAbi.FLAVOR);
        resolver.requireRule(testTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(testTarget));
    }/*from   ww  w  .jav a2s  .  c  o  m*/

    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    JavacOptions javacOptions = JavacOptionsFactory.create(templateJavacOptions, params, resolver, ruleFinder,
            args);

    CxxLibraryEnhancement cxxLibraryEnhancement = new CxxLibraryEnhancement(params, args.useCxxLibraries,
            args.cxxLibraryWhitelist, resolver, pathResolver, ruleFinder, cxxPlatform);
    params = cxxLibraryEnhancement.updatedParams;

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

    BuildRuleParams testsLibraryParams = params.copyWithDeps(
            Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder()
                    .addAll(params.getDeclaredDeps().get())
                    .addAll(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(),
                            resolver.getAllRules(args.providedDeps))))
                    .addAll(ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))).build()),
            params.getExtraDeps()).withFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);

    JavaLibrary testsLibrary = resolver
            .addToIndex(new DefaultJavaLibrary(testsLibraryParams, pathResolver, ruleFinder, args.srcs,
                    ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(),
                            args.resources),
                    javacOptions.getGeneratedSourceFolderName(),
                    args.proguardConfig.map(SourcePaths.toSourcePath(params.getProjectFilesystem())::apply),
                    /* postprocessClassesCommands */ ImmutableList.of(),
                    /* exportDeps */ ImmutableSortedSet.of(), resolver.getAllRules(args.providedDeps),
                    abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, testsLibraryParams.getDeps()),
                    javacOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.of(),
                    new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot,
                    args.manifestFile, args.mavenCoords, /* tests */ ImmutableSortedSet.of(),
                    /* classesToRemoveFromJar */ ImmutableSet.of()));

    return new JavaTest(
            params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            pathResolver, testsLibrary, /* additionalClasspathEntries */ ImmutableSet.of(), args.labels,
            args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(),
            args.vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment,
            args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs,
            args.env, args.getRunTestSeparately(), args.getForkMode(), args.stdOutLogLevel,
            args.stdErrLogLevel);
}

From source file:com.facebook.buck.jvm.scala.ScalaTestDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams rawParams,
        final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

    if (rawParams.getBuildTarget().getFlavors().contains(CalculateAbi.FLAVOR)) {
        BuildTarget testTarget = rawParams.getBuildTarget().withoutFlavors(CalculateAbi.FLAVOR);
        resolver.requireRule(testTarget);
        return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams,
                new BuildTargetSourcePath(testTarget));
    }//from w  ww  .j av  a2 s .  com

    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    final BuildRule scalaLibrary = resolver.getRule(config.getScalaLibraryTarget());
    BuildRuleParams params = rawParams.copyWithDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder()
            .addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());

    JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(
            params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, pathResolver, ruleFinder,
            cxxPlatform);
    params = cxxLibraryEnhancement.updatedParams;

    Tool scalac = config.getScalac(resolver);

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

    BuildRuleParams javaLibraryParams = params.appendExtraDeps(Iterables.concat(
            BuildRules.getExportedRules(
                    Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))),
            scalac.getDeps(ruleFinder))).withFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
    JavaLibrary testsLibrary = resolver
            .addToIndex(new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs,
                    ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(),
                            args.resources),
                    /* generatedSourceFolderName */ Optional.empty(), /* proguardConfig */ Optional.empty(),
                    /* postprocessClassesCommands */ ImmutableList.of(),
                    /* exportDeps */ ImmutableSortedSet.of(), /* providedDeps */ ImmutableSortedSet.of(),
                    abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()),
                    /* trackClassUsage */ false, /* additionalClasspathEntries */ ImmutableSet.of(),
                    new ScalacToJarStepFactory(scalac,
                            ImmutableList.<String>builder().addAll(config.getCompilerFlags())
                                    .addAll(args.extraArguments).build()),
                    args.resourcesRoot, args.manifestFile, args.mavenCoords,
                    /* tests */ ImmutableSortedSet.of(), /* classesToRemoveFromJar */ ImmutableSet.of()));

    return new JavaTest(
            params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            pathResolver, testsLibrary, /* additionalClasspathEntries */ ImmutableSet.of(), args.labels,
            args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(),
            args.vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment,
            args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs,
            args.env, args.runTestSeparately.orElse(false), args.forkMode.orElse(ForkMode.NONE),
            args.stdOutLogLevel, args.stdErrLogLevel);
}