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:io.druid.server.http.InventoryViewUtils.java

public static Set<DruidDataSource> getDataSources(InventoryView serverInventoryView) {
    TreeSet<DruidDataSource> dataSources = Sets.newTreeSet(new Comparator<DruidDataSource>() {
        @Override/*from ww  w  .  j  ava 2  s. c om*/
        public int compare(DruidDataSource druidDataSource, DruidDataSource druidDataSource1) {
            return druidDataSource.getName().compareTo(druidDataSource1.getName());
        }
    });
    dataSources
            .addAll(Lists.newArrayList(Iterables.concat(Iterables.transform(serverInventoryView.getInventory(),
                    new Function<DruidServer, Iterable<DruidDataSource>>() {
                        @Override
                        public Iterable<DruidDataSource> apply(DruidServer input) {
                            return input.getDataSources();
                        }
                    }))));
    return dataSources;
}

From source file:org.gradle.internal.component.IncompatibleConfigurationSelectionException.java

private static String generateMessage(AttributeContainer fromConfigurationAttributes,
        AttributesSchema consumerSchema, ComponentResolveMetadata targetComponent, String targetConfiguration) {
    Set<String> requestedAttributes = Sets
            .newTreeSet(Iterables.transform(fromConfigurationAttributes.keySet(), ATTRIBUTE_NAME));
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Configuration '" + targetConfiguration + "' in "
            + targetComponent.getComponentId().getDisplayName() + " does not match the consumer attributes");
    formatConfiguration(formatter, fromConfigurationAttributes, consumerSchema,
            Collections.singletonList(targetComponent.getConfiguration(targetConfiguration)),
            requestedAttributes, targetConfiguration);
    return formatter.toString();
}

From source file:edu.harvard.med.iccbl.screensaver.policy.DataSharingLevelMapper.java

public static ScreensaverUserRole getPrimaryDataSharingLevelRoleForUser(ScreenType screenType,
        ScreensaverUser user) {/*from   w  ww .  j  a  v  a2  s.  co m*/
    TreeSet<ScreensaverUserRole> userDslRoles = Sets
            .newTreeSet(Sets.intersection(user.getScreensaverUserRoles(), UserDslRoles.get(screenType)));
    if (!userDslRoles.isEmpty()) {
        return userDslRoles.last();
    }
    return null;
}

From source file:cc.kave.episodes.mining.evaluation.ProposalHelper.java

public static TreeSet<Tuple<Episode, Double>> createEpisodesSortedSet() {
    final TreeSet<Tuple<Episode, Double>> res = Sets.newTreeSet(new Comparator<Tuple<Episode, Double>>() {
        @Override/*from ww  w  .  j av a 2s . co m*/
        public int compare(final Tuple<Episode, Double> o1, final Tuple<Episode, Double> o2) {
            int valueOrdering = Double.compare(o2.getSecond(), o1.getSecond());
            boolean areValuesEqual = valueOrdering == 0;
            if (areValuesEqual) {
                int frequencyOrdering = Integer.compare(o2.getFirst().getFrequency(),
                        o1.getFirst().getFrequency());
                boolean areFrequenciesEqual = frequencyOrdering == 0;
                if (areFrequenciesEqual) {
                    int numberOfEventsOrdering = Integer.compare(o2.getFirst().getNumEvents(),
                            o1.getFirst().getNumEvents());
                    boolean areNumberOfEventsEqual = numberOfEventsOrdering == 0;
                    if (areNumberOfEventsEqual) {
                        int eventsOrdering = o1.getFirst().getFacts().toString()
                                .compareTo(o2.getFirst().getFacts().toString());
                        return eventsOrdering;
                    } else {
                        return numberOfEventsOrdering;
                    }
                } else {
                    return frequencyOrdering;
                }
            } else {
                return valueOrdering;
            }
        }
    });
    return res;
}

From source file:ezbake.groups.service.caching.SetChecksumProvider.java

@Override
public Long getChecksum(Set<Long> data) {
    SortedSet<Long> sortedSet = Sets.newTreeSet(data);

    Long checksum = 0l;//w  w  w.ja  v  a2 s .  c  o  m
    for (Long l : sortedSet) {
        checksum ^= l;
    }

    return checksum;
}

From source file:biz.ganttproject.impex.msproject2.CustomPropertyMapping.java

static Map<CustomPropertyDefinition, FieldType> buildMapping(TaskManager taskManager) throws MPXJException {
    final SortedSet<TaskField> taskFields = Sets.newTreeSet(new Comparator<TaskField>() {
        @Override//from w  ww.  j av  a2 s .com
        public int compare(TaskField o1, TaskField o2) {
            return o1.ordinal() - o2.ordinal();
        }
    });
    taskFields.addAll(Arrays.asList(TaskField.values()));
    return buildMapping(taskManager.getCustomPropertyManager(), taskFields, TaskField.class);
}

From source file:org.eclipse.mylyn.internal.gerrit.ui.operations.BranchProposalProvider.java

public BranchProposalProvider(SortedSet<String> proposals) {
    this.proposals = Sets.newTreeSet(proposals);
}

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

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

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

From source file:org.apache.beam.runners.flink.translation.utils.FlinkPipelineTranslatorUtils.java

/** Creates a mapping from PCollection id to output tag integer. */
public static BiMap<String, Integer> createOutputMap(Iterable<String> localOutputs) {
    ImmutableBiMap.Builder<String, Integer> builder = ImmutableBiMap.builder();
    int outputIndex = 0;
    // sort localOutputs for stable indexing
    for (String tag : Sets.newTreeSet(localOutputs)) {
        builder.put(tag, outputIndex);//from  w w w .  ja v a  2 s .  com
        outputIndex++;
    }
    return builder.build();
}

From source file:voldemort.versioning.VectorClockUtils.java

/**
 * Compare two VectorClocks, the outcomes will be one of the following: <br>
 * -- Clock 1 is BEFORE clock 2, if there exists an nodeId such that
 * c1(nodeId) <= c2(nodeId) and there does not exist another nodeId such
 * that c1(nodeId) > c2(nodeId). <br>
 * -- Clock 1 is CONCURRENT to clock 2 if there exists an nodeId, nodeId2
 * such that c1(nodeId) < c2(nodeId) and c1(nodeId2) > c2(nodeId2)<br>
 * -- Clock 1 is AFTER clock 2 otherwise
 * /*from  w  w  w. j av  a2s.  c  o  m*/
 * @param v1 The first VectorClock
 * @param v2 The second VectorClock
 */
public static Occurred compare(VectorClock v1, VectorClock v2) {
    if (v1 == null || v2 == null)
        throw new IllegalArgumentException("Can't compare null vector clocks!");
    // We do two checks: v1 <= v2 and v2 <= v1 if both are true then
    boolean v1Bigger = false;
    boolean v2Bigger = false;

    SortedSet<Short> v1Nodes = v1.getVersionMap().navigableKeySet();
    SortedSet<Short> v2Nodes = v2.getVersionMap().navigableKeySet();
    // get clocks(nodeIds) that both v1 and v2 has
    SortedSet<Short> commonNodes = Sets.newTreeSet(v1Nodes);
    commonNodes.retainAll(v2Nodes);
    // if v1 has more nodes than common nodes
    // v1 has clocks that v2 does not
    if (v1Nodes.size() > commonNodes.size()) {
        v1Bigger = true;
    }
    // if v2 has more nodes than common nodes
    // v2 has clocks that v1 does not
    if (v2Nodes.size() > commonNodes.size()) {
        v2Bigger = true;
    }
    // compare the common parts
    for (Short nodeId : commonNodes) {
        // no need to compare more
        if (v1Bigger && v2Bigger) {
            break;
        }
        long v1Version = v1.getVersionMap().get(nodeId);
        long v2Version = v2.getVersionMap().get(nodeId);
        if (v1Version > v2Version) {
            v1Bigger = true;
        } else if (v1Version < v2Version) {
            v2Bigger = true;
        }
    }

    /*
     * This is the case where they are equal. Consciously return BEFORE, so
     * that the we would throw back an ObsoleteVersionException for online
     * writes with the same clock.
     */
    if (!v1Bigger && !v2Bigger)
        return Occurred.BEFORE;
    /* This is the case where v1 is a successor clock to v2 */
    else if (v1Bigger && !v2Bigger)
        return Occurred.AFTER;
    /* This is the case where v2 is a successor clock to v1 */
    else if (!v1Bigger && v2Bigger)
        return Occurred.BEFORE;
    /* This is the case where both clocks are parallel to one another */
    else
        return Occurred.CONCURRENTLY;
}