private static void sortByLastPushedDateAndName(List<Project> projects) { Collections.sort( projects, new Comparator<Project>() { @Override public int compare(Project p1, Project p2) { int compareLastPushedDate; if (p1.lastPushedDate == null && p2.lastPushedDate == null) { return p1.name.compareTo(p2.name); } if (p1.lastPushedDate == null) { return 1; } else if (p2.lastPushedDate == null) { return -1; } compareLastPushedDate = p2.lastPushedDate.compareTo(p1.lastPushedDate); if (compareLastPushedDate == 0) { return p1.name.compareTo(p2.name); } return compareLastPushedDate; } }); }
private static void sortDatum( List<Posting> postings, List<Issue> issues, List<PullRequest> pullRequests, List<Milestone> milestones) { Collections.sort( issues, new Comparator<Issue>() { @Override public int compare(Issue i1, Issue i2) { return i2.createdDate.compareTo(i1.createdDate); } }); Collections.sort( postings, new Comparator<Posting>() { @Override public int compare(Posting p1, Posting p2) { return p2.createdDate.compareTo(p1.createdDate); } }); Collections.sort( pullRequests, new Comparator<PullRequest>() { @Override public int compare(PullRequest p1, PullRequest p2) { return p2.created.compareTo(p1.created); } }); Collections.sort( milestones, new Comparator<Milestone>() { @Override public int compare(Milestone m1, Milestone m2) { return m2.title.compareTo(m1.title); } }); }
public static List sortByValue(Map map) { List list = new LinkedList(map.entrySet()); Collections.sort( list, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()) .compareTo(((Map.Entry) (o2)).getValue()); } }); Map result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); result.put(entry.getKey(), entry.getValue()); } Collections.reverse(list); return list; }