List of usage examples for java.util Collections sort
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> void sort(List<T> list, Comparator<? super T> c)
From source file:Main.java
/** * Return the items of an Iterable as a sorted list. * * @param <T>/* ww w. j a v a 2s . co m*/ * The type of items in the Iterable. * @param items * The collection to be sorted. * @return A list containing the same items as the Iterable, but sorted. */ public static <T> List<T> sorted(Iterable<T> items, Comparator<T> comparator) { List<T> result = toList(items); Collections.sort(result, comparator); return result; }
From source file:Main.java
public static <E> List<E> sorted(Collection<E> col, Comparator<? super E> comparator) { final List<E> list = new ArrayList<>(col); Collections.sort(list, comparator); return list;/*from ww w . j a v a 2s. c o m*/ }
From source file:Main.java
/** * @return a sorted list where the string with the highest integer value comes first! *///ww w . j a va2s . c o m public static <T> List<Entry<T, Long>> sortLong(Collection<Entry<T, Long>> entrySet) { List<Entry<T, Long>> sorted = new ArrayList<Entry<T, Long>>(entrySet); Collections.sort(sorted, new Comparator<Entry<T, Long>>() { @Override public int compare(Entry<T, Long> o1, Entry<T, Long> o2) { long i1 = o1.getValue(); long i2 = o2.getValue(); if (i1 < i2) { return 1; } else if (i1 > i2) { return -1; } else { return 0; } } }); return sorted; }
From source file:Main.java
/** * @return a sorted list where the string with the highest integer value comes first! *//* www. j a v a 2 s . c o m*/ public static <T> List<Entry<T, Long>> sortLong(Collection<Entry<T, Long>> entrySet) { List<Entry<T, Long>> sorted = new ArrayList<Entry<T, Long>>(entrySet); Collections.sort(sorted, new Comparator<Entry<T, Long>>() { @Override public int compare(Entry<T, Long> o1, Entry<T, Long> o2) { long i1 = o1.getValue(); long i2 = o2.getValue(); if (i1 < i2) return 1; else if (i1 > i2) return -1; else return 0; } }); return sorted; }
From source file:com.senacor.wbs.web.core.util.SortUtils.java
@SuppressWarnings("unchecked") public static void sort(List beanCollection, final String sortAttribute, final boolean ascending, final Locale locale) { Comparator comparator = new LocaleAwareComparator(sortAttribute, ascending, locale); Collections.sort(beanCollection, comparator); }
From source file:Main.java
/** * Compare the list with the simple-name-comparator. * @param list/*from w ww. ja v a2 s. c o m*/ * the list argument. * @return * the sorted list. */ public static List<String> sortSimpleName(List<String> list) { if (list != null && list.size() > 0) { Collections.sort(list, SIMPLE_NAME_COMPARATOR); } return list; }
From source file:Main.java
/** * Creates a new list and sorts it with the comparator provided. * * @param <T>//w w w .j a v a2 s . com * @param values * @param comparator * @return */ public static <T> ArrayList<T> newSortedArrayList(Iterable<T> values, Comparator<T> comparator) { checkNotNull(values); checkNotNull(comparator); ArrayList<T> result = values instanceof Collection ? new ArrayList<T>(((Collection) values).size()) : new ArrayList<T>(); for (T value : values) { result.add(value); } Collections.sort(result, comparator); return result; }
From source file:io.pivotal.jira.JiraFixVersion.java
public static List<JiraFixVersion> sort(List<JiraFixVersion> versions) { List<JiraFixVersion> toSort = new ArrayList<>(versions); Collections.sort(toSort, new JiraFixVersionComparator()); return toSort; }
From source file:com.envision.envservice.common.util.UserUtil.java
public static void sortByName(List<UserBo> users) { Collections.sort(users, new Comparator<UserBo>() { @Override//from ww w . ja v a2 s .c o m public int compare(UserBo u1, UserBo u2) { if (StringUtils.isEmpty(u1.getName())) { return 1; } if (StringUtils.isEmpty(u2.getName())) { return -1; } String u1Name = u1.getName(); if (u1Name.contains(".")) { String[] names = u1Name.split("\\."); u1Name = names[1] + names[0]; } String u2Name = u2.getName(); if (u2Name.contains(".")) { String[] names = u2Name.split("\\."); u2Name = names[1] + names[0]; } return u1Name.compareTo(u2Name); } }); }
From source file:com.u2apple.tool.util.StaticMapFileUtils.java
private static void sortDevices(List<Device> devices) { Collections.sort(devices, (o1, o2) -> o1.getProductId().compareTo(o2.getProductId())); }