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.python.CxxPythonExtensionDescription.java

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

    Optional<Map.Entry<Flavor, CxxPlatform>> platform = cxxPlatforms.getFlavorAndValue(params.getBuildTarget());
    if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(ruleResolver, args, platform.get().getValue(),
                params);//from   w  w  w  .  j  a v a  2  s.  c om
    }
    // See if we're building a particular "type" of this library, and if so, extract
    // it as an enum.
    final Optional<Map.Entry<Flavor, Type>> type = LIBRARY_TYPE.getFlavorAndValue(params.getBuildTarget());
    final Optional<Map.Entry<Flavor, PythonPlatform>> pythonPlatform = pythonPlatforms
            .getFlavorAndValue(params.getBuildTarget());

    // If we *are* building a specific type of this lib, call into the type specific
    // rule builder methods.  Currently, we only support building a shared lib from the
    // pre-existing static lib, which we do here.
    if (type.isPresent() && platform.isPresent() && pythonPlatform.isPresent()) {
        Preconditions.checkState(type.get().getValue() == Type.EXTENSION);
        return createExtensionBuildRule(
                params.copyWithDeps(
                        Suppliers.ofInstance(ImmutableSortedSet.copyOf(
                                getPlatformDeps(params, ruleResolver, pythonPlatform.get().getValue(), args))),
                        Suppliers.ofInstance(ImmutableSortedSet.of())),
                ruleResolver, pythonPlatform.get().getValue(), platform.get().getValue(), args);
    }

    // Otherwise, we return the generic placeholder of this library, that dependents can use
    // get the real build rules via querying the action graph.
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Path baseModule = PythonUtil.getBasePath(params.getBuildTarget(), args.baseModule);
    String moduleName = args.moduleName.orElse(params.getBuildTarget().getShortName());
    final Path module = baseModule.resolve(getExtensionName(moduleName));
    return new CxxPythonExtension(params, pathResolver) {

        @Override
        protected BuildRule getExtension(PythonPlatform pythonPlatform, CxxPlatform cxxPlatform)
                throws NoSuchBuildTargetException {
            return ruleResolver.requireRule(getBuildTarget().withAppendedFlavors(pythonPlatform.getFlavor(),
                    cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR));
        }

        @Override
        public Path getModule() {
            return module;
        }

        @Override
        public PythonPackageComponents getPythonPackageComponents(PythonPlatform pythonPlatform,
                CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
            BuildRule extension = getExtension(pythonPlatform, cxxPlatform);
            SourcePath output = new BuildTargetSourcePath(extension.getBuildTarget());
            return PythonPackageComponents.of(ImmutableMap.of(module, output), ImmutableMap.of(),
                    ImmutableMap.of(), ImmutableSet.of(), Optional.of(false));
        }

        @Override
        public NativeLinkTarget getNativeLinkTarget(final PythonPlatform pythonPlatform) {
            return new NativeLinkTarget() {

                @Override
                public BuildTarget getBuildTarget() {
                    return params.getBuildTarget().withAppendedFlavors(pythonPlatform.getFlavor());
                }

                @Override
                public NativeLinkTargetMode getNativeLinkTargetMode(CxxPlatform cxxPlatform) {
                    return NativeLinkTargetMode.library();
                }

                @Override
                public Iterable<? extends NativeLinkable> getNativeLinkTargetDeps(CxxPlatform cxxPlatform) {
                    return FluentIterable.from(getPlatformDeps(params, ruleResolver, pythonPlatform, args))
                            .filter(NativeLinkable.class);
                }

                @Override
                public NativeLinkableInput getNativeLinkTargetInput(CxxPlatform cxxPlatform)
                        throws NoSuchBuildTargetException {
                    return NativeLinkableInput.builder()
                            .addAllArgs(getExtensionArgs(
                                    params.copyWithChanges(
                                            params.getBuildTarget().withAppendedFlavors(
                                                    pythonPlatform.getFlavor(),
                                                    CxxDescriptionEnhancer.SHARED_FLAVOR),
                                            Suppliers.ofInstance(ImmutableSortedSet.copyOf(getPlatformDeps(
                                                    params, ruleResolver, pythonPlatform, args))),
                                            Suppliers.ofInstance(ImmutableSortedSet.of())),
                                    ruleResolver, pathResolver, ruleFinder, cxxPlatform, args))
                            .addAllFrameworks(args.frameworks).build();
                }

                @Override
                public Optional<Path> getNativeLinkTargetOutputPath(CxxPlatform cxxPlatform) {
                    return Optional.empty();
                }

            };
        }

        @Override
        public Stream<SourcePath> getRuntimeDeps() {
            return getDeclaredDeps().stream().map(HasBuildTarget::getBuildTarget)
                    .map(BuildTargetSourcePath::new);
        }

    };
}

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

private Optional<Path> findNdkFromRepository(Path repository) {
    ImmutableSortedSet<Path> repositoryContents;
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(repository)) {
        repositoryContents = ImmutableSortedSet.copyOf(stream);
    } catch (IOException e) {
        ndkErrorMessage = Optional.of("Unable to read contents of Android ndk.repository or "
                + "ANDROID_NDK_REPOSITORY at " + repository);
        return Optional.empty();
    }//from w ww .ja  v  a2  s.  c  o m

    Optional<Path> ndkPath = Optional.empty();
    if (!repositoryContents.isEmpty()) {
        Optional<String> newestVersion = Optional.empty();
        VersionStringComparator versionComparator = new VersionStringComparator();
        for (Path potentialNdkPath : repositoryContents) {
            if (potentialNdkPath.toFile().isDirectory()) {
                Optional<String> ndkVersion = findNdkVersion(potentialNdkPath);
                if (ndkVersion.isPresent()) {
                    if (targetNdkVersion.isPresent()) {
                        if (versionsMatch(targetNdkVersion.get(), ndkVersion.get())) {
                            return Optional.of(potentialNdkPath);
                        }
                    } else {
                        if (!newestVersion.isPresent()
                                || versionComparator.compare(ndkVersion.get(), newestVersion.get()) > 0) {
                            ndkPath = Optional.of(potentialNdkPath);
                            newestVersion = Optional.of(ndkVersion.get());
                        }
                    }
                }
            }
        }
    }
    if (!ndkPath.isPresent()) {
        ndkErrorMessage = Optional.of("Couldn't find a valid NDK under " + repository);
        return Optional.empty();
    } else if (targetNdkVersion.isPresent()) {
        ndkErrorMessage = Optional.of("Buck is configured to use Android NDK version " + targetNdkVersion.get()
                + " at ANDROID_NDK_REPOSITORY or ndk.repository but the "
                + "repository does not contain that version.");
        return Optional.empty();
    }
    return ndkPath;
}

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

@Override
protected RuleKey.Builder ruleKeyBuilder() {
    return super.ruleKeyBuilder().set("srcs", srcs).set("resources", resources)
            .set("classpathEntries", ImmutableSortedSet.copyOf(getDeclaredClasspathEntries().values()))
            .set("isAndroidLibrary", isAndroidRule()).set("sourceLevel", sourceLevel)
            .set("targetLevel", targetLevel).set("exportDeps", exportDeps);
}

From source file:org.apache.flume.channel.file.EventQueueBackingStoreFile.java

@Override
ImmutableSortedSet<Integer> getReferenceCounts() {
    return ImmutableSortedSet.copyOf(logFileIDReferenceCounts.keySet());
}

From source file:com.google.devtools.build.lib.packages.Package.java

/**
 * Package initialization: part 3 of 3: applies all other settings and completes
 * initialization of the package.// w w  w.  ja  va2s.  com
 *
 * <p>Only after this method is called can this package be considered "complete"
 * and be shared publicly.
 */
protected void finishInit(Builder builder) {
    // If any error occurred during evaluation of this package, consider all
    // rules in the package to be "in error" also (even if they were evaluated
    // prior to the error).  This behaviour is arguably stricter than need be,
    // but stopping a build only for some errors but not others creates user
    // confusion.
    if (builder.containsErrors) {
        for (Rule rule : builder.getTargets(Rule.class)) {
            rule.setContainsErrors();
        }
    }
    this.filename = builder.getFilename();
    this.packageDirectory = filename.getParentDirectory();

    this.sourceRoot = getSourceRoot(filename, packageIdentifier.getSourceRoot());
    if ((sourceRoot == null
            || !sourceRoot.getRelative(packageIdentifier.getSourceRoot()).equals(packageDirectory))
            && !filename.getBaseName().equals("WORKSPACE")) {
        throw new IllegalArgumentException(
                "Invalid BUILD file name for package '" + packageIdentifier + "': " + filename);
    }

    this.makeEnv = builder.makeEnv.build();
    this.targets = ImmutableSortedKeyMap.copyOf(builder.targets);
    this.defaultVisibility = builder.defaultVisibility;
    this.defaultVisibilitySet = builder.defaultVisibilitySet;
    if (builder.defaultCopts == null) {
        this.defaultCopts = ImmutableList.of();
    } else {
        this.defaultCopts = ImmutableList.copyOf(builder.defaultCopts);
    }
    this.buildFile = builder.buildFile;
    this.containsErrors = builder.containsErrors;
    this.subincludes = builder.subincludes.keySet();
    this.skylarkFileDependencies = builder.skylarkFileDependencies;
    this.defaultLicense = builder.defaultLicense;
    this.defaultDistributionSet = builder.defaultDistributionSet;
    this.features = ImmutableSortedSet.copyOf(builder.features);
    this.events = ImmutableList.copyOf(builder.events);
}

From source file:edu.mit.streamjit.impl.compiler2.Actor.java

public ImmutableSortedSet<Integer> translateInputIndices(final int input, Set<Integer> logicalIndices) {
    return ImmutableSortedSet
            .copyOf(Collections2.transform(logicalIndices, index -> translateInputIndex(input, index)));
}

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

@Override
public ImmutableSortedSet<BuildRule> getDepsForTransitiveClasspathEntries() {
    return ImmutableSortedSet.copyOf(Sets.union(getDeclaredDeps(), exportedDeps));
}

From source file:edu.mit.streamjit.impl.compiler.Compiler.java

/**
 * Fuses StreamNodes as directed by the configuration.
 *//*w ww.  j a v  a2  s  . c o  m*/
private void fuse() {
    //TODO: check this works/doesn't work with peeking or state.
    Set<Integer> eligible = new HashSet<>();
    for (StreamNode n : streamNodes.values()) {
        SwitchParameter<Boolean> parameter = config.getParameter("fuse" + n.id, SwitchParameter.class,
                Boolean.class);
        if (!n.isPeeking() && parameter.getValue())
            eligible.add(n.id);
    }

    boolean fused;
    do {
        fused = false;
        ImmutableSortedSet<StreamNode> nodes = ImmutableSortedSet.copyOf(streamNodes.values());
        for (StreamNode n : nodes) {
            Set<StreamNode> preds = n.predecessorNodes();
            if (eligible.contains(n.id) && preds.size() == 1) {
                new StreamNode(preds.iterator().next(), n); //adds itself to maps
                fused = true;
            }
        }
    } while (fused);
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

private String propertyDescription(ModelSchemaExtractionContext<?> parentContext, ModelProperty<?> property) {
    if (property.getDeclaredBy().size() == 1 && property.getDeclaredBy().contains(parentContext.getType())) {
        return String.format("property '%s'", property.getName());
    } else {/*from   w  w w.j  a v  a  2s.  c o m*/
        ImmutableSortedSet<String> declaredBy = ImmutableSortedSet
                .copyOf(Iterables.transform(property.getDeclaredBy(), Functions.toStringFunction()));
        return String.format("property '%s' declared by %s", property.getName(),
                Joiner.on(", ").join(declaredBy));
    }
}

From source file:ezbake.security.common.core.EzSecurityTokenUtils.java

public static byte[] serializeToken(final EzSecurityToken token) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dataOutputStream = new DataOutputStream(baos);

    // Validity caveats - who, what, when
    putStringToOutputStream(dataOutputStream, token.getValidity().getIssuedTo(), EzSecurityConstant.CHARSET);
    if (token.getValidity().getIssuedFor() != null && !token.getValidity().getIssuedFor().isEmpty()) {
        putStringToOutputStream(dataOutputStream, token.getValidity().getIssuedFor(),
                EzSecurityConstant.CHARSET);
    }/*  ww w.  java 2  s  . co  m*/
    putStringToOutputStream(dataOutputStream, String.valueOf(token.getValidity().getNotAfter()),
            EzSecurityConstant.CHARSET);
    putStringToOutputStream(dataOutputStream, String.valueOf(token.getValidity().getNotBefore()),
            EzSecurityConstant.CHARSET);
    putStringToOutputStream(dataOutputStream, String.valueOf(token.getValidity().getIssuedTime()),
            EzSecurityConstant.CHARSET);

    // Token Type
    putStringToOutputStream(dataOutputStream, token.getType().toString(), EzSecurityConstant.CHARSET);

    // Principal - just the identifying information. The principal has it's own signature that should verify the rest
    putStringToOutputStream(dataOutputStream, token.getTokenPrincipal().getPrincipal(),
            EzSecurityConstant.CHARSET);
    if (token.getTokenPrincipal().getIssuer() != null) {
        dataOutputStream.write(token.getTokenPrincipal().getIssuer().getBytes(StandardCharsets.UTF_8));
    }
    if (token.getTokenPrincipal().getRequestChain() != null) {
        for (String chain : token.getTokenPrincipal().getRequestChain()) {
            putStringToOutputStream(dataOutputStream, chain, EzSecurityConstant.CHARSET);
        }
    }

    // Authorizations
    if (token.getAuthorizationLevel() != null && !token.getAuthorizationLevel().isEmpty()) {
        putStringToOutputStream(dataOutputStream, token.getAuthorizationLevel(), EzSecurityConstant.CHARSET);
    }
    if (token.getAuthorizations() != null) {
        if (token.getAuthorizations().getFormalAuthorizations() != null) {
            Set<String> auths = ImmutableSortedSet.copyOf(token.getAuthorizations().getFormalAuthorizations());
            for (String auth : auths) {
                putStringToOutputStream(dataOutputStream, auth, EzSecurityConstant.CHARSET);
            }
        }
        if (token.getAuthorizations().getExternalCommunityAuthorizations() != null) {
            Set<String> auths = ImmutableSortedSet
                    .copyOf(token.getAuthorizations().getExternalCommunityAuthorizations());
            for (String auth : auths) {
                putStringToOutputStream(dataOutputStream, auth, EzSecurityConstant.CHARSET);
            }
        }
        if (token.getAuthorizations().getPlatformObjectAuthorizations() != null) {
            Set<Long> auths = ImmutableSortedSet
                    .copyOf(token.getAuthorizations().getPlatformObjectAuthorizations());
            for (Long auth : auths) {
                putStringToOutputStream(dataOutputStream, Long.toString(auth), EzSecurityConstant.CHARSET);
            }
        }
    }

    if (token.getExternalProjectGroups() != null) {
        token.setExternalProjectGroups(ImmutableSortedMap.copyOf(token.getExternalProjectGroups()));
        for (Map.Entry<String, List<String>> project : token.getExternalProjectGroups().entrySet()) {
            putStringToOutputStream(dataOutputStream, project.getKey(), EzSecurityConstant.CHARSET);
            Collections.sort(project.getValue());
            for (String group : project.getValue()) {
                putStringToOutputStream(dataOutputStream, group, EzSecurityConstant.CHARSET);
            }
        }
    }

    if (token.getExternalCommunities() != null) {
        for (Map.Entry<String, CommunityMembership> entry : token.getExternalCommunities().entrySet()) {
            CommunityMembership community = entry.getValue();
            putStringToOutputStream(dataOutputStream, community.getName(), EzSecurityConstant.CHARSET);
            putStringToOutputStream(dataOutputStream, community.getType(), EzSecurityConstant.CHARSET);
            putStringToOutputStream(dataOutputStream, community.getOrganization(), EzSecurityConstant.CHARSET);
            Collections.sort(community.getGroups());
            for (String groups : community.getGroups()) {
                putStringToOutputStream(dataOutputStream, groups, EzSecurityConstant.CHARSET);
            }
            Collections.sort(community.getTopics());
            for (String topics : community.getTopics()) {
                putStringToOutputStream(dataOutputStream, topics, EzSecurityConstant.CHARSET);
            }
            Collections.sort(community.getRegions());
            for (String regions : community.getRegions()) {
                putStringToOutputStream(dataOutputStream, regions, EzSecurityConstant.CHARSET);
            }
            if (entry.getValue().getFlags() != null) {
                Map<String, Boolean> flags = ImmutableSortedMap.copyOf(entry.getValue().getFlags());
                for (Map.Entry<String, Boolean> fentry : flags.entrySet()) {
                    dataOutputStream.write(fentry.getKey().getBytes(StandardCharsets.UTF_8));
                    dataOutputStream
                            .write(Boolean.toString(fentry.getValue()).getBytes(StandardCharsets.UTF_8));
                }
            }
        }
    }

    putStringToOutputStream(dataOutputStream, String.valueOf(token.isValidForExternalRequest()),
            EzSecurityConstant.CHARSET);
    putStringToOutputStream(dataOutputStream, token.getCitizenship(), EzSecurityConstant.CHARSET);
    putStringToOutputStream(dataOutputStream, token.getOrganization(), EzSecurityConstant.CHARSET);

    dataOutputStream.flush();
    return baos.toByteArray();
}