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 <K extends Comparable<? super K>> List<K> sorted(Collection<K> collection) { List<K> requiredTicketIds = new ArrayList<>(collection); Collections.sort(requiredTicketIds); return requiredTicketIds; }
From source file:Main.java
public static List<String> getSharedPreferenceTags(Context context) { ArrayList<String> tags = new ArrayList<String>(); String rootPath = context.getApplicationInfo().dataDir + "/shared_prefs"; File root = new File(rootPath); if (root.exists()) { for (File file : root.listFiles()) { String fileName = file.getName(); if (fileName.endsWith(PREFS_SUFFIX)) { tags.add(fileName.substring(0, fileName.length() - PREFS_SUFFIX.length())); }//from w ww . j a va 2s .c o m } } Collections.sort(tags); return tags; }
From source file:Main.java
/** * Build a List from the entry set of a map. * /*from w w w.j a v a 2 s . c o m*/ * <p> * NOTE: This should not be necessary but there are bugs * when you iterate using map.entrySet().iterator(). * </p> * * @param map the map to use as the source * @param sortedByValue whether or not to sort the values * of the created list * @return a list containing all values of the given * map */ public static List mapToEntryList(Map map, boolean sortedByValue) { List retList = new ArrayList(); if (map.isEmpty()) { return Collections.EMPTY_LIST; } Iterator it = map.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); Object obj = map.get(key); retList.add(obj); } // Sort if (sortedByValue) Collections.sort(retList); return retList; }
From source file:Main.java
private static List<String> filterAndSortedParamNames(Map<String, Object> paramValueMap, List<String> ignoreParamNameList) { List<String> filteredParamNames = filterParamNames(paramValueMap, ignoreParamNameList); Collections.sort(filteredParamNames); return filteredParamNames; }
From source file:Main.java
/** * This API is to get the lowest value from a List. The input objects need * to implement Comparable.//ww w.ja v a2s. c o m * * * @param <T> * The type of the object the input list can contain and also the * return type of the method * @param list * @return * @author sabuj.das */ public static <T extends Comparable<T>> T lowestValue(List<T> list) { if (list == null || list.isEmpty()) { return null; } Collections.sort(list); return list.get(0); }
From source file:edu.washington.gs.skyline.model.quantification.PValues.java
public static double[] adjustPValues(double[] pValues) { List<Pair<Double, Integer>> entries = new ArrayList<>(); DoubleStream.of(pValues).forEach(value -> entries.add(Pair.of(value, entries.size()))); Collections.sort(entries); double currentMin = 1.0; double[] result = new double[entries.size()]; for (int i = entries.size() - 1; i >= 0; i--) { double value = entries.get(i).getLeft() * entries.size() / (i + 1); currentMin = Math.min(value, currentMin); result[entries.get(i).getRight()] = currentMin; }// ww w.j a v a 2 s . c o m return result; }
From source file:com.canoo.webtest.plugins.pdftest.PdfToFontsFilter.java
static String fontsToString(final List _fonts) { final List strings = new ArrayList(); for (int i = 0; i < _fonts.size(); i++) { final PDFFont font = (PDFFont) _fonts.get(i); strings.add(font.getPage() + "|" + font.getType() + "|" + font.getName()); }/*from w w w . j av a2s. c o m*/ Collections.sort(strings); final String lineSep = System.getProperty("line.separator"); return StringUtils.join(strings, lineSep); }
From source file:gt.org.ms.api.requesting.ValidationsHelper.java
public static <T> T findBestMatchItem(final String param, List<T> options) { List<MatchItem> weights = new ArrayList<MatchItem>( Collections2.transform(options, new Function<T, MatchItem>() { @Override/*from ww w.ja v a 2s . com*/ public MatchItem apply(T f) { return new MatchItem( StringUtils.getLevenshteinDistance(param.toLowerCase(), f.toString().toLowerCase()), f); } })); Collections.sort(weights); //fot those objects without tostring implementation it will be wrong so better return null return (T) weights.get(0).value; }
From source file:Main.java
/** * Returns a sorted copy of the provided collection of things. Uses the natural ordering of the things. *//*from w ww .j a va 2 s . c om*/ public static <T extends Comparable> List<T> sort(Iterable<T> things) { List<T> copy = toMutableList(things); Collections.sort(copy); return copy; }
From source file:Main.java
public static <E extends Comparable<E>> List<E> sorted(Collection<E> col) { ArrayList<E> list = new ArrayList<E>(col); Collections.sort(list); return list;/*from www . j a v a2 s . c om*/ }