Example usage for com.google.common.collect ImmutableSortedMap values

List of usage examples for com.google.common.collect ImmutableSortedMap values

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedMap values.

Prototype

Collection<V> values();

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.facebook.buck.features.haskell.HaskellHaddockLibRule.java

public static HaskellHaddockLibRule from(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams buildRuleParams, SourcePathRuleFinder ruleFinder, HaskellSources sources,
        Tool haddockTool, ImmutableList<String> haddockFlags, ImmutableList<String> compilerFlags,
        ImmutableList<String> linkerFlags, ImmutableSet<SourcePath> interfaces,
        ImmutableSortedMap<String, HaskellPackage> packages,
        ImmutableSortedMap<String, HaskellPackage> exposedPackages, HaskellPackageInfo packageInfo,
        HaskellPlatform platform, Preprocessor preprocessor, PreprocessorFlags ppFlags) {

    ImmutableList.Builder<BuildRule> pkgDeps = ImmutableList.builder();

    for (HaskellPackage pkg : packages.values()) {
        pkgDeps.addAll(pkg.getDeps(ruleFinder).iterator());
    }//from w  ww . j av a 2s .co  m
    for (HaskellPackage pkg : exposedPackages.values()) {
        pkgDeps.addAll(pkg.getDeps(ruleFinder).iterator());
    }

    Supplier<ImmutableSortedSet<BuildRule>> declaredDeps = MoreSuppliers.memoize(() -> ImmutableSortedSet
            .<BuildRule>naturalOrder().addAll(BuildableSupport.getDepsCollection(haddockTool, ruleFinder))
            .addAll(sources.getDeps(ruleFinder)).addAll(ruleFinder.filterBuildRuleInputs(interfaces))
            .addAll(pkgDeps.build()).addAll(ppFlags.getDeps(ruleFinder)).build());
    return new HaskellHaddockLibRule(buildTarget, projectFilesystem,
            buildRuleParams.withDeclaredDeps(declaredDeps).withoutExtraDeps(), sources, haddockTool,
            haddockFlags, compilerFlags, linkerFlags, interfaces, packages, exposedPackages, packageInfo,
            platform, preprocessor, ppFlags);
}

From source file:com.facebook.buck.haskell.HaskellPackageRule.java

public static HaskellPackageRule from(BuildTarget target, BuildRuleParams baseParams,
        final SourcePathResolver resolver, SourcePathRuleFinder ruleFinder, final Tool ghcPkg,
        HaskellVersion haskellVersion, HaskellPackageInfo packageInfo,
        final ImmutableSortedMap<String, HaskellPackage> depPackages, ImmutableSortedSet<String> modules,
        final ImmutableSortedSet<SourcePath> libraries, final ImmutableSortedSet<SourcePath> interfaces) {
    return new HaskellPackageRule(
            baseParams.copyWithChanges(target, Suppliers.memoize(() -> ImmutableSortedSet
                    .<BuildRule>naturalOrder().addAll(ghcPkg.getDeps(ruleFinder))
                    .addAll(depPackages.values().stream().flatMap(pkg -> pkg.getDeps(ruleFinder)).iterator())
                    .addAll(ruleFinder.filterBuildRuleInputs(Iterables.concat(libraries, interfaces))).build()),
                    Suppliers.ofInstance(ImmutableSortedSet.of())),
            resolver, ghcPkg, haskellVersion, packageInfo, depPackages, modules, libraries, interfaces);
}

From source file:edu.mit.streamjit.util.bytecode.methodhandles.Combinators.java

private static MethodHandle lookupswitch(ImmutableSortedMap<Integer, MethodHandle> cases,
        MethodHandle defaultCase) {
    if (cases.isEmpty()) {
        checkArgument(defaultCase.type().parameterList().equals(ImmutableList.of(int.class)),
                "bad type for default case %s", defaultCase.type());
        return defaultCase;
    }//from   w  ww .j a v  a 2  s.c om
    MethodType type = cases.values().iterator().next().type();
    for (MethodHandle mh : cases.values())
        checkArgument(mh.type().equals(type), "type mismatch in %s", cases.values());
    checkArgument(defaultCase.type().equals(type.insertParameterTypes(0, int.class)),
            "bad type for default case %s, other cases %s", defaultCase.type(), type);
    return lookupswitch0(cases, defaultCase);
}

From source file:com.facebook.buck.features.haskell.HaskellPackageRule.java

public static HaskellPackageRule from(BuildTarget target, ProjectFilesystem projectFilesystem,
        BuildRuleParams baseParams, SourcePathRuleFinder ruleFinder, Tool ghcPkg, HaskellVersion haskellVersion,
        Linker.LinkableDepType depType, HaskellPackageInfo packageInfo,
        ImmutableSortedMap<String, HaskellPackage> depPackages, ImmutableSortedSet<String> modules,
        ImmutableSortedSet<SourcePath> libraries, ImmutableSortedSet<SourcePath> interfaces,
        ImmutableSortedSet<SourcePath> objects) {
    Supplier<ImmutableSortedSet<BuildRule>> declaredDeps = MoreSuppliers.memoize(() -> ImmutableSortedSet
            .<BuildRule>naturalOrder().addAll(BuildableSupport.getDepsCollection(ghcPkg, ruleFinder))
            .addAll(depPackages.values().stream().flatMap(pkg -> pkg.getDeps(ruleFinder)).iterator())
            .addAll(ruleFinder.filterBuildRuleInputs(Iterables.concat(libraries, interfaces))).build());
    return new HaskellPackageRule(target, projectFilesystem,
            baseParams.withDeclaredDeps(declaredDeps).withoutExtraDeps(), ghcPkg, haskellVersion, depType,
            packageInfo, depPackages, modules, libraries, interfaces, objects);
}

From source file:edu.mit.streamjit.util.bytecode.methodhandles.Combinators.java

/**
 * Returns a method handle with a leading int argument that selects one of
 * the method handles in the given map, which is invoked with the remaining
 * arguments.  If the leading int argument is not present in the map, an
 * AssertionError will be thrown./*from   w ww .j a va 2  s . co  m*/
 * @param cases the switch cases
 * @return a method handle approximating the switch statement
 */
public static MethodHandle lookupswitch(Map<Integer, MethodHandle> cases) {
    ImmutableSortedMap<Integer, MethodHandle> sortedCases = ImmutableSortedMap.copyOf(cases);
    String validCases = sortedCases.keySet().toString();
    IntConsumer defaultCaseAction = (idx) -> {
        throw new AssertionError(String.format("lookupswitch index %d not in cases %s", idx, validCases));
    };
    MethodHandle defaultCase = INTCONSUMER_ACCEPT.bindTo(defaultCaseAction);
    if (!sortedCases.values().isEmpty()) {
        //just pick an arbitrary element -- we'll catch type mismatches later
        MethodType t = sortedCases.values().iterator().next().type();
        defaultCase = MethodHandles.dropArguments(defaultCase, 1, t.parameterArray());
        defaultCase = defaultCase.asType(defaultCase.type().changeReturnType(t.returnType()));
    }
    return lookupswitch(sortedCases, defaultCase);
}

From source file:io.prestosql.benchmark.driver.RegexTemplate.java

public RegexTemplate(String template) {
    this.template = requireNonNull(template, "template is null");

    try {// w w  w.  j  a v  a 2s .  com
        this.pattern = Pattern.compile(template);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid template: " + template, e);
    }

    Map<String, Integer> namedGroups;
    try {
        namedGroups = (Map<String, Integer>) NAMED_GROUPS_METHOD.invoke(pattern);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
    ImmutableSortedMap<Integer, String> sortedGroups = ImmutableSortedMap
            .copyOf(ImmutableBiMap.copyOf(namedGroups).inverse());
    this.fieldNames = ImmutableList.copyOf(sortedGroups.values());
}

From source file:com.facebook.presto.benchmark.driver.RegexTemplate.java

public RegexTemplate(String template) {
    this.template = requireNonNull(template, "template is null");

    try {/*from   w w  w  .  java  2  s.  co m*/
        this.pattern = Pattern.compile(template);
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid template: " + template, e);
    }

    Map<String, Integer> namedGroups;
    try {
        namedGroups = (Map<String, Integer>) NAMED_GROUPS_METHOD.invoke(pattern);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    ImmutableSortedMap<Integer, String> sortedGroups = ImmutableSortedMap
            .copyOf(ImmutableBiMap.copyOf(namedGroups).inverse());
    this.fieldNames = ImmutableList.copyOf(sortedGroups.values());
}

From source file:org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.java

@Override
// TODO Return a simple Result (that includes the origin metadata) here
public CurrentSnapshotResult execute(C context) {
    CurrentSnapshotResult result = delegate.execute(context);
    ImmutableSortedMap<String, CurrentFileCollectionFingerprint> finalOutputs = result.getFinalOutputs();
    context.getWork().persistResult(finalOutputs, result.getFailure() == null, result.getOriginMetadata());
    outputFilesRepository.recordOutputs(finalOutputs.values());

    return result;
}

From source file:com.facebook.buck.haskell.HaskellGhciRule.java

public static HaskellGhciRule from(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams params, BuildRuleResolver resolver, HaskellSources srcs,
        ImmutableList<String> compilerFlags, Optional<BuildTarget> ghciBinDep, Optional<SourcePath> ghciInit,
        BuildRule omnibusSharedObject, ImmutableSortedMap<String, SourcePath> solibs,
        ImmutableSet<HaskellPackage> firstOrderHaskellPackages, ImmutableSet<HaskellPackage> haskellPackages,
        ImmutableSet<HaskellPackage> prebuiltHaskellPackages, boolean enableProfiling, Path ghciScriptTemplate,
        Path ghciBinutils, Path ghciGhc, Path ghciLib, Path ghciCxx, Path ghciCc, Path ghciCpp) {

    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ImmutableSet.Builder<BuildRule> extraDeps = ImmutableSet.builder();

    extraDeps.add(omnibusSharedObject);/*from  w w  w . j  a v a2 s.  c  o  m*/

    for (HaskellPackage pkg : haskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }

    for (HaskellPackage pkg : prebuiltHaskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }

    if (ghciBinDep.isPresent()) {
        extraDeps.add(resolver.getRule(ghciBinDep.get()));
    }

    extraDeps.addAll(ruleFinder.filterBuildRuleInputs(solibs.values()));

    return new HaskellGhciRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()),
            resolver, srcs, compilerFlags, ghciBinDep, ghciInit, omnibusSharedObject, solibs,
            firstOrderHaskellPackages, haskellPackages, prebuiltHaskellPackages, enableProfiling,
            ghciScriptTemplate, ghciBinutils, ghciGhc, ghciLib, ghciCxx, ghciCc, ghciCpp);
}

From source file:com.facebook.buck.support.cli.args.PluginBasedCommandHelpPrinter.java

/**
 * Prints the text with usage information for the given command to the provided stream.
 *
 * <p>This method divides command options into multiple categories: global options (common to all
 * commands), common options for this command and options for every plugin-based subcommand.
 */// w  ww.  j a  va  2 s  .c  o m
public void printUsage(PluginBasedCommand command, PrintStream stream) {
    printShortDescription(command, stream);
    CmdLineParserWithPrintInformation parser = new CmdLineParserWithPrintInformation(command);
    ImmutableSortedMap<PluginBasedSubCommand, CmdLineParserWithPrintInformation> subCommands = command
            .getSubCommands().stream()
            .collect(ImmutableSortedMap.toImmutableSortedMap(
                    Comparator.comparing(PluginBasedSubCommand::getOptionValue), Functions.identity(),
                    CmdLineParserWithPrintInformation::new));

    int len = calculateTotalMaxLen(parser, subCommands.values());

    OutputStreamWriter writer = new OutputStreamWriter(stream);

    printGlobalOptionsUsage(stream, writer, parser, len);
    printCommonOptionsUsage(stream, writer, parser, len);

    for (Map.Entry<PluginBasedSubCommand, CmdLineParserWithPrintInformation> subCommand : subCommands
            .entrySet()) {
        printSubCommandUsage(stream, writer, subCommand.getKey(), subCommand.getValue(),
                command.getTypeOptionName(), len);
    }

    stream.println();
}