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.google.devtools.build.lib.rules.android.ProguardHelper.java

/**
 * Retrieves the full set of proguard specs that should be applied to this binary, including the
 * specs passed in, if Proguard should run on the given rule.  {@link #createProguardAction}
 * relies on this method returning an empty list if the given rule doesn't declare specs in
 * --java_optimization_mode=legacy./*from  w  w  w  . ja  v  a2  s . co  m*/
 *
 * <p>If Proguard shouldn't be applied, or the legacy link mode is used and there are no
 * proguard_specs on this rule, an empty list will be returned, regardless of any given specs or
 * specs from dependencies.  {@link AndroidBinary#createAndroidBinary} relies on that behavior.
 */
public static ImmutableList<Artifact> collectTransitiveProguardSpecs(RuleContext ruleContext,
        Artifact... specsToInclude) {
    JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext);
    if (optMode == JavaOptimizationMode.NOOP) {
        return ImmutableList.of();
    }

    ImmutableList<Artifact> proguardSpecs = ruleContext.attributes().has(PROGUARD_SPECS, BuildType.LABEL_LIST)
            ? ruleContext.getPrerequisiteArtifacts(PROGUARD_SPECS, Mode.TARGET).list()
            : ImmutableList.<Artifact>of();
    if (optMode == JavaOptimizationMode.LEGACY && proguardSpecs.isEmpty()) {
        return ImmutableList.of();
    }

    // TODO(bazel-team): In modes except LEGACY verify that proguard specs don't include -dont...
    // flags since those flags would override the desired optMode
    ImmutableSortedSet.Builder<Artifact> builder = ImmutableSortedSet.orderedBy(Artifact.EXEC_PATH_COMPARATOR)
            .addAll(proguardSpecs).add(specsToInclude)
            .addAll(ruleContext.getPrerequisiteArtifacts(":extra_proguard_specs", Mode.TARGET).list());
    for (ProguardSpecProvider dep : ruleContext.getPrerequisites("deps", Mode.TARGET,
            ProguardSpecProvider.class)) {
        builder.addAll(dep.getTransitiveProguardSpecs());
    }

    // Generate and include implicit Proguard spec for requested mode.
    if (!optMode.getImplicitProguardDirectives().isEmpty()) {
        Artifact implicitDirectives = getProguardConfigArtifact(ruleContext, optMode.name().toLowerCase());
        ruleContext.registerAction(new FileWriteAction(ruleContext.getActionOwner(), implicitDirectives,
                optMode.getImplicitProguardDirectives(), /*executable*/ false));
        builder.add(implicitDirectives);
    }

    return builder.build().asList();
}

From source file:com.facebook.buck.util.MoreCollectors.java

/**
 * Returns a {@code Collector} that builds an {@code ImmutableSortedSet}.
 *
 * This {@code Collector} behaves similar to:
 * {@code Collectors.collectingAndThen(//ww  w . j a  va 2  s .com
 *    Collectors.toList(), list -> ImmutableSortedSet.copyOf(comparator, list))
 *  }
 *  but without building the intermediate list.
 *
 * @param <T> the type of the input elements
 * @param ordering comparator used to order the elements.
 * @return a {@code Collector} that builds an {@code ImmutableSortedSet}.
 */
public static <T> Collector<T, ?, ImmutableSortedSet<T>> toImmutableSortedSet(Comparator<? super T> ordering) {
    return Collector.of(() -> new ImmutableSortedSet.Builder<T>(ordering), ImmutableSortedSet.Builder::add,
            (left, right) -> left.addAll(right.build()), ImmutableSortedSet.Builder::build);
}

From source file:org.sonar.core.test.DefaultTestable.java

public SortedSet<Integer> testedLines() {
    ImmutableSortedSet.Builder<Integer> coveredLines = ImmutableSortedSet.naturalOrder();
    for (Edge edge : coverEdges()) {
        coveredLines.addAll(lines(edge));
    }//from   w w w. j  a va2 s.c om
    return coveredLines.build();
}

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

/**
 * Gets the numeric api levels from the contents of the platforms directory in descending order.
 *
 * <p>Note that the directory entries are assumed to match {@code android-[0-9]+}. Any directory
 * entries that are not directories or do not match that pattern are ignored.
 *///from w  w  w.ja va2  s. c om
static final ImmutableSortedSet<Integer> getApiLevels(Dirents platformsDirectories) {
    ImmutableSortedSet.Builder<Integer> apiLevels = ImmutableSortedSet.reverseOrder();
    for (Dirent platformDirectory : platformsDirectories) {
        if (platformDirectory.getType() != Dirent.Type.DIRECTORY) {
            continue;
        }
        Matcher matcher = PLATFORMS_API_LEVEL_PATTERN.matcher(platformDirectory.getName());
        if (matcher.matches()) {
            apiLevels.add(Integer.parseInt(matcher.group(1)));
        }
    }
    return apiLevels.build();
}

From source file:com.facebook.buck.core.module.impl.DefaultBuckModuleManager.java

@Override
public ImmutableSortedSet<String> getModuleIds() {
    ImmutableSortedSet.Builder<String> moduleIds = ImmutableSortedSet.naturalOrder();
    for (PluginWrapper pluginWrapper : pluginManager.getPlugins()) {
        moduleIds.add(pluginWrapper.getPluginId());
    }// www.ja  v  a2  s.  c om
    return moduleIds.build();
}

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

@Override
public ImmutableSortedSet<String> getGeneratedSources(BuildTarget target, ThriftConstructorArg args,
        String thriftName, ImmutableList<String> services) {

    Path prefix = PythonUtil.getBasePath(target, getBaseModule(args))
            .resolve(Files.getNameWithoutExtension(thriftName));

    ImmutableSortedSet.Builder<String> sources = ImmutableSortedSet.naturalOrder();

    sources.add(prefix.resolve("constants.py").toString());
    sources.add(prefix.resolve("ttypes.py").toString());

    for (String service : services) {
        sources.add(prefix.resolve(service + ".py").toString());
        if (type == Type.NORMAL) {
            sources.add(prefix.resolve(service + "-remote").toString());
        }/* w ww  . ja v  a 2  s.  c om*/
    }

    return sources.build();
}

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

@Override
protected Iterable<String> getInputsToCompareToOutput(BuildContext context) {
    // Build a sorted set so that metaInfDirectory contents are listed in a canonical order.
    ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();

    if (manifestFile != null) {
        builder.add(manifestFile);// w w  w .jav a  2s .  c o m
    }

    addMetaInfContents(builder);

    return builder.build();
}

From source file:com.proofpoint.jmx.JmxInspector.java

private void addConfig(Multimap<String, String> nameMap, Class<?> clazz,
        ImmutableSortedSet.Builder<InspectorRecord> builder)
        throws InvocationTargetException, IllegalAccessException {
    Collection<String> thisNameList = nameMap.get(clazz.getName());
    if (thisNameList != null) {
        for (Method method : clazz.getMethods()) {
            Managed configAnnotation = method.getAnnotation(Managed.class);
            if (configAnnotation != null) {
                for (String thisName : thisNameList) {
                    builder.add(new InspectorRecord(thisName, method.getName(), configAnnotation.description(),
                            getType(method)));
                }/*  ww  w .java  2 s .c  om*/
            }
        }
    }
}

From source file:org.apache.calcite.jdbc.SimpleCalciteSchema.java

protected void addImplicitTableToBuilder(ImmutableSortedSet.Builder<String> builder) {
    builder.addAll(schema.getTableNames());
}

From source file:com.facebook.buck.versions.TargetNodeTranslator.java

public <A extends Comparable<?>> Optional<ImmutableSortedSet<A>> translateSortedSet(ImmutableSortedSet<A> val) {
    boolean modified = false;
    ImmutableSortedSet.Builder<A> builder = ImmutableSortedSet.naturalOrder();
    for (A a : val) {
        Optional<A> item = translate(a);
        modified = modified || item.isPresent();
        builder.add(item.orElse(a));/*from   www  . ja  v a2s  . com*/
    }
    return modified ? Optional.of(builder.build()) : Optional.empty();
}