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:edu.mit.streamjit.impl.compiler2.MapConcreteStorage.java

@Override
public void adjust() {
    //This is pretty slow, but we need them in order so we don't overwrite.
    ImmutableSortedSet<Integer> indices = ImmutableSortedSet.copyOf(map.keySet());
    for (int i : indices) {
        int newReadIndex = i - throughput;
        Object item = map.remove(i);
        if (newReadIndex >= minReadIndex) {
            Object overwrote = map.put(newReadIndex, item);
            assert overwrote == null : newReadIndex;
        }/*from   w ww . j av a2s  .c o  m*/
    }
}

From source file:com.google.enterprise.connector.importexport.DumpConnectors.java

@Override
public void run(CommandLine commandLine) throws Exception {
    // Must specify output filename.
    String[] args = commandLine.getArgs();

    initStandAloneContext(false);//from   ww  w .  j  a  va2  s .  c  om
    // Since we did not start the Context, we need to init TypeMap.
    getTypeMap().init();

    try {
        // If user asks for a list of available Connectors, print it and exit.
        if (commandLine.hasOption("list")) {
            listConnectors();
            return;
        }

        // Determine which connectors to export.
        Collection<String> connectors = null;
        String[] connectorNames = commandLine.getOptionValues('c');
        if (connectorNames != null) {
            connectors = ImmutableSortedSet.copyOf(connectorNames);
        }

        // Must specify output file.
        if (args.length != 1) {
            printUsage();
            return;
        }

        // Write the connector configurations out to the specified file.
        PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(args[0]), "UTF-8"));
        getExportConnectors().getConnectors(connectors).toXml(out, 0);
        out.close();
    } finally {
        shutdown();
    }
}

From source file:com.google.devtools.moe.client.config.ProjectConfig.java

/**
 * Returns the {@link RepositoryConfig} in this config with the given name.
 *
 * @throws MoeProblem if no such repository with the given name exists
 *///from www.  ja v  a 2 s.  co  m
public RepositoryConfig getRepositoryConfig(String repositoryName) {
    if (!repositories().containsKey(repositoryName)) {
        throw new MoeProblem("No such repository '%s' in the config. Found: %s", repositoryName,
                ImmutableSortedSet.copyOf(repositories().keySet()));
    }
    return repositories().get(repositoryName);
}

From source file:com.opengamma.id.ExternalIdBundleWithDates.java

/**
 * Creates a bundle from an array of identifiers.
 * //from   w  w w.  j a v  a  2 s.c om
 * @param externalIds  the array of identifiers, null returns an empty bundle
 */
public ExternalIdBundleWithDates(ExternalIdWithDates... externalIds) {
    if ((externalIds == null) || (externalIds.length == 0)) {
        _externalIds = ImmutableSortedSet.of();
    } else {
        ArgumentChecker.noNulls(externalIds, "externalIds");
        _externalIds = ImmutableSortedSet.copyOf(externalIds);
    }
}

From source file:org.apache.calcite.rel.core.Match.java

/** Creates an immutable copy of a map of sorted sets. */
private static <K extends Comparable<K>, V> ImmutableSortedMap<K, SortedSet<V>> copy(Map<K, SortedSet<V>> map) {
    final ImmutableSortedMap.Builder<K, SortedSet<V>> b = ImmutableSortedMap.naturalOrder();
    for (Map.Entry<K, SortedSet<V>> e : map.entrySet()) {
        b.put(e.getKey(), ImmutableSortedSet.copyOf(e.getValue()));
    }//from  ww  w . j a  va  2s .  c o m
    return b.build();
}

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

@SuppressWarnings("unchecked")
public <T, U extends Description<T>> TargetNode<T, U> create(HashCode rawInputsHashCode, U description,
        T constructorArg, ProjectFilesystem filesystem, BuildTarget buildTarget,
        ImmutableSet<BuildTarget> declaredDeps, ImmutableSet<VisibilityPattern> visibilityPatterns,
        CellPathResolver cellRoots) throws NoSuchBuildTargetException {

    ImmutableSortedSet.Builder<BuildTarget> extraDepsBuilder = ImmutableSortedSet.naturalOrder();
    ImmutableSet.Builder<Path> pathsBuilder = ImmutableSet.builder();

    // Scan the input to find possible BuildTargets, necessary for loading dependent rules.
    T arg = description.createUnpopulatedConstructorArg();
    for (Field field : arg.getClass().getFields()) {
        ParamInfo info = new ParamInfo(typeCoercerFactory, arg.getClass(), field);
        if (info.isDep() && info.isInput()
                && info.hasElementTypes(BuildTarget.class, SourcePath.class, Path.class)) {
            detectBuildTargetsAndPathsForConstructorArg(extraDepsBuilder, pathsBuilder, info, constructorArg);
        }//w ww.  j a  va2s .c  om
    }

    if (description instanceof ImplicitDepsInferringDescription) {
        extraDepsBuilder.addAll(((ImplicitDepsInferringDescription<T>) description)
                .findDepsForTargetFromConstructorArgs(buildTarget, cellRoots, constructorArg));
    }

    if (description instanceof ImplicitInputsInferringDescription) {
        pathsBuilder.addAll(((ImplicitInputsInferringDescription<T>) description)
                .inferInputsFromConstructorArgs(buildTarget.getUnflavoredBuildTarget(), constructorArg));
    }

    return new TargetNode<>(this, rawInputsHashCode, description, constructorArg, filesystem, buildTarget,
            declaredDeps, ImmutableSortedSet.copyOf(Sets.difference(extraDepsBuilder.build(), declaredDeps)),
            visibilityPatterns, pathsBuilder.build(), cellRoots, Optional.empty());
}

From source file:uk.ac.ebi.atlas.model.baseline.ExperimentalFactors.java

public ImmutableSortedSet<Factor> getFactors(String type) {

    return ImmutableSortedSet.copyOf(factorsByType.get(type));

}

From source file:com.facebook.buck.features.js.JsUtil.java

static BuildRuleParams paramsWithDeps(BuildRuleParams params, BuildRule... rules) {
    return params.withoutDeclaredDeps().withExtraDeps(ImmutableSortedSet.copyOf(rules));
}

From source file:io.wcm.handler.media.format.impl.MediaFormatHandlerImpl.java

/**
 * Get media formats defined by a CMS application that is responsible for the given media library path.
 * @param comparator Comparator for set/*from  www.jav  a 2 s.  c  o  m*/
 * @return Media formats
 */
@Override
public SortedSet<MediaFormat> getMediaFormats(Comparator<MediaFormat> comparator) {
    SortedSet<MediaFormat> set = new TreeSet<>(comparator);
    set.addAll(getMediaFormatsForApplication());
    return ImmutableSortedSet.copyOf(set);
}

From source file:org.auraframework.impl.css.token.StyleContextImpl.java

/**
 * Builds a new {@link StyleContext} based on the information in the given context, and appends additional
 * {@link TokensDef} descriptors./* w  ww. ja v a  2  s  .com*/
 *
 * @param additionalTokens Append these tokens after the token overrides from the app.
 */
public static StyleContext build(DefinitionService definitionService, AuraContext auraContext,
        Iterable<DefDescriptor<TokensDef>> additionalTokens) {
    // browser
    String client = auraContext.getClient().getType().name();

    // extra true conditions
    ImmutableSortedSet<String> extra = ImmutableSortedSet
            .copyOf(Aura.getStyleAdapter().getExtraTrueConditions());

    // token overrides
    TokenCache tokens = null;
    try {
        DefDescriptor<? extends BaseComponentDef> top = auraContext.getLoadingApplicationDescriptor();
        if (top != null && top.getDefType() == DefType.APPLICATION) {
            List<DefDescriptor<TokensDef>> appOverrides = ((ApplicationDef) definitionService
                    .getDefinition(top)).getTokenOverrides();
            tokens = new TokenCacheImpl(definitionService, Iterables.concat(appOverrides, additionalTokens));
        }
    } catch (QuickFixException e) {
        // either the app or a dependency is invalid, this isn't the place to deal with it though,
        // we have to proceed here without app overrides
    }

    return new StyleContextImpl(client, extra, tokens);
}