List of usage examples for java.util Collections sort
@SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> void sort(List<T> list)
From source file:Main.java
public static <T extends Comparable<? super T>> void sort(List<T> list) { Collections.sort(list); }
From source file:Main.java
public static String[] range(String in) { // basic form: x1, x2, x3, x4 // range form: x1-5, n3-7 List<String> rs = new ArrayList<String>(); for (String s : Splitter.on(",").trimResults().omitEmptyStrings().split(in)) { s = s.trim();/*from ww w . j ava2 s .c o m*/ if (range0(rs, s)) continue; rs.add(s); } Collections.sort(rs); return Iterables.toArray(rs, String.class); }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> List<T> sort(List<T> list) { if (list != null && list.size() > 0) { Collections.sort((List) list); }/*from w w w .ja va2 s .c o m*/ return list; }
From source file:Main.java
public static <T extends Comparable<? super T>> void sort(List<T> list) { List<T> sortableList = new ArrayList<>(list); Collections.sort(sortableList); list.clear();/*from w w w. j a v a2 s. c o m*/ list.addAll(sortableList); }
From source file:Main.java
public static ArrayList<String> getCountriesArray1() { Locale[] locales = Locale.getAvailableLocales(); ArrayList<String> countries = new ArrayList<String>(); for (Locale locale : locales) { String country = locale.getDisplayCountry(); Currency currency = Currency.getInstance(locale); if (country.trim().length() > 0 && !countries.contains(country) && !country.trim().equals("World")) { countries.add(country + " (" + currency + ")"); }//from w w w . java 2 s. c o m } Collections.sort(countries); setCountriesISOMap(); return countries; }
From source file:Main.java
/** * //from w w w .j a v a2 s. c o m * @param <T> * @param list * @return */ public static <T extends Comparable<T>> T getLowerMiddleValue(List<T> list) { if (null == list || list.isEmpty()) return null; Collections.sort(list); return list.get((list.size() - 1) / 2); }
From source file:Main.java
/** * Get package names of all installed apps. * @param with_system Mark if system apps are included or not. *//*from w w w.ja v a 2 s .c o m*/ public static String[] getAllInstalledPackageNames(Context context, boolean with_system) { List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(0); if (packages == null) { return null; } List<String> result = new ArrayList<>(); for (ApplicationInfo applicationInfo : packages) { //Skip over system apps. if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !with_system) { continue; } result.add(applicationInfo.packageName); } Collections.sort(result); return result.toArray(new String[result.size()]); }
From source file:Main.java
public static <T extends Comparable<? super T>> void sort(final List<T> list) { Collections.sort(list); }
From source file:Main.java
public static <T extends Comparable<? super T>> List<List<T>> getAllCombinations(final List<T> pList, final int pSize) { assert (pSize < pList.size()); final List<List<T>> result = new ArrayList<List<T>>(); if (pSize == 0) { result.add(new ArrayList<T>()); return result; }// w w w . j a v a 2 s . c om final List<List<T>> combinations = getAllCombinations(pList, pSize - 1); for (final List<T> combination : combinations) { for (final T element : pList) { if (combination.contains(element)) { continue; } final List<T> list = new ArrayList<T>(); list.addAll(combination); if (list.contains(element)) { continue; } list.add(element); Collections.sort(list); if (result.contains(list)) { continue; } result.add(list); } } return result; }
From source file:Main.java
public static double getQuantile(Collection<Double> l, double alpha) { List<Double> sorted = new ArrayList<Double>(l); Collections.sort(sorted); int size = sorted.size(); if (size == 0) return Double.NaN; double kDouble = (size - 1) * alpha; int k = (int) Math.floor(kDouble); double g = kDouble - k; double lowerValue = sorted.get(k); if (sorted.size() <= k + 1) return lowerValue; double upperValue = sorted.get(k + 1); return (1 - g) * lowerValue + g * upperValue; }