Example usage for com.google.common.collect Sets newTreeSet

List of usage examples for com.google.common.collect Sets newTreeSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newTreeSet.

Prototype

public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) 

Source Link

Document

Creates a mutable, empty TreeSet instance with the given comparator.

Usage

From source file:com.cloudera.science.ml.core.formula.Term.java

public Term(String... names) {
    this.names = Sets.newTreeSet(Arrays.asList(names));
    Preconditions.checkArgument(!this.names.isEmpty(), "Terms must have >= 1 named variables");
}

From source file:org.gradoop.flink.algorithms.fsm.pojos.Intersection.java

/**
 * Constructor./*  www .ja va2 s  .c  om*/
 *
 * @param first first integer set
 * @param second first integer set
 */
public Intersection(Set<Integer> first, Set<Integer> second) {
    this.ids = Sets.newTreeSet(first);
    this.ids.addAll(second);
}

From source file:com.cloudera.science.attribution.SessionsFn.java

@Override
public Pair<String, Pair<Boolean, Collection<String>>> map(
        Pair<String, Pair<Collection<Boolean>, Collection<String>>> in) {
    boolean hasEvent = !in.second().first().isEmpty();
    Collection<String> unique = Lists.newArrayList(Sets.newTreeSet(in.second().second()));
    return Pair.of(in.first(), Pair.of(hasEvent, unique));
}

From source file:de.rwhq.btree.Range.java

/**
 * merges the given Collection of Ranges by using the provided comparator.
 * /*w  w w  .  j  av a  2 s  . c  om*/
 * @param ranges
 * @param comparator
 * @param <K>
 * @return
 */
public static <K> TreeSet<Range<K>> merge(final Collection<Range<K>> ranges, final Comparator<K> comparator) {
    checkNotNull(ranges, "range list must not be null");
    checkNotNull(comparator, "comparator must not be null");

    TreeSet<Range<K>> tmpSet = Sets.newTreeSet(createRangeComparator(comparator));

    tmpSet.addAll(ranges);
    Range<K> last = null;

    Iterator<Range<K>> iterator = tmpSet.iterator();
    while (iterator.hasNext()) {
        Range<K> r = iterator.next();

        if (last == null) {
            last = r;
            continue;
        }

        // only if this to() is larger than last to(), extend to()
        if (last.getTo() != null) {
            if ((r.getFrom() == null || comparator.compare(last.getTo(), r.getFrom()) >= 0)) {
                if (r.getTo() == null)
                    last.setTo(null);
                else if (comparator.compare(last.getTo(), r.getTo()) < 0) {
                    last.setTo(r.getTo());
                }

                iterator.remove();
            } else { // separate ranges
                last = r;
            }
        } else {
            iterator.remove();
        }
    }

    return tmpSet;
}

From source file:com.metamx.druid.master.MergerWhitelist.java

@JsonCreator
public MergerWhitelist(Set<String> dataSources) {
    this.dataSources = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
    this.dataSources.addAll(dataSources);
}

From source file:org.apache.druid.server.coordinator.DatasourceWhitelist.java

@JsonCreator
public DatasourceWhitelist(Set<String> dataSources) {
    this.dataSources = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
    this.dataSources.addAll(dataSources);
}

From source file:com.netflix.exhibitor.core.config.RollingHostNamesBuilder.java

RollingHostNamesBuilder(InstanceConfig rootConfig, InstanceConfig rollingConfig, String leaderHostname) {
    ServerList rootServers = new ServerList(rootConfig.getString(StringConfigs.SERVERS_SPEC));
    ServerList rollingServers = new ServerList(rollingConfig.getString(StringConfigs.SERVERS_SPEC));

    Set<String> newServers = Sets.difference(Sets.newTreeSet(rollingServers.getHostnames()),
            Sets.newTreeSet(rootServers.getHostnames()));
    Set<String> unchangedServers = Sets.intersection(Sets.newTreeSet(rollingServers.getHostnames()),
            Sets.newTreeSet(rootServers.getHostnames()));

    ImmutableList.Builder<String> builder = ImmutableList.builder();
    builder.addAll(newServers); // new servers need to be started first as the others will try to communicate with them. You may have issues if there is more than 1 new server
    if ((leaderHostname != null) && unchangedServers.contains(leaderHostname)) {
        Set<String> allButLeader = Sets.difference(unchangedServers, Sets.newHashSet(leaderHostname));
        builder.addAll(allButLeader); // the servers that are staying in the cluster can be restarted next.
        builder.add(leaderHostname); // restart the leader last in the hopes of keeping quorum as long as possible
    } else {//  w w w.j  a  v a2  s  .com
        builder.addAll(unchangedServers); // the servers that are staying in the cluster can be restarted next.
    }
    rollingHostNames = builder.build(); // servers coming out of the cluster can be restarted all at once at the end (assuming they still exist)
}

From source file:de.tuberlin.uebb.jdae.llmsl.GlobalEquation.java

public BlockEquation bindIdentity() {
    return bind(BlockConstant.globalCtxt(Sets.newTreeSet(need())));
}

From source file:org.apache.beam.runners.dataflow.worker.ReaderRegistry.java

/**
 * A {@link ReaderRegistry} with each {@link ReaderFactory} known to the Dataflow worker already
 * registered./*from w w  w . j  a va2 s.c  o m*/
 *
 * <p>Uses {@link ServiceLoader} to dynamically bind well known types to reader factories via a
 * {@link ReaderFactory.Registrar}.
 */
public static ReaderRegistry defaultRegistry() {
    Set<ReaderFactory.Registrar> readerFactoryRegistrars = Sets
            .newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE);
    readerFactoryRegistrars.addAll(Lists
            .newArrayList(ServiceLoader.load(ReaderFactory.Registrar.class, ReflectHelpers.findClassLoader())));

    ImmutableMap.Builder<String, ReaderFactory> factories = ImmutableMap.builder();
    for (ReaderFactory.Registrar registrar : readerFactoryRegistrars) {
        factories.putAll(registrar.factories());
    }
    return new ReaderRegistry(factories.build());
}

From source file:ezbake.security.api.ua.Authorizations.java

public Authorizations(Authorizations other) {
    this.level = other.level;
    this.auths = Sets.newTreeSet(other.auths);
    this.communityAuthorizations = Sets.newTreeSet(other.communityAuthorizations);
    this.citizenship = other.citizenship;
    this.organization = other.organization;
}