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:org.apache.calcite.jdbc.CalciteSchema.java

/** Returns the list of function names in this schema, both implicit and
 * explicit, never null. *//*  ww  w.j  a v a  2  s.c o  m*/
public final NavigableSet<String> getFunctionNames() {
    final ImmutableSortedSet.Builder<String> builder = new ImmutableSortedSet.Builder<>(NameSet.COMPARATOR);
    // Add explicit functions, case-sensitive.
    builder.addAll(functionMap.map().keySet());
    // Add implicit functions, case-sensitive.
    addImplicitFuncNamesToBuilder(builder);
    return Compatible.INSTANCE.navigableSet(builder.build());
}

From source file:org.cyclop.service.cassandra.intern.QueryServiceImpl.java

protected void loadPartitionKeyNames(Optional<CqlTable> table,
        ImmutableSortedSet.Builder<CqlColumnName> cqlColumnNames) {

}

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

/**
 * Returns the indices written in this storage during an execution of the
 * given schedule.  The returned set is not cached so as to be responsive
 * to changes in output index functions.
 * @param externalSchedule the schedule//from  www.ja  v  a  2s.  c om
 * @return the indices written during the given schedule under the current
 * index functions
 * @see #writeIndexSpan(java.util.Map)
 */
public ImmutableSortedSet<Integer> writeIndices(Map<ActorGroup, Integer> externalSchedule) {
    ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder();
    for (Actor a : upstream())
        builder.addAll(a.writes(this,
                Range.closedOpen(0, a.group().schedule().get(a) * externalSchedule.get(a.group()))));
    return builder.build();
}

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

/**
 * Returns the set of all table names. Includes implicit and explicit tables
 * and functions with zero parameters.//from  w  w  w. ja v a 2s.  c  o m
 */
public final NavigableSet<String> getTableNames() {
    final ImmutableSortedSet.Builder<String> builder = new ImmutableSortedSet.Builder<>(COMPARATOR);
    // Add explicit tables, case-sensitive.
    builder.addAll(tableMap.keySet());
    // Add implicit tables, case-sensitive.
    addImplicitTableToBuilder(builder);
    return Compatible.INSTANCE.navigableSet(builder.build());
}

From source file:com.facebook.buck.java.JavaSymbolFinder.java

/**
 * Guessing file names from fully-qualified Java symbols is ambiguous, because we don't know ahead
 * of time exactly what part of the symbol is the package, and what part is class names or static
 * members. This returns the set of all possible Java files for a given symbol, given different
 * possibilities for the package name and resolving against all the available source roots.
 * Returns only those candidates that actually exist.
 *///from w ww.j a va2 s.  c o m
private ImmutableSortedSet<Path> getCandidatePaths(String symbol, Collection<Path> srcRoots) {
    ImmutableSortedSet.Builder<Path> candidatePaths = ImmutableSortedSet.naturalOrder();
    List<String> symbolParts = Lists.newArrayList(symbol.split("\\."));
    for (int symbolIndex = 0; symbolIndex < symbolParts.size(); symbolIndex++) {
        List<String> pathPartsList = symbolParts.subList(0, symbolIndex);
        String[] pathParts = pathPartsList.toArray(new String[pathPartsList.size()]);
        String candidateFileName = symbolParts.get(symbolIndex) + ".java";
        for (Path srcRoot : srcRoots) {
            Path candidatePath = srcRoot.resolve(Paths.get("", pathParts)).resolve(candidateFileName);
            if (projectFilesystem.exists(candidatePath)) {
                candidatePaths.add(candidatePath);
            }
        }
    }
    return candidatePaths.build();
}

From source file:org.dishevelled.collect.Sets.java

/**
  * Create and return an immutable sorted set containing the unique elements in the specified iterator
  * sorted according to the specified comparator. The returned immutable sorted set is a high-performance,
  * immutable <code>SortedSet</code> that stores its elements in a sorted array.
  */*from  ww  w . ja v a2 s.  c  om*/
  * @param <T> element type
  * @param iterator iterator, must not be null
  * @param comparator comparator to be used to sort the returned immutable sorted set
  * @return an immutable set containing the unique elements returned by the specified iterator
  *    sorted according to the specified comparator
  */
public static <T extends Comparable<? super T>> SortedSet<T> asImmutableSortedSet(
        final Iterator<? extends T> iterator, final Comparator<? super T> comparator) {
    if (iterator == null) {
        throw new IllegalArgumentException("iterator must not be null");
    }
    if (comparator == null) {
        return asImmutableSortedSet(iterator);
    }
    ImmutableSortedSet.Builder<T> builder = new ImmutableSortedSet.Builder<T>(comparator);
    builder.addAll(iterator);
    return builder.build();
}

From source file:com.facebook.buck.apple.AppleDescriptions.java

public static Optional<AppleAssetCatalog> createBuildRuleForTransitiveAssetCatalogDependencies(
        TargetGraph targetGraph, BuildRuleParams params, SourcePathResolver sourcePathResolver,
        ApplePlatform applePlatform, Tool actool) {
    TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());

    ImmutableSet<AppleAssetCatalogDescription.Arg> assetCatalogArgs = AppleBuildRules
            .collectRecursiveAssetCatalogs(targetGraph, Optional.empty(), ImmutableList.of(targetNode));

    ImmutableSortedSet.Builder<SourcePath> assetCatalogDirsBuilder = ImmutableSortedSet.naturalOrder();

    Optional<String> appIcon = Optional.empty();
    Optional<String> launchImage = Optional.empty();

    AppleAssetCatalogDescription.Optimization optimization = null;

    for (AppleAssetCatalogDescription.Arg arg : assetCatalogArgs) {
        if (optimization == null) {
            optimization = arg.optimization;
        }/*from  w  w w. ja v a 2  s  .co  m*/

        assetCatalogDirsBuilder.addAll(arg.dirs);
        if (arg.appIcon.isPresent()) {
            if (appIcon.isPresent()) {
                throw new HumanReadableException(
                        "At most one asset catalog in the dependencies of %s " + "can have a app_icon",
                        params.getBuildTarget());
            }

            appIcon = arg.appIcon;
        }

        if (arg.launchImage.isPresent()) {
            if (launchImage.isPresent()) {
                throw new HumanReadableException(
                        "At most one asset catalog in the dependencies of %s " + "can have a launch_image",
                        params.getBuildTarget());
            }

            launchImage = arg.launchImage;
        }

        if (arg.optimization != optimization) {
            throw new HumanReadableException(
                    "At most one asset catalog optimisation style can be " + "specified in the dependencies %s",
                    params.getBuildTarget());
        }
    }

    ImmutableSortedSet<SourcePath> assetCatalogDirs = assetCatalogDirsBuilder.build();

    if (assetCatalogDirs.isEmpty()) {
        return Optional.empty();
    }

    BuildRuleParams assetCatalogParams = params.copyWithChanges(
            params.getBuildTarget().withAppendedFlavors(AppleAssetCatalog.FLAVOR),
            Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));

    return Optional.of(new AppleAssetCatalog(assetCatalogParams, sourcePathResolver, applePlatform.getName(),
            actool, assetCatalogDirs, appIcon, launchImage, optimization, MERGED_ASSET_CATALOG_NAME));
}

From source file:com.lyndir.lhunath.opal.system.util.ObjectUtils.java

/**
 * Generate a decent generic {@link Object#hashCode()} for the given object using its fields.  The fields used depend on how the
 * object's type has been annotated with {@link ObjectMeta}.
 *
 * @param o The object for which a hashCode should be generated (inside your {@link Object#equals(Object)}, use {@code this}).
 *
 * @return A hashCode of specific field values of the given object.
 *//*from  ww  w.j  a  v a2 s .c  o  m*/
public static int hashCode(final Object o) {

    int identityHashCode = System.identityHashCode(o);
    logger.trc("%sHashCode for: %s (%d)", StringUtils.indent(seen.get(For.hashCode).get().size()), //
            o.getClass().getName(), identityHashCode);

    if (seen.get(For.hashCode).get().contains(identityHashCode)) {
        // Cyclic reference.
        logger.trc("%s- Detected cycle, returning identity.",
                StringUtils.indent(seen.get(For.hashCode).get().size() + 1), identityHashCode);
        return identityHashCode;
    }

    try {
        seen.get(For.hashCode).get().add(identityHashCode);
        return ifNotNullElse(forEachFieldWithMeta(For.hashCode, o.getClass(),
                new NFunctionNN<LastResult<Field, Integer>, Integer>() {
                    @Override
                    @SuppressWarnings("ParameterNameDiffersFromOverriddenParameter")
                    public Integer apply(@Nonnull final LastResult<Field, Integer> lastResult) {

                        Field field = lastResult.getCurrent();
                        Integer lastHashCode = lastResult.getLastResult();
                        if (lastHashCode == null)
                            lastHashCode = 0;

                        // Field's value
                        Object value = null;
                        try {
                            field.setAccessible(true);
                            value = field.get(o);
                        } catch (SecurityException | IllegalAccessException ignored) {
                        }

                        // Field's value's hashCode
                        int hashCode = System.identityHashCode(value);
                        if (value != null && isValueAccessible(value))
                            try {
                                if (value instanceof Iterable) {
                                    // Best-effort special handling for Iterables in case they don't implement hashCode themselves.
                                    // We just use the hashCode of the sorted hashCodes of the values.
                                    ImmutableSortedSet.Builder<Integer> hashCodes = ImmutableSortedSet
                                            .naturalOrder();
                                    //noinspection SynchronizationOnLocalVariableOrMethodParameter
                                    synchronized (value) {
                                        for (final Object o_ : (Iterable<?>) value)
                                            hashCodes.add(ObjectUtils.hashCode(o_));
                                    }
                                    hashCode = hashCodes.build().hashCode();
                                } else
                                    hashCode = value.hashCode();
                            } catch (final Throwable t) {
                                logger.dbg(t,
                                        "Couldn't load hashCode for: %s, value: %s.  Falling back to identity hashCode.",
                                        field, value);
                            }

                        // Increment the total hashCode with this field's value's hashCode
                        int newHashCode = HASHCODE_PRIME * lastHashCode + hashCode;
                        logger.trc("%s- %s=%d (hashCode -> %d)",
                                StringUtils.indent(seen.get(For.hashCode).get().size()), //
                                field.getName(), hashCode, newHashCode);

                        return newHashCode;
                    }
                }, null), new NNSupplier<Integer>() {
                    @Nonnull
                    @Override
                    public Integer get() {

                        // This object has no meta fields fit for hashCode usage.  Fall back to the object's own hashCode implementation.
                        return o.hashCode();
                    }
                });
    } finally {
        seen.get(For.hashCode).get().remove(identityHashCode);
    }
}

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

private void findRemovals() {
    ImmutableSortedSet.Builder<WorkerActor> builder = ImmutableSortedSet.naturalOrder();
    next_worker: for (WorkerActor a : Iterables.filter(actors, WorkerActor.class)) {
        if (!REMOVABLE_WORKERS.contains(a.worker().getClass()))
            continue;
        for (Storage s : a.outputs())
            if (!s.initialData().isEmpty())
                continue next_worker;
        for (Storage s : a.inputs())
            if (!s.initialData().isEmpty())
                continue next_worker;
        if (!REMOVAL_STRATEGY.remove(a, config))
            continue;
        builder.add(a);//from   www. jav  a 2s  . com
    }
    this.actorsToBeRemoved = builder.build();
}

From source file:com.facebook.buck.cli.Config.java

private static ImmutableSortedSet<Path> listFiles(Path root) throws IOException {
    if (!Files.isDirectory(root)) {
        return ImmutableSortedSet.of();
    }/*from   w  w w .  j a  v  a2 s.  c o  m*/

    ImmutableSortedSet.Builder<Path> toReturn = ImmutableSortedSet.naturalOrder();

    try (DirectoryStream<Path> directory = Files.newDirectoryStream(root)) {
        toReturn.addAll(directory.iterator());
    }

    return toReturn.build();
}