Example usage for java.util Comparator reverseOrder

List of usage examples for java.util Comparator reverseOrder

Introduction

In this page you can find the example usage for java.util Comparator reverseOrder.

Prototype

public static <T extends Comparable<? super T>> Comparator<T> reverseOrder() 

Source Link

Document

Returns a comparator that imposes the reverse of the natural ordering.

Usage

From source file:Main.java

public static void main(String[] args) {
    BinaryOperator<Integer> bi = BinaryOperator.maxBy(Comparator.reverseOrder());
    System.out.println(bi.apply(2, 3));
}

From source file:Main.java

public static void main(String[] args) {
    BinaryOperator<Integer> bi = BinaryOperator.minBy(Comparator.reverseOrder());
    System.out.println(bi.apply(2, 3));
}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList("1", "1", "2", "3", "4");

    stringList.stream().sorted(Comparator.reverseOrder()).forEach(System.out::println);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList("2", "1", "3", "4");

    Optional<String> m = stringList.stream().min(Comparator.reverseOrder());
    if (m.isPresent()) {
        System.out.println(m.get());
    } else {/*from   ww w  .  j av  a2 s.  co  m*/
        System.out.println("No Value");
    }

}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList("2", "1", "3", "4");

    Optional<String> m = stringList.stream().max(Comparator.reverseOrder());
    if (m.isPresent()) {
        System.out.println(m.get());
    } else {//from w ww. j  a  va 2  s  .c  o m
        System.out.println("No Value");
    }

}

From source file:Main.java

public static void main(String[] args) {
    Stream<String> s = Stream.of("1", "2", "3");

    Optional<String> o = s.collect(Collectors.maxBy(Comparator.reverseOrder()));

    if (o.isPresent()) {
        System.out.println(o.get());
    } else {// ww w.  j  av  a 2  s. c o  m
        System.out.println("no value");
    }

}

From source file:Main.java

public static void main(String[] args) {
    Stream<String> s = Stream.of("1", "2", "3");

    Optional<String> o = s.collect(Collectors.minBy(Comparator.reverseOrder()));

    if (o.isPresent()) {
        System.out.println(o.get());
    } else {//from w w  w .  j  a  va 2 s.  c  o m
        System.out.println("no value");
    }

}

From source file:org.mycore.imagetiler.MCRImageTest.java

private static boolean deleteDirectory(final Path path) {
    if (Files.exists(path)) {
        try {//from  w  w  w .ja v a 2 s.  co m
            Files.walk(path).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
        } catch (IOException e) {
            //ignore
        }
    }
    return !Files.exists(path);
}

From source file:com.example.message.GetMessageRequest.java

Flux<Message> filterPages(final Flux<Message> messages) {
    return messages.sort(Comparator.reverseOrder()).index().filter(tuple -> tuple.getT1() >= page * size)
            .take(size).map(Tuple2::getT2);
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.java

public Integer getLatestEnabledVersion() {
    List<Integer> versions = new ArrayList<>(instances.keySet());
    if (!versions.isEmpty()) {
        versions.sort(Integer::compareTo);
        versions.sort(Comparator.reverseOrder());
    }//from  ww  w  . j  av a  2s .  c o m

    return versions.stream().map(i -> new ImmutablePair<>(i, instances.get(i)))
            .filter(is -> is.getRight().stream().allMatch(i -> i.isHealthy() && i.isRunning())).findFirst()
            .orElse(new ImmutablePair<>(null, null)).getLeft();
}