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> ImmutableSortedSet<E> copyOf(Comparator<? super E> comparator,
            Iterator<? extends E> elements) 

Source Link

Usage

From source file:kr.co.bitnine.octopus.engine.calcite.CachingCalciteSchema.java

/**
 * Creates a CachingCalciteSchema./*  ww  w.  j a v  a  2  s . c om*/
 */
CachingCalciteSchema(CalciteSchema parent, Schema schema, String name) {
    super(parent, schema, name);
    this.implicitSubSchemaCache = new AbstractCached<SubSchemaCache>() {
        public SubSchemaCache build() {
            return new SubSchemaCache(CachingCalciteSchema.this,
                    Compatible.INSTANCE.navigableSet(ImmutableSortedSet.copyOf(COMPARATOR,
                            CachingCalciteSchema.this.getSchema().getSubSchemaNames())));
        }
    };
    this.implicitTableCache = new AbstractCached<NavigableSet<String>>() {
        public NavigableSet<String> build() {
            return Compatible.INSTANCE.navigableSet(ImmutableSortedSet.copyOf(COMPARATOR,
                    CachingCalciteSchema.this.getSchema().getTableNames()));
        }
    };
    this.implicitFunctionCache = new AbstractCached<NavigableSet<String>>() {
        public NavigableSet<String> build() {
            return Compatible.INSTANCE.navigableSet(ImmutableSortedSet.copyOf(COMPARATOR,
                    CachingCalciteSchema.this.getSchema().getFunctionNames()));
        }
    };
}

From source file:com.facebook.buck.io.file.PathListing.java

/**
 * Lists paths in descending modified time order, excluding any paths which bring the number of
 * files over {@code maxNumPaths} or over {@code totalSizeFilter} bytes in size.
 *//*from  ww w  .  java 2s  .  c  om*/
public static ImmutableSortedSet<Path> listMatchingPathsWithFilters(Path pathToGlob, String globPattern,
        PathModifiedTimeFetcher pathModifiedTimeFetcher, FilterMode filterMode, OptionalInt maxPathsFilter,
        Optional<Long> totalSizeFilter) throws IOException {

    // Fetch the modification time of each path and build a map of
    // (path => modification time) pairs.
    ImmutableMap.Builder<Path, FileTime> pathFileTimesBuilder = ImmutableMap.builder();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathToGlob, globPattern)) {
        for (Path path : stream) {
            try {
                pathFileTimesBuilder.put(path, pathModifiedTimeFetcher.getLastModifiedTime(path));
            } catch (NoSuchFileException e) {
                // Ignore the path.
                continue;
            }
        }
    }
    ImmutableMap<Path, FileTime> pathFileTimes = pathFileTimesBuilder.build();

    ImmutableSortedSet<Path> paths = ImmutableSortedSet.copyOf(Ordering.natural()
            // Order the keys of the map (the paths) by their values (the file modification
            // times).
            .onResultOf(Functions.forMap(pathFileTimes))
            // If two keys of the map have the same value, fall back to key order.
            .compound(Ordering.natural())
            // Use descending order.
            .reverse(), pathFileTimes.keySet());

    paths = applyNumPathsFilter(paths, filterMode, maxPathsFilter);
    paths = applyTotalSizeFilter(paths, filterMode, totalSizeFilter);
    return paths;
}

From source file:com.facebook.buck.io.PathListing.java

/**
 * Lists paths in descending modified time order,
 * excluding any paths which bring the number of files over {@code maxNumPaths}
 * or over {@code totalSizeFilter} bytes in size.
 *//*w  w  w .ja  v  a  2  s .  com*/
public static ImmutableSortedSet<Path> listMatchingPathsWithFilters(Path pathToGlob, String globPattern,
        PathModifiedTimeFetcher pathModifiedTimeFetcher, FilterMode filterMode,
        Optional<Integer> maxPathsFilter, Optional<Long> totalSizeFilter) throws IOException {

    // Fetch the modification time of each path and build a map of
    // (path => modification time) pairs.
    ImmutableMap.Builder<Path, FileTime> pathFileTimesBuilder = ImmutableMap.builder();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathToGlob, globPattern)) {
        for (Path path : stream) {
            try {
                pathFileTimesBuilder.put(path, pathModifiedTimeFetcher.getLastModifiedTime(path));
            } catch (NoSuchFileException e) {
                // Ignore the path.
                continue;
            }
        }
    }
    ImmutableMap<Path, FileTime> pathFileTimes = pathFileTimesBuilder.build();

    ImmutableSortedSet<Path> paths = ImmutableSortedSet.copyOf(Ordering.natural()
            // Order the keys of the map (the paths) by their values (the file modification times).
            .onResultOf(Functions.forMap(pathFileTimes))
            // If two keys of the map have the same value, fall back to key order.
            .compound(Ordering.natural())
            // Use descending order.
            .reverse(), pathFileTimes.keySet());

    paths = applyNumPathsFilter(paths, filterMode, maxPathsFilter);
    paths = applyTotalSizeFilter(paths, filterMode, totalSizeFilter);
    return paths;
}

From source file:org.sonar.server.plugins.ws.InstalledPluginsWsAction.java

private SortedSet<PluginMetadata> retrieveAndSortPluginMetadata() {
    return ImmutableSortedSet.copyOf(NAME_KEY_PLUGIN_METADATA_COMPARATOR,
            filter(pluginRepository.getMetadata(), NotCorePluginsPredicate.INSTANCE));
}

From source file:com.opengamma.financial.security.cds.CDSIndexComponentBundle.java

/**
 * Creates a cdsIndex components bundle from a set of cdsIndex
 * component and a comparator./*  w  ww .  ja va  2  s . c  o  m*/
 *
 * @param components  the set of components assigned, not null
 */
private CDSIndexComponentBundle(Iterable<CreditDefaultSwapIndexComponent> components,
        Comparator<? super CreditDefaultSwapIndexComponent> comparator) {
    ArgumentChecker.notEmpty(components, "components");
    ArgumentChecker.noNulls(components, "components");
    ArgumentChecker.notNull(comparator, "comparator");

    _components = ImmutableSortedSet.copyOf(comparator, deduplicate(components));
    _redCodeMapping = Maps.uniqueIndex(_components,
            new Function<CreditDefaultSwapIndexComponent, ExternalId>() {
                @Override
                public ExternalId apply(CreditDefaultSwapIndexComponent input) {
                    return input.getObligorRedCode();
                }
            });
}

From source file:com.linecorp.armeria.server.docs.MethodInfo.java

/**
 * Creates a new instance./* ww w  .j av a2 s  .  c om*/
 */
public MethodInfo(String name, TypeSignature returnTypeSignature, Iterable<FieldInfo> parameters,
        Iterable<TypeSignature> exceptionTypeSignatures, Iterable<EndpointInfo> endpoints,
        Iterable<HttpHeaders> exampleHttpHeaders, Iterable<String> exampleRequests,
        @Nullable String docString) {

    this.name = requireNonNull(name, "name");

    this.returnTypeSignature = requireNonNull(returnTypeSignature, "returnTypeSignature");
    this.parameters = ImmutableList.copyOf(requireNonNull(parameters, "parameters"));
    this.exceptionTypeSignatures = ImmutableSortedSet.copyOf(comparing(TypeSignature::signature),
            requireNonNull(exceptionTypeSignatures, "exceptionTypeSignatures"));
    this.endpoints = ImmutableSortedSet.copyOf(Comparator.comparing(e -> e.hostnamePattern() + ':' + e.path()),
            requireNonNull(endpoints, "endpoints"));
    this.exampleHttpHeaders = Streams.stream(requireNonNull(exampleHttpHeaders, "exampleHttpHeaders"))
            .map(HttpHeaders::copyOf).map(HttpHeaders::asImmutable).collect(toImmutableList());
    this.exampleRequests = ImmutableList.copyOf(requireNonNull(exampleRequests, "exampleRequests"));
    this.docString = Strings.emptyToNull(docString);
}

From source file:org.sonar.server.plugins.ws.AvailablePluginsWsAction.java

private Collection<PluginUpdate> retrieveAvailablePlugins() {
    return ImmutableSortedSet.copyOf(NAME_KEY_PLUGIN_UPDATE_ORDERING,
            updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH).findAvailablePlugins());
}

From source file:de.cosmocode.palava.salesforce.SalesforceException.java

/**
 * Creates a new SalesforceException using the specified errors.
 * //from www.  j av a 2 s. c om
 * @throws NullPointerException if errors is null
 */
public SalesforceException(List<Error> errors) {
    Preconditions.checkNotNull(errors, "Errors");
    this.errors = ImmutableSortedSet.copyOf(COMPARATOR, errors);
}

From source file:org.sonar.server.plugins.ws.AvailableAction.java

private static Collection<PluginUpdate> retrieveAvailablePlugins(UpdateCenter updateCenter) {
    return ImmutableSortedSet.copyOf(NAME_KEY_PLUGIN_UPDATE_ORDERING, updateCenter.findAvailablePlugins());
}

From source file:org.sonar.server.plugins.ws.UpdatesPluginsWsAction.java

private Collection<PluginUpdate> retrieveUpdatablePlugins() {
    return ImmutableSortedSet.copyOf(NAME_KEY_PLUGIN_UPDATE_ORDERING,
            updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH).findPluginUpdates());
}