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

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

Introduction

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

Prototype

public static <E extends Comparable<? super E>> ImmutableSortedSet<E> copyOf(E[] elements) 

Source Link

Usage

From source file:com.facebook.buck.android.relinker.RelinkerRule.java

private void writeSymbols(Path dest, Set<String> symbols) throws IOException {
    Files.write(absolutify(dest), ImmutableSortedSet.copyOf(symbols), Charsets.UTF_8,
            StandardOpenOption.CREATE);
}

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

protected DefaultJavaLibrary(BuildRuleParams params, final SourcePathResolver resolver,
        SourcePathRuleFinder ruleFinder, Set<? extends SourcePath> srcs, Set<? extends SourcePath> resources,
        Optional<Path> generatedSourceFolder, Optional<SourcePath> proguardConfig,
        ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<BuildRule> exportedDeps,
        ImmutableSortedSet<BuildRule> providedDeps, BuildTarget abiJar, boolean trackClassUsage,
        final JarArchiveDependencySupplier abiClasspath, ImmutableSet<Path> additionalClasspathEntries,
        CompileToJarStepFactory compileStepFactory, Optional<Path> resourcesRoot,
        Optional<SourcePath> manifestFile, Optional<String> mavenCoords, ImmutableSortedSet<BuildTarget> tests,
        ImmutableSet<Pattern> classesToRemoveFromJar) {
    super(params.appendExtraDeps(() -> ruleFinder.filterBuildRuleInputs(abiClasspath.get())), resolver);
    this.ruleFinder = ruleFinder;
    this.compileStepFactory = compileStepFactory;

    // Exported deps are meant to be forwarded onto the CLASSPATH for dependents,
    // and so only make sense for java library types.
    for (BuildRule dep : exportedDeps) {
        if (!(dep instanceof JavaLibrary)) {
            throw new HumanReadableException(params.getBuildTarget() + ": exported dep " + dep.getBuildTarget()
                    + " (" + dep.getType() + ") " + "must be a type of java library.");
        }/*from w w w  . j a v a 2 s. c  o m*/
    }

    this.srcs = ImmutableSortedSet.copyOf(srcs);
    this.resources = ImmutableSortedSet.copyOf(resources);
    this.proguardConfig = proguardConfig;
    this.postprocessClassesCommands = postprocessClassesCommands;
    this.exportedDeps = exportedDeps;
    this.providedDeps = providedDeps;
    this.additionalClasspathEntries = additionalClasspathEntries.stream().map(getProjectFilesystem()::resolve)
            .collect(MoreCollectors.toImmutableSet());
    this.resourcesRoot = resourcesRoot;
    this.manifestFile = manifestFile;
    this.mavenCoords = mavenCoords;
    this.tests = tests;

    this.abiJar = abiJar;
    this.trackClassUsage = trackClassUsage;
    this.abiClasspath = abiClasspath;
    this.deps = params.getDeps();
    if (!srcs.isEmpty() || !resources.isEmpty() || manifestFile.isPresent()) {
        this.outputJar = Optional.of(getOutputJarPath(getBuildTarget(), getProjectFilesystem()));
    } else {
        this.outputJar = Optional.empty();
    }

    this.outputClasspathEntriesSupplier = Suppliers.memoize(() -> JavaLibraryClasspathProvider
            .getOutputClasspathJars(DefaultJavaLibrary.this, getResolver(), sourcePathForOutputJar()));

    this.transitiveClasspathsSupplier = Suppliers.memoize(
            () -> JavaLibraryClasspathProvider.getClasspathsFromLibraries(getTransitiveClasspathDeps()));

    this.transitiveClasspathDepsSupplier = Suppliers
            .memoize(() -> JavaLibraryClasspathProvider.getTransitiveClasspathDeps(DefaultJavaLibrary.this));

    this.buildOutputInitializer = new BuildOutputInitializer<>(params.getBuildTarget(), this);
    this.generatedSourceFolder = generatedSourceFolder;
    this.classesToRemoveFromJar = classesToRemoveFromJar;
}

From source file:ealvatag.tag.reference.GenreTypes.java

/**
 * Currently this is only used for testing and in another unused class. We'll construct a set on the fly
 *
 * @return the set of all genre values//from  w  w w.  j  a v a 2s .  c o  m
 */
public ImmutableSortedSet<String> getSortedValueSet() {
    return ImmutableSortedSet.copyOf(values);
}

From source file:com.facebook.buck.android.AndroidAarDescription.java

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph,
        BuildRuleParams originalBuildRuleParams, BuildRuleResolver resolver, A args)
        throws NoSuchBuildTargetException {

    UnflavoredBuildTarget originalBuildTarget = originalBuildRuleParams.getBuildTarget().checkUnflavored();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    ImmutableList.Builder<BuildRule> aarExtraDepsBuilder = ImmutableList.<BuildRule>builder()
            .addAll(originalBuildRuleParams.getExtraDeps().get());

    /* android_manifest */
    AndroidManifestDescription.Arg androidManifestArgs = androidManifestDescription
            .createUnpopulatedConstructorArg();
    androidManifestArgs.skeleton = args.manifestSkeleton;
    androidManifestArgs.deps = args.deps;

    BuildRuleParams androidManifestParams = originalBuildRuleParams.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_MANIFEST_FLAVOR),
            originalBuildRuleParams.getDeclaredDeps(), originalBuildRuleParams.getExtraDeps());

    AndroidManifest manifest = androidManifestDescription.createBuildRule(targetGraph, androidManifestParams,
            resolver, androidManifestArgs);
    aarExtraDepsBuilder.add(resolver.addToIndex(manifest));

    final APKModuleGraph apkModuleGraph = new APKModuleGraph(targetGraph,
            originalBuildRuleParams.getBuildTarget(), Optional.empty());

    /* assemble dirs */
    AndroidPackageableCollector collector = new AndroidPackageableCollector(
            originalBuildRuleParams.getBuildTarget(), /* buildTargetsToExcludeFromDex */ ImmutableSet.of(),
            /* resourcesToExclude */ ImmutableSet.of(), apkModuleGraph);
    collector.addPackageables(/*from   w  w w . j  a  v a2  s  .c  o  m*/
            AndroidPackageableCollector.getPackageableRules(originalBuildRuleParams.getDeps()));
    AndroidPackageableCollection packageableCollection = collector.build();

    ImmutableSortedSet<BuildRule> androidResourceDeclaredDeps = AndroidResourceHelper
            .androidResOnly(originalBuildRuleParams.getDeclaredDeps().get());
    ImmutableSortedSet<BuildRule> androidResourceExtraDeps = AndroidResourceHelper
            .androidResOnly(originalBuildRuleParams.getExtraDeps().get());

    BuildRuleParams assembleAssetsParams = originalBuildRuleParams.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_ASSETS_FLAVOR),
            Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
    ImmutableCollection<SourcePath> assetsDirectories = packageableCollection.getAssetsDirectories();
    AssembleDirectories assembleAssetsDirectories = new AssembleDirectories(assembleAssetsParams, pathResolver,
            assetsDirectories);
    aarExtraDepsBuilder.add(resolver.addToIndex(assembleAssetsDirectories));

    BuildRuleParams assembleResourceParams = originalBuildRuleParams.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_RESOURCE_FLAVOR),
            Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps));
    ImmutableCollection<SourcePath> resDirectories = packageableCollection.getResourceDetails()
            .getResourceDirectories();
    MergeAndroidResourceSources assembleResourceDirectories = new MergeAndroidResourceSources(
            assembleResourceParams, pathResolver, resDirectories);
    aarExtraDepsBuilder.add(resolver.addToIndex(assembleResourceDirectories));

    /* android_resource */
    BuildRuleParams androidResourceParams = originalBuildRuleParams.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ANDROID_RESOURCE_FLAVOR),
            Suppliers.ofInstance(
                    ImmutableSortedSet.of(manifest, assembleAssetsDirectories, assembleResourceDirectories)),
            Suppliers.ofInstance(ImmutableSortedSet.of()));

    AndroidResource androidResource = new AndroidResource(androidResourceParams, ruleFinder,
            /* deps */ ImmutableSortedSet.<BuildRule>naturalOrder().add(assembleAssetsDirectories)
                    .add(assembleResourceDirectories).addAll(originalBuildRuleParams.getDeclaredDeps().get())
                    .build(),
            new BuildTargetSourcePath(assembleResourceDirectories.getBuildTarget()),
            /* resSrcs */ ImmutableSortedSet.of(), Optional.empty(), /* rDotJavaPackage */ null,
            new BuildTargetSourcePath(assembleAssetsDirectories.getBuildTarget()),
            /* assetsSrcs */ ImmutableSortedSet.of(), Optional.empty(),
            new BuildTargetSourcePath(manifest.getBuildTarget()), /* hasWhitelistedStrings */ false);
    aarExtraDepsBuilder.add(resolver.addToIndex(androidResource));

    /* native_libraries */
    AndroidNativeLibsPackageableGraphEnhancer packageableGraphEnhancer = new AndroidNativeLibsPackageableGraphEnhancer(
            resolver, originalBuildRuleParams, nativePlatforms, ImmutableSet.of(), cxxBuckConfig,
            /* nativeLibraryMergeMap */ Optional.empty(), /* nativeLibraryMergeGlue */ Optional.empty(),
            AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> nativeLibrariesOptional = packageableGraphEnhancer
            .enhance(packageableCollection).getCopyNativeLibraries();
    if (nativeLibrariesOptional.isPresent()
            && nativeLibrariesOptional.get().containsKey(apkModuleGraph.getRootAPKModule())) {
        aarExtraDepsBuilder
                .add(resolver.addToIndex(nativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule())));
    }

    Optional<Path> assembledNativeLibsDir = nativeLibrariesOptional.map(input -> {
        // there will be only one value for the root module
        CopyNativeLibraries copyNativeLibraries = input.get(apkModuleGraph.getRootAPKModule());
        if (copyNativeLibraries == null) {
            throw new HumanReadableException(
                    "Native libraries are present but not in the root application module.");
        }
        return copyNativeLibraries.getPathToNativeLibsDir();
    });
    BuildRuleParams androidAarParams = originalBuildRuleParams
            .copyWithExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.copyOf(aarExtraDepsBuilder.build())));
    return new AndroidAar(androidAarParams, manifest, androidResource,
            assembleResourceDirectories.getPathToOutput(), assembleAssetsDirectories.getPathToOutput(),
            assembledNativeLibsDir,
            ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()));
}

From source file:com.facebook.buck.android.AndroidBinary.java

/**
 * @param target the Android platform version to target, e.g., "Google Inc.:Google APIs:16". You
 *     can find the list of valid values on your system by running
 *     {@code android list targets --compact}.
 *//*from w ww. j a v  a  2  s . com*/
AndroidBinary(BuildRuleParams params, JavacOptions javacOptions, Optional<Path> proguardJarOverride,
        SourcePath manifest, String target, ImmutableSortedSet<BuildRule> originalDeps, Keystore keystore,
        PackageType packageType, DexSplitMode dexSplitMode, Set<BuildTarget> buildTargetsToExcludeFromDex,
        boolean useAndroidProguardConfigWithOptimizations, Optional<Integer> proguardOptimizationPasses,
        Optional<SourcePath> proguardConfig, ResourceCompressionMode resourceCompressionMode,
        Set<TargetCpuType> cpuFilters, ResourceFilter resourceFilter, boolean buildStringSourceMap,
        boolean disablePreDex, boolean exopackage, Set<BuildRule> preprocessJavaClassesDeps,
        Optional<String> preprocessJavaClassesBash) {
    this.originalBuildRuleParams = Preconditions.checkNotNull(params);
    this.javacOptions = Preconditions.checkNotNull(javacOptions);
    this.proguardJarOverride = Preconditions.checkNotNull(proguardJarOverride);
    this.manifest = Preconditions.checkNotNull(manifest);
    this.target = Preconditions.checkNotNull(target);
    this.originalDeps = Preconditions.checkNotNull(originalDeps);
    this.classpathDeps = originalDeps;
    this.keystore = Preconditions.checkNotNull(keystore);
    this.packageType = Preconditions.checkNotNull(packageType);
    this.dexSplitMode = Preconditions.checkNotNull(dexSplitMode);
    this.buildTargetsToExcludeFromDex = ImmutableSet
            .copyOf(Preconditions.checkNotNull(buildTargetsToExcludeFromDex));
    this.useAndroidProguardConfigWithOptimizations = useAndroidProguardConfigWithOptimizations;
    this.optimizationPasses = Preconditions.checkNotNull(proguardOptimizationPasses);
    this.proguardConfig = Preconditions.checkNotNull(proguardConfig);
    this.resourceCompressionMode = Preconditions.checkNotNull(resourceCompressionMode);
    this.cpuFilters = ImmutableSet.copyOf(cpuFilters);
    this.resourceFilter = Preconditions.checkNotNull(resourceFilter);
    this.buildStringSourceMap = buildStringSourceMap;
    this.disablePreDex = disablePreDex;
    this.exopackage = exopackage;
    this.preprocessJavaClassesDeps = ImmutableSortedSet.copyOf(preprocessJavaClassesDeps);
    this.preprocessJavaClassesBash = Preconditions.checkNotNull(preprocessJavaClassesBash);
    this.primaryDexPath = getPrimaryDexPath(params.getBuildTarget());
}

From source file:org.pircbotx.UserChannelDao.java

/**
 * Gets all currently known channels the user is a part of as a normal user.
 * A {@link UserListEvent} for all channels must of been dispatched before
 * this method will return complete results
 *
 * @param user Known user/*  w  ww  . ja  va2 s  . c o  m*/
 * @return An immutable sorted set of Channels
 */
@Synchronized("accessLock")
public ImmutableSortedSet<C> getNormalUserChannels(@NonNull U user) {
    Set<C> remainingChannels = new HashSet<C>(mainMap.getChannels(user));
    for (UserChannelMap<U, C> curLevelMap : levelsMap.values())
        remainingChannels.removeAll(curLevelMap.getChannels(user));
    return ImmutableSortedSet.copyOf(remainingChannels);
}

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

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

    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));

    // Grab all the sources and headers generated from the passed in thrift sources.
    CxxHeadersAndSources spec = getThriftHeaderSourceSpec(params, args, sources);

    // Add all the passed in language-specific thrift deps, and any C/C++ specific deps
    // passed in via the constructor arg.
    ImmutableSortedSet<BuildRule> allDeps = ImmutableSortedSet.<BuildRule>naturalOrder().addAll(deps)
            .addAll(resolver.getAllRules((cpp2 ? args.cpp2Deps : args.cppDeps))).build();

    // Create language specific build params by using the deps we formed above.
    BuildRuleParams langParams = params.copyWithDeps(Suppliers.ofInstance(ImmutableSortedSet.of()),
            Suppliers.ofInstance(allDeps));

    // Merge the thrift generated headers with the ones passed in via the description.
    ImmutableSortedMap.Builder<String, SourcePath> headersBuilder = ImmutableSortedMap.naturalOrder();
    headersBuilder.putAll(spec.getHeaders());
    if (args.cppExportedHeaders.getNamedSources().isPresent()) {
        headersBuilder.putAll(args.cppExportedHeaders.getNamedSources().get());
    } else {/*from  ww w .  ja va2s .  c o m*/
        headersBuilder.putAll(pathResolver.getSourcePathNames(params.getBuildTarget(), "cpp_headers",
                args.cppExportedHeaders.getUnnamedSources().get()));
    }
    ImmutableSortedMap<String, SourcePath> headers = headersBuilder.build();

    // Merge the thrift generated sources with the ones passed in via the description.
    ImmutableSortedMap.Builder<String, SourceWithFlags> srcsBuilder = ImmutableSortedMap.naturalOrder();
    srcsBuilder.putAll(spec.getSources());
    if (args.cppSrcs.getNamedSources().isPresent()) {
        srcsBuilder.putAll(args.cppSrcs.getNamedSources().get());
    } else {
        for (SourceWithFlags sourceWithFlags : args.cppSrcs.getUnnamedSources().get()) {
            srcsBuilder.put(
                    pathResolver.getSourcePathName(params.getBuildTarget(), sourceWithFlags.getSourcePath()),
                    sourceWithFlags);
        }
    }
    ImmutableSortedMap<String, SourceWithFlags> srcs = srcsBuilder.build();

    // Construct the C/C++ library description argument to pass to the
    CxxLibraryDescription.Arg langArgs = CxxLibraryDescription.createEmptyConstructorArg();
    langArgs.headerNamespace = args.cppHeaderNamespace;
    langArgs.srcs = ImmutableSortedSet.copyOf(srcs.values());
    langArgs.exportedHeaders = SourceList.ofNamedSources(headers);
    langArgs.canBeAsset = Optional.empty();
    langArgs.compilerFlags = cpp2 ? args.cpp2CompilerFlags : args.cppCompilerFlags;

    // Since thrift generated C/C++ code uses lots of templates, just use exported deps throughout.
    langArgs.exportedDeps = FluentIterable.from(allDeps).transform(HasBuildTarget::getBuildTarget)
            .toSortedSet(Ordering.natural());

    return cxxLibraryDescription.createBuildRule(targetGraph, langParams, resolver, langArgs);
}

From source file:org.dishevelled.collect.Sets.java

/**
  * Create and return an immutable sorted set containing the unique elements in the specified iterator
  * sorted by their natural order. The returned immutable sorted set is a high-performance, immutable
  * <code>SortedSet</code> that stores its elements in a sorted array.
  */*w  w w.  j  av a  2s  . c  o m*/
  * @param <T> element type
  * @param iterator iterator, must not be null
  * @return an immutable set containing the unique elements returned by the specified iterator
  *    sorted by their natural order
  */
public static <T extends Comparable<? super T>> SortedSet<T> asImmutableSortedSet(
        final Iterator<? extends T> iterator) {
    if (iterator == null) {
        throw new IllegalArgumentException("iterator must not be null");
    }
    return ImmutableSortedSet.copyOf(iterator);
}

From source file:com.techcavern.pircbotz.UserChannelDao.java

@Synchronized("accessLock")
public ImmutableSortedSet<C> getAllChannels() {
    return ImmutableSortedSet.copyOf(channelNameMap.values());
}

From source file:google.registry.rdap.RdapDomainSearchAction.java

/** Assembles a list of {@link HostResource} keys by name. */
private Iterable<Key<HostResource>> getNameserverRefsByLdhName(final RdapSearchPattern partialStringQuery,
        final DateTime now) {
    // Handle queries without a wildcard; just load the host by foreign key in the usual way.
    if (!partialStringQuery.getHasWildcard()) {
        Key<HostResource> hostKey = loadAndGetKey(HostResource.class, partialStringQuery.getInitialString(),
                now);/*from   www. j  a  va2  s  .  co  m*/
        if (hostKey == null) {
            return ImmutableList.of();
        } else {
            return ImmutableList.of(hostKey);
        }
        // Handle queries with a wildcard, but no suffix. Query the host resources themselves, rather
        // than the foreign key index, because then we have an index on fully qualified host name and
        // deletion time, so we can check the deletion status in the query itself. There are no pending
        // deletes for hosts, so we can call queryUndeleted.
    } else if (partialStringQuery.getSuffix() == null) {
        // TODO (b/24463238): figure out how to limit the size of these queries effectively
        return queryUndeleted(HostResource.class, "fullyQualifiedHostName", partialStringQuery, 1000).keys();
        // Handle queries with a wildcard and a suffix. In this case, it is more efficient to do things
        // differently. We use the suffix to look up the domain, then loop through the subordinate hosts
        // looking for matches.
        // TODO(mountford): This might not be ok; it will only find nameservers on domains we control
    } else {
        DomainResource domainResource = loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(),
                now);
        if (domainResource == null) {
            throw new NotFoundException("No domain found for specified nameserver suffix");
        }
        ImmutableList.Builder<Key<HostResource>> builder = new ImmutableList.Builder<>();
        for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) {
            // We can't just check that the host name starts with the initial query string, because then
            // the query ns.exam*.example.com would match against nameserver ns.example.com.
            if (partialStringQuery.matches(fqhn)) {
                Key<HostResource> hostKey = loadAndGetKey(HostResource.class, fqhn, now);
                if (hostKey != null) {
                    builder.add(hostKey);
                }
            }
        }
        return builder.build();
    }
}