Java Code Examples for java.util.Comparator.reverseOrder()

The following are Jave code examples for showing how to use reverseOrder() of the java.util.Comparator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cruise-control   File: MetricSampleAggregator.java   View Source Code Vote up 6 votes
/**
 * Construct the metric sample aggregator.
 *
 * @param config   The load monitor configurations.
 * @param metadata The metadata of the cluster.
 */
public MetricSampleAggregator(KafkaCruiseControlConfig config,
                              Metadata metadata,
                              MetricCompletenessChecker metricCompletenessChecker) {
  _windowedAggregatedPartitionMetrics = new ConcurrentSkipListMap<>(Comparator.reverseOrder());
  // We keep twice as many the snapshot windows.
  _numSnapshots = config.getInt(KafkaCruiseControlConfig.NUM_LOAD_SNAPSHOTS_CONFIG);
  _numSnapshotsToKeep = _numSnapshots * 2;
  _snapshotWindowMs = config.getLong(KafkaCruiseControlConfig.LOAD_SNAPSHOT_WINDOW_MS_CONFIG);
  _minSamplesPerSnapshot = config.getInt(KafkaCruiseControlConfig.MIN_SAMPLES_PER_LOAD_SNAPSHOT_CONFIG);
  _activeSnapshotWindow = -1L;
  _snapshotCollectionInProgress = new AtomicInteger(0);
  _metadata = metadata;
  _metricCompletenessChecker = metricCompletenessChecker;
  _cachedAggregationResult = null;
  _cachedAggregationResultWindow = -1L;
  _aggregationResultGeneration = new AtomicLong(0);
  _latestBrokerMetrics = new ConcurrentHashMap<>();
  _identityPartitionMap = new ConcurrentHashMap<>();
}
 
Example 2
Project: Apriori   File: Apriori.java   View Source Code Vote up 6 votes
/**
 * Executes the Apriori algorithm on a specific set of transactions in order to learn
 * association rules, which specify frequent item sets.
 *
 * @param iterable An iterable, which allows to iterate the transactions, as an instance of the
 *                 type {@link Iterable}. The iterable may not be null
 * @return The rule set, which contains the association rules, which have been learned by the
 * algorithm, as an instance of the class {@link RuleSet} or an empty rule set, if no
 * association rules have been learned
 */
@NotNull
public final Output<ItemType> execute(@NotNull final Iterable<Transaction<ItemType>> iterable) {
    ensureNotNull(iterable, "The iterable may not be null");
    LOGGER.info("Starting Apriori algorithm");
    long startTime = System.currentTimeMillis();
    Map<Integer, TransactionalItemSet<ItemType>> frequentItemSets = frequentItemSetMinerTask
            .findFrequentItemSets(iterable);
    RuleSet<ItemType> ruleSet = null;

    if (configuration.isGeneratingRules()) {
        ruleSet = associationRuleGeneratorTask.generateAssociationRules(frequentItemSets);
    }

    FrequentItemSets<ItemType> sortedItemSets = new FrequentItemSets<>(
            Comparator.reverseOrder());
    frequentItemSets.values().forEach(x -> sortedItemSets.add(new ItemSet<>(x)));
    long endTime = System.currentTimeMillis();
    Output<ItemType> output = new Output<>(configuration, startTime, endTime, sortedItemSets,
            ruleSet);
    LOGGER.info("Apriori algorithm terminated after {} milliseconds", output.getRuntime());
    return output;
}
 
Example 3
Project: Apriori   File: FrequentItemSetsTest.java   View Source Code Vote up 6 votes
/**
 * Tests, if all class members are set correctly by the constructor.
 */
@Test
public final void testConstructor() {
    SortedSet<ItemSet<NamedItem>> frequentItemSets = new FrequentItemSets<>(
            Comparator.reverseOrder());
    ItemSet<NamedItem> itemSet1 = new ItemSet<>();
    itemSet1.add(new NamedItem("a"));
    itemSet1.setSupport(0.5);
    ItemSet<NamedItem> itemSet2 = new ItemSet<>();
    itemSet2.add(new NamedItem("b"));
    itemSet2.setSupport(0.6);
    frequentItemSets.add(itemSet1);
    frequentItemSets.add(itemSet2);
    assertEquals(2, frequentItemSets.size());
    assertEquals(itemSet2, frequentItemSets.first());
    assertEquals(itemSet1, frequentItemSets.last());
}
 
Example 4
Project: Apriori   File: FrequentItemSetsTest.java   View Source Code Vote up 6 votes
/**
 * Tests the functionality of the clone-method.
 */
@Test
public final void testClone() {
    FrequentItemSets<NamedItem> frequentItemSets1 = new FrequentItemSets<>(
            Comparator.reverseOrder());
    ItemSet<NamedItem> itemSet1 = new ItemSet<>();
    itemSet1.add(new NamedItem("a"));
    itemSet1.setSupport(0.5);
    ItemSet<NamedItem> itemSet2 = new ItemSet<>();
    itemSet2.add(new NamedItem("b"));
    itemSet2.setSupport(0.6);
    frequentItemSets1.add(itemSet1);
    frequentItemSets1.add(itemSet2);
    FrequentItemSets<NamedItem> frequentItemSets2 = frequentItemSets1.clone();
    assertEquals(frequentItemSets1.size(), frequentItemSets2.size());
    assertEquals(frequentItemSets1.first(), frequentItemSets2.first());
    assertEquals(frequentItemSets1.last(), frequentItemSets2.last());
}
 
Example 5
Project: Apriori   File: FrequentItemSetsTest.java   View Source Code Vote up 6 votes
/**
 * Tests the functionality of the method, which allows to create a string, which contains
 * information about frequent item sets.
 */
@Test
public final void testFormatFrequentItemSets() {
    NamedItem item1 = new NamedItem("a");
    NamedItem item2 = new NamedItem("b");
    double support1 = 0.3;
    double support2 = 0.7;
    ItemSet<NamedItem> itemSet1 = new ItemSet<>();
    itemSet1.add(item1);
    itemSet1.setSupport(support1);
    ItemSet<NamedItem> itemSet2 = new ItemSet<>();
    itemSet2.add(item2);
    itemSet2.setSupport(support2);
    FrequentItemSets<NamedItem> frequentItemSets = new FrequentItemSets<>(
            Comparator.reverseOrder());
    frequentItemSets.add(itemSet1);
    frequentItemSets.add(itemSet2);
    assertEquals(
            "[" + itemSet2 + " (support = " + support2 + "),\n" + itemSet1 + " (support = " +
                    support1 + ")]",
            FrequentItemSets.formatFrequentItemSets(frequentItemSets));
}
 
Example 6
Project: Apriori   File: FrequentItemSetsTest.java   View Source Code Vote up 5 votes
/**
 * Tests the functionality of the method, which allows to create a string, which contains
 * information about frequent item sets, if the no frequent item sets are available.
 */
@Test
public final void testFormatFrequentItemSetsIfEmpty() {
    FrequentItemSets<NamedItem> frequentItemSets = new FrequentItemSets<>(
            Comparator.reverseOrder());
    assertEquals("[]", FrequentItemSets.formatFrequentItemSets(frequentItemSets));
}
 
Example 7
Project: EEWBot   File: QuakeInfo.java   View Source Code Vote up 5 votes
@Override
public EmbedObject buildEmbed() {
	final EmbedBuilder builder = new EmbedBuilder();
	if (getEpicenter().equals("---")&&getDepth().equals("---")) {
		builder.withTitle("地震速報");
		final Map<SeismicIntensity, List<String>> map = new TreeMap<>(Comparator.reverseOrder());
		getDetails().forEach(detail -> detail.getCities().entrySet().forEach(city -> {
			List<String> list = map.get(city.getKey());
			if (list==null)
				map.put(city.getKey(), list = new ArrayList<>());
			list.addAll(city.getValue());
		}));
		map.entrySet().forEach(entry -> builder.appendField(entry.getKey().toString(), String.join("  ", entry.getValue()), false));
	} else {
		builder.withTitle("地震情報");
		builder.appendField("震央", getEpicenter(), true);
		if (!getDepth().equals("---"))
			builder.appendField("深さ", getDepth(), true);
		if (getMagnitude()>0f)
			builder.appendField("マグニチュード", String.valueOf(getMagnitude()), true);
		getMaxIntensity().ifPresent(intensity -> builder.appendField("最大震度", intensity.getSimple(), false));
	}
	builder.appendField("情報", getInfo(), true);

	getMaxIntensity().ifPresent(intensity -> builder.withColor(intensity.getColor()));
	builder.withTimestamp(getAnnounceTime().getTime());
	getImageUrl().ifPresent(url -> builder.withImage(url));

	builder.withFooterText("地震情報 - Yahoo!天気・災害");
	builder.withUrl(getUrl());
	return builder.build();
}
 
Example 8
Project: jdk8u-jdk   File: BasicTest.java   View Source Code Vote up 5 votes
public void testReverseComparator() {
    Comparator<String> cmpr = Comparator.reverseOrder();
    Comparator<String> cmp = cmpr.reversed();

    assertEquals(cmp.reversed(), cmpr);
    assertEquals(0, cmp.compare("a", "a"));
    assertEquals(0, cmpr.compare("a", "a"));
    assertTrue(cmp.compare("a", "b") < 0);
    assertTrue(cmpr.compare("a", "b") > 0);
    assertTrue(cmp.compare("b", "a") > 0);
    assertTrue(cmpr.compare("b", "a") < 0);
}
 
Example 9
Project: SoftUni   File: DisplayCommand.java   View Source Code Vote up 5 votes
private Comparator<Course> createCourseComparator (String sortType) {
    if(sortType.equalsIgnoreCase("descending")) {
        return Comparator.reverseOrder();
    } else if (sortType.equalsIgnoreCase("ascending")) {
        return Comparator.naturalOrder();
    } else {
        throw  new InvalidInputException(this.getInput());
    }
}
 
Example 10
Project: openjdk-jdk10   File: BasicTest.java   View Source Code Vote up 5 votes
public void testReverseComparator() {
    Comparator<String> cmpr = Comparator.reverseOrder();
    Comparator<String> cmp = cmpr.reversed();

    assertEquals(cmp.reversed(), cmpr);
    assertEquals(0, cmp.compare("a", "a"));
    assertEquals(0, cmpr.compare("a", "a"));
    assertTrue(cmp.compare("a", "b") < 0);
    assertTrue(cmpr.compare("a", "b") > 0);
    assertTrue(cmp.compare("b", "a") > 0);
    assertTrue(cmpr.compare("b", "a") < 0);
}
 
Example 11
Project: cruise-control   File: MetricCompletenessChecker.java   View Source Code Vote up 4 votes
public MetricCompletenessChecker(int maxNumSnapshots) {
  _validPartitionsPerTopicByWindows = new ConcurrentSkipListMap<>(Comparator.reverseOrder());
  _validPartitionsByWindows = new TreeMap<>(Comparator.reverseOrder());
  _modelGeneration = null;
  _maxNumSnapshots = maxNumSnapshots;
}
 
Example 12
Project: iextrading4j-book   File: IEXOrderBook.java   View Source Code Vote up 4 votes
public IEXOrderBook(final String symbol) {
    this.symbol = symbol;
    this.bidOffers = new TreeMap<>(Comparator.reverseOrder());
    this.askOffers = new TreeMap<>();
}