java.util.Collections.reverseOrder()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(306)

本文整理了Java中java.util.Collections.reverseOrder()方法的一些代码示例,展示了Collections.reverseOrder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.reverseOrder()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:reverseOrder

Collections.reverseOrder介绍

[英]A comparator which reverses the natural order of the elements. The Comparator that's returned is Serializable.
[中]反转元素自然顺序的比较器。返回的比较器是可序列化的。

代码示例

代码示例来源:origin: google/guava

@Override
 public List<String> order(List<String> insertionOrder) {
  Collections.sort(insertionOrder, Collections.reverseOrder());
  return insertionOrder;
 }
}

代码示例来源:origin: stackoverflow.com

sort(T[] a, Comparator<? super T> c) 

Arrays.sort(a, Collections.reverseOrder());

代码示例来源:origin: robolectric/robolectric

@Nonnull
private <T> List<Class<? extends T>> prioritize(Iterable<Class<? extends T>> iterable) {
 List<Class<? extends T>> serviceClasses = new ArrayList<>();
 for (Class<? extends T> serviceClass : iterable) {
  serviceClasses.add(serviceClass);
 }
 Comparator<Class<? extends T>> c = reverseOrder(comparing(PluginFinder::priority));
 c = c.thenComparing(Class::getName);
 serviceClasses.sort(c);
 return serviceClasses;
}

代码示例来源:origin: stagemonitor/stagemonitor

private static List<ElasticsearchAvailabilityObserver> initElasticsearchAvailabilityObservers(ConfigurationRegistry configurationRegistry) {
  final List<ElasticsearchAvailabilityObserver> elasticsearchAvailabilityObservers = new ArrayList<ElasticsearchAvailabilityObserver>();
  ServiceLoader<ElasticsearchAvailabilityObserver> observers = ServiceLoader
      .load(ElasticsearchAvailabilityObserver.class, CorePlugin.class.getClassLoader());
  for (ElasticsearchAvailabilityObserver elasticsearchAvailabilityObserver : observers) {
    elasticsearchAvailabilityObservers.add(elasticsearchAvailabilityObserver);
    elasticsearchAvailabilityObserver.init(configurationRegistry);
  }
  
  Collections.sort(elasticsearchAvailabilityObservers, Collections.reverseOrder(new Comparator<ElasticsearchAvailabilityObserver>() {
    @Override
    public int compare(ElasticsearchAvailabilityObserver o1, ElasticsearchAvailabilityObserver o2) {
      return (o1.getPriority() < o2.getPriority()) ? -1 : ((o1.getPriority() == o2.getPriority()) ? 0 : 1);
    }
  }));
  return elasticsearchAvailabilityObservers;
}

代码示例来源:origin: org.apache.spark/spark-core_2.10

@Test
public void sortByKey() {
 List<Tuple2<Integer, Integer>> pairs = new ArrayList<>();
 pairs.add(new Tuple2<>(0, 4));
 pairs.add(new Tuple2<>(3, 2));
 pairs.add(new Tuple2<>(-1, 1));
 JavaPairRDD<Integer, Integer> rdd = sc.parallelizePairs(pairs);
 // Default comparator
 JavaPairRDD<Integer, Integer> sortedRDD = rdd.sortByKey();
 assertEquals(new Tuple2<>(-1, 1), sortedRDD.first());
 List<Tuple2<Integer, Integer>> sortedPairs = sortedRDD.collect();
 assertEquals(new Tuple2<>(0, 4), sortedPairs.get(1));
 assertEquals(new Tuple2<>(3, 2), sortedPairs.get(2));
 // Custom comparator
 sortedRDD = rdd.sortByKey(Collections.reverseOrder(), false);
 assertEquals(new Tuple2<>(-1, 1), sortedRDD.first());
 sortedPairs = sortedRDD.collect();
 assertEquals(new Tuple2<>(0, 4), sortedPairs.get(1));
 assertEquals(new Tuple2<>(3, 2), sortedPairs.get(2));
}

代码示例来源:origin: wildfly/wildfly

available.add(encoding);
Collections.sort(available, Collections.reverseOrder());
resultingMappings.addAll(available);

代码示例来源:origin: apache/mahout

@Test
public void testDepth() {
 List<Integer> totals = Lists.newArrayList();
 for (int i = 0; i < 1000; i++) {
  ChineseRestaurant x = new ChineseRestaurant(10);
  Multiset<Integer> counts = HashMultiset.create();
  for (int j = 0; j < 100; j++) {
   counts.add(x.sample());
  }
  List<Integer> tmp = Lists.newArrayList();
  for (Integer k : counts.elementSet()) {
   tmp.add(counts.count(k));
  }
  Collections.sort(tmp, Collections.reverseOrder());
  while (totals.size() < tmp.size()) {
   totals.add(0);
  }
  int j = 0;
  for (Integer k : tmp) {
   totals.set(j, totals.get(j) + k);
   j++;
  }
 }
 // these are empirically derived values, not principled ones
 assertEquals(25000.0, (double) totals.get(0), 1000);
 assertEquals(24000.0, (double) totals.get(1), 1000);
 assertEquals(8000.0, (double) totals.get(2), 200);
 assertEquals(1000.0, (double) totals.get(15), 50);
 assertEquals(1000.0, (double) totals.get(20), 40);
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testRulesRunOnNonOvershadowedSegmentsOnly()
         mockPeon
     ).collect(Collectors.toCollection(() -> new TreeSet<>(Collections.reverseOrder())))
 CoordinatorStats stats = afterParams.getCoordinatorStats();
 Assert.assertEquals(1, stats.getTiers("assignedCount").size());
 Assert.assertEquals(1, stats.getTieredStat("assignedCount", "_default_tier"));
 Assert.assertTrue(stats.getTiers("unassignedCount").isEmpty());
 Assert.assertTrue(stats.getTiers("unassignedSize").isEmpty());
 Assert.assertEquals(2, availableSegments.size());
 Assert.assertEquals(availableSegments, params.getAvailableSegments());
 Assert.assertEquals(availableSegments, afterParams.getAvailableSegments());

代码示例来源:origin: apache/hbase

@Test
public void testFloat32() {
 Float[] vals =
   assertEquals("Surprising return value.",
    5, OrderedBytes.encodeFloat32(buf1, vals[i], ord));
   assertEquals("Broken test: serialization did not consume entire buffer.",
    buf1.getLength(), buf1.getPosition());
   assertEquals("Surprising serialized length.", 5, buf1.getPosition() - 1);
   assertEquals("Buffer underflow.", 0, a[0]);
   assertEquals("Buffer underflow.", 0, a[1]);
  Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
  Float[] sortedVals = Arrays.copyOf(vals, vals.length);
  if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
  else Arrays.sort(sortedVals, Collections.reverseOrder());

代码示例来源:origin: apache/ignite

/**
   * Checks reverse order of exchangeFutures.
   *
   * @throws Exception If failed.
   */
  @Test
  public void testExchangeFutures() throws Exception {
    GridCachePartitionExchangeManager mgr = ((IgniteKernal)grid(0)).internalCache(DEFAULT_CACHE_NAME).context().shared().exchange();

    for (int i = 1; i <= 10; i++) {
      startGrid(i);

      List<GridDhtPartitionsExchangeFuture> futs = mgr.exchangeFutures();

      List<GridDhtPartitionsExchangeFuture> sortedFuts = new ArrayList<>(futs);

      Collections.sort(sortedFuts, Collections.reverseOrder());

      for (int j = 0; j < futs.size(); j++)
        assertEquals(futs.get(j), sortedFuts.get(j));
    }
  }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testRun()
     Stream.of(
       new ServerHolder(druidServer, mockPeon)
     ).collect(Collectors.toCollection(() -> new TreeSet<>(Collections.reverseOrder())))
   ));

代码示例来源:origin: apache/hbase

@Test
 public void testApplyDescending() {
  byte[][] vals = new byte[VALS.length][];
  byte[][] ordered = new byte[VALS.length][];
  for (int i = 0; i < VALS.length; i++) {
   vals[i] = Arrays.copyOf(VALS[i], VALS[i].length);
   ordered[i] = Arrays.copyOf(VALS[i], VALS[i].length);
   DESCENDING.apply(ordered[i]);
  }

  Arrays.sort(vals, Collections.reverseOrder(Bytes.BYTES_COMPARATOR));
  Arrays.sort(ordered, Bytes.BYTES_COMPARATOR);

  for (int i = 0; i < vals.length; i++) {
   DESCENDING.apply(ordered[i]);
   assertArrayEquals(vals[i], ordered[i]);
  }

  byte[] expected = new byte[] { VALS[0][0], DESCENDING.apply(VALS[0][1]), VALS[0][2] };
  byte[] rangeApply = Arrays.copyOf(VALS[0], VALS[0].length);
  DESCENDING.apply(rangeApply, 1, 1);
  assertArrayEquals(expected, rangeApply);
 }
}

代码示例来源:origin: apache/storm

Collections.sort(sortedKeys, Collections.reverseOrder());
        break;
      chunkList.add(it.next());
    ret.add(chunkList);

代码示例来源:origin: org.apache.spark/spark-core

@Test
public void sortByKey() {
 List<Tuple2<Integer, Integer>> pairs = new ArrayList<>();
 pairs.add(new Tuple2<>(0, 4));
 pairs.add(new Tuple2<>(3, 2));
 pairs.add(new Tuple2<>(-1, 1));
 JavaPairRDD<Integer, Integer> rdd = sc.parallelizePairs(pairs);
 // Default comparator
 JavaPairRDD<Integer, Integer> sortedRDD = rdd.sortByKey();
 assertEquals(new Tuple2<>(-1, 1), sortedRDD.first());
 List<Tuple2<Integer, Integer>> sortedPairs = sortedRDD.collect();
 assertEquals(new Tuple2<>(0, 4), sortedPairs.get(1));
 assertEquals(new Tuple2<>(3, 2), sortedPairs.get(2));
 // Custom comparator
 sortedRDD = rdd.sortByKey(Collections.reverseOrder(), false);
 assertEquals(new Tuple2<>(-1, 1), sortedRDD.first());
 sortedPairs = sortedRDD.collect();
 assertEquals(new Tuple2<>(0, 4), sortedPairs.get(1));
 assertEquals(new Tuple2<>(3, 2), sortedPairs.get(2));
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void shouldGeneratePowerLawDistribution() {
  GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
  try {
    new Neo4jGraphGenerator(database).generateGraph(getGeneratorConfiguration(100, 2));
    List<Integer> degrees = new LinkedList<>();
    try (Transaction tx = database.beginTx()) {
      for (Node node : database.getAllNodes()) {
        degrees.add(node.getDegree());
      }
      tx.success();
    }
    Collections.sort(degrees, Collections.reverseOrder());
    //todo make this an automated test
    //System.out.println(ArrayUtils.toString(degrees.toArray(new Integer[degrees.size()])));
  } finally {
    database.shutdown();
  }
}

代码示例来源:origin: MovingBlocks/Terasology

private static List<GameInfo> getSavedGameOrRecording(Path saveOrRecordingPath) {
  SortedMap<FileTime, Path> savedGamePaths = Maps.newTreeMap(Collections.reverseOrder());
  try (DirectoryStream<Path> stream = Files.newDirectoryStream(saveOrRecordingPath)) {
    for (Path entry : stream) {
        if (!info.getTitle().isEmpty()) {
          Date date = new Date(world.getKey().toMillis());
          result.add(new GameInfo(info, date, world.getValue()));

代码示例来源:origin: apache/incubator-druid

@Test
public void testRunTwoTiersWithExistingSegments()
         mockPeon
     ).collect(Collectors.toCollection(() -> new TreeSet<>(Collections.reverseOrder()))),
     "normal",
     Stream.of(
         mockPeon
     ).collect(Collectors.toCollection(() -> new TreeSet<>(Collections.reverseOrder())))
 CoordinatorStats stats = afterParams.getCoordinatorStats();
 Assert.assertEquals(12L, stats.getTieredStat("assignedCount", "hot"));
 Assert.assertEquals(0L, stats.getTieredStat("assignedCount", "normal"));
 Assert.assertTrue(stats.getTiers("unassignedCount").isEmpty());
 Assert.assertTrue(stats.getTiers("unassignedSize").isEmpty());

代码示例来源:origin: apache/hbase

@Test
public void testFloat64() {
 Double[] vals =
   assertEquals("Surprising return value.",
    9, OrderedBytes.encodeFloat64(buf1, vals[i], ord));
   assertEquals("Broken test: serialization did not consume entire buffer.",
    buf1.getLength(), buf1.getPosition());
   assertEquals("Surprising serialized length.", 9, buf1.getPosition() - 1);
   assertEquals("Buffer underflow.", 0, a[0]);
   assertEquals("Buffer underflow.", 0, a[1]);
  Arrays.sort(encoded, Bytes.BYTES_COMPARATOR);
  Double[] sortedVals = Arrays.copyOf(vals, vals.length);
  if (ord == Order.ASCENDING) Arrays.sort(sortedVals);
  else Arrays.sort(sortedVals, Collections.reverseOrder());

代码示例来源:origin: google/guava

@Override
 public List<String> order(List<String> insertionOrder) {
  Collections.sort(insertionOrder, Collections.reverseOrder());
  return insertionOrder;
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testRunRuleDoesNotExist()
         mockPeon
     ).collect(Collectors.toCollection(() -> new TreeSet<>(Collections.reverseOrder())))

相关文章

Collections类方法