How to check the right order of a list using Java 8 Lambda Expressions?
java-8, lambda
Solution
Based on Stuart Marks's suggestion, here's my final code
public void inAscOrder() {
verify("stringInASCOrder",
this::findMultiple,
elements -> IntStream.range(0, elements.size() - 1).allMatch(
i -> elements.get(i).getText()
.compareTo(elements.get(i + 1).getText()) <= 0));
}
Problem
I'm having the following method ``` private <T> void verify(String message, Supplier<T> targetSupplier, Predicate<T> predicate) { String verification = "verify that " + message; System.out.println(" -> " + verification); long start = System.currentTimeMillis(); while ((System.currentTimeMillis() - start) < timeoutInMs) { try { T target = targetSupplier.get(); if (predicate.test(target)) { return Verification.ok(); } result = Verification.ko(); } catch (NotFoundException e) { result = Verification.notFound(); } } } ``` and a ``` List<String> ABC ``` How can I check if ABC is in ascending/descending order using Java 8 lambda expressions? Many thank