List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
From source file:Main.java
public static void main(String args[]) { // create linked list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-2);/*from w w w . j a v a2 s . c o m*/ list.add(2); list.add(-12); list.add(8); // create comparator for reverse order Comparator cmp = Collections.reverseOrder(Collections.reverseOrder()); // sort the list Collections.sort(list, cmp); System.out.println(list); }
From source file:Main.java
/** * Construct a comparator that use the reverse order than the given comparator. * * @param comparator The comparator to reverse. * @param <T> The type of objects. * * @return A reverse comparator.//from w w w .jav a 2 s. c om */ public static <T> Comparator<T> reverseComparator(Comparator<T> comparator) { return Collections.reverseOrder(comparator); }
From source file:com.xebia.devradar.Timeline.java
public void update(Collection<Event> workspaceEvents) { List<Event> workspaceSortedEvents = new ArrayList<Event>(workspaceEvents); Collections.sort(workspaceSortedEvents, Collections.reverseOrder(new Comparator<Event>() { @Override//w ww . ja v a2 s.c om public int compare(Event o1, Event o2) { return new CompareToBuilder().append(o1.timestamp, o2.timestamp).toComparison(); } })); if (workspaceSortedEvents.size() < MAX_SIZE) { this.events = workspaceSortedEvents; } else { this.events = workspaceSortedEvents.subList(0, MAX_SIZE); } }
From source file:persistence.git.document.RevCommitRepository.java
Optional<RevCommit> getLastRevCommit(final Git git) throws SourceControlUnspecifiedException { Optional<RevCommit> lastCommit; try {/*from w ww .j ava 2s. c om*/ lastCommit = Lists.newArrayList(git.log().call()).stream().sorted(Collections.reverseOrder( (RevCommit u1, RevCommit u2) -> Integer.compare(u1.getCommitTime(), u2.getCommitTime()))) .findFirst(); } catch (GitAPIException e) { throw new SourceControlUnspecifiedException(e); } return lastCommit; }
From source file:org.lucidj.launcher.Launcher.java
private static String find_apache_karaf(String runtime_dir) { File[] file_array = new File(runtime_dir + "/Apache-Karaf").listFiles(); if (file_array == null) { return (null); }/* w w w . j a v a2s . com*/ // Not yet. Lets search inside runtime dir List<File> file_list = Arrays.asList(file_array); Collections.sort(file_list, Collections.reverseOrder(new AlphanumComparator())); for (File file : file_list) { if (file.isDirectory()) { // Embedded jdk_home return (file.getPath()); } } return (null); }
From source file:Person.java
public void order(boolean asc) { Comparator<Person> comp = asc ? new ComparePerson() : Collections.reverseOrder(new ComparePerson()); Collections.sort(this.listPersons, comp); }
From source file:org.openmrs.module.uiframeworkpatientsummarysupport.fragment.controller.PatientProblemsFragmentController.java
public void controller(FragmentModel model, @FragmentParam(value = "patientId") Patient patient) { //TODO should be able to use problem added and problem resolved GP //but for demo purposes we are using the active list service List<ActiveListItem> problems = Context.getActiveListService().getActiveListItems(patient, Problem.ACTIVE_LIST_TYPE); //sort the problems by date started descending Collections.sort(problems, Collections.reverseOrder(new ActiveListItemByStartDateComparator())); model.addAttribute("problems", problems); }
From source file:org.molasdin.wbase.collections.list.ExtendedListDecorator.java
@Override public void sort(Order order) { if (Order.ASC.equals(order)) { Collections.sort(decorated(), comparator); } else {//from ww w . j a va2 s. c om Collections.sort(decorated(), Collections.reverseOrder(comparator)); } }
From source file:org.sventon.model.DirEntrySorter.java
/** * Sorts given list./* ww w. ja va2s .c o m*/ * * @param entries Entries to sort. */ public void sort(final List<DirEntry> entries) { final Comparator<DirEntry> comparator; if (sortMode == SortMode.DESC) { comparator = Collections.reverseOrder(new DirEntryComparator(sortType, true)); } else { comparator = new DirEntryComparator(sortType, true); } Collections.sort(entries, comparator); }
From source file:org.sventon.util.RepositoryEntrySorter.java
/** * Sorts given list./*from w w w . j a v a 2 s . c o m*/ * * @param entries Entries to sort. */ public void sort(final List<RepositoryEntry> entries) { final Comparator<RepositoryEntry> comparator; if (sortMode == SortMode.DESC) { comparator = Collections.reverseOrder(new RepositoryEntryComparator(sortType, true)); } else { comparator = new RepositoryEntryComparator(sortType, true); } Collections.sort(entries, comparator); }