List of usage examples for java.util Comparator reversed
default Comparator<T> reversed()
From source file:Main.java
public static void main(String[] args) { Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 }; List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray)); Comparator<Integer> normal = Integer::compare; Comparator<Integer> reversed = normal.reversed(); Collections.sort(listOfIntegers, reversed); listOfIntegers.stream().forEach(e -> System.out.print(e + " ")); System.out.println(""); }
From source file:Main.java
public static void main(String[] args) { List<String> friends = Arrays.asList("CSS", "HTML", "Oracle", "Dart"); //same but reverse System.out.println("\nsort reverse:"); Comparator<String> comp = (aName, bName) -> aName.compareTo(bName); friends.stream().sorted(comp.reversed()).forEach(System.out::println); }
From source file:Main.java
public static void main(String... args) { // Comparators Comparator<Person> comparator = (p1, p2) -> p1.firstName.compareTo(p2.firstName); Person p1 = new Person("A", "Z"); Person p2 = new Person("B", "Z"); System.out.println(comparator.compare(p1, p2));// > 0 System.out.println(comparator.reversed().compare(p1, p2)); // < 0 }
From source file:Main.java
public static void main(String[] args) throws Exception { Comparator<Person> comparator = (p1, p2) -> p1.firstName.compareTo(p2.firstName); Person p1 = new Person("John", "Doe"); Person p2 = new Person("Alice", "Wonderland"); comparator.compare(p1, p2); // > 0 comparator.reversed().compare(p1, p2); // <0 }
From source file:ch.rasc.wampspring.demo.various.grid.PropertyComparatorFactory.java
public static <T> Comparator<T> createComparator(String propertyName, SortDirection sortDirection) { try {/* w w w . ja v a 2 s . c om*/ Comparator<T> comparator = new PropertyComparator<>(propertyName); if (sortDirection == SortDirection.DESC) { comparator = comparator.reversed(); } return comparator; } catch (ParseException e) { return null; } }
From source file:ch.rasc.edsutil.PropertyComparatorFactory.java
public static <T> Comparator<T> createComparator(String propertyName, SortDirection sortDirection, boolean ignoreCase) { try {// ww w . j a va 2s . c o m Comparator<T> comparator = new PropertyComparator<>(propertyName, ignoreCase); if (sortDirection == SortDirection.DESCENDING) { comparator = comparator.reversed(); } return comparator; } catch (ParseException e) { return null; } }
From source file:com.orange.clara.cloud.servicedbdumper.service.DbDumperServiceInstanceBindingService.java
private Map<String, Object> extractCredentials(List<DbDumperCredential> dbDumperCredentials) { SimpleDateFormat dateFormater = new SimpleDateFormat(this.dateFormat); Map<String, Object> credentials = Maps.newHashMap(); List<Map<String, Object>> dumpFiles = new ArrayList<>(); Map<String, Object> dumpFile; Comparator<DbDumperCredential> comparator = (d1, d2) -> d1.getCreatedAt().compareTo(d2.getCreatedAt()); dbDumperCredentials.sort(comparator.reversed()); for (DbDumperCredential dbDumperCredential : dbDumperCredentials) { dumpFile = Maps.newHashMap();/*from w w w . ja v a2 s .co m*/ dumpFile.put("download_url", dbDumperCredential.getDownloadUrl()); dumpFile.put("show_url", dbDumperCredential.getShowUrl()); dumpFile.put("filename", dbDumperCredential.getFilename()); dumpFile.put("created_at", dateFormater.format(dbDumperCredential.getCreatedAt())); dumpFile.put("dump_id", dbDumperCredential.getId()); dumpFile.put("size", dbDumperCredential.getSize()); dumpFile.put("deleted", dbDumperCredential.getDeleted()); dumpFile.put("tags", dbDumperCredential.getTags()); dumpFiles.add(dumpFile); } credentials.put("dumps", dumpFiles); return credentials; }
From source file:fi.helsinki.opintoni.service.StudyAttainmentService.java
public List<StudyAttainmentDto> getStudyAttainments(String studentNumber, int limit, Locale locale) { Comparator<StudyAttainmentDto> studyAttainmentDtoComparator = this::compareStudyAttainments; return oodiClient.getStudyAttainments(studentNumber).stream() .map(a -> studyAttainmentConverter.toDto(a, locale)).sorted(studyAttainmentDtoComparator.reversed()) .limit(limit).collect(Collectors.toList()); }
From source file:alluxio.cli.fs.command.LsCommand.java
private List<URIStatus> sortByFieldAndOrder(List<URIStatus> statuses, String sortField, boolean reverse) throws IOException { Optional<Comparator<URIStatus>> sortToUse = Optional.ofNullable(SORT_FIELD_COMPARATORS.get(sortField)); if (!sortToUse.isPresent()) { throw new InvalidArgumentException(ExceptionMessage.INVALID_ARGS_SORT_FIELD.getMessage(sortField)); }/* w w w.j a v a2 s.c o m*/ Comparator<URIStatus> sortBy = sortToUse.get(); if (reverse) { sortBy = sortBy.reversed(); } return statuses.stream().sorted(sortBy).collect(Collectors.toList()); }
From source file:fi.helsinki.opintoni.service.StudyAttainmentService.java
private List<StudyAttainmentDto> getWhitelistedAttainments(List<OodiStudyAttainment> studyAttainments, List<Long> whitelistedAttainmentIds, Locale locale) { Comparator<StudyAttainmentDto> studyAttainmentDtoComparator = this::compareStudyAttainments; return studyAttainments.stream().filter(a -> whitelistedAttainmentIds.contains(a.studyAttainmentId)) .map(a -> studyAttainmentConverter.toDto(a, locale)).sorted(studyAttainmentDtoComparator.reversed()) .collect(Collectors.toList()); }