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:info.mikaelsvensson.devtools.analysis.db2eventlog.Db2EventLogReportGenerator.java
private static void sortQueryDataBySamples(List<QueryStatistics> data) { Collections.sort(data, QueryStatistics.CALL_COUNT_COMPARATOR); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java
/** * Sorts map by value (http://stackoverflow.com/a/2581754) * * @param map map//from ww w. java2s . com * @param <K> key * @param <V> value * @return sorted map by value */ public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map, final boolean asc) { List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { if (asc) { return (o1.getValue()).compareTo(o2.getValue()); } else { return (o2.getValue()).compareTo(o1.getValue()); } } }); LinkedHashMap<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:com.pamarin.income.controller.NormalSettingsCtrl.java
private void sortBySymbolAscending() { Collections.sort(currencys, new Comparator<Currency>() { @Override/*from w w w .j a va 2s . co m*/ public int compare(Currency o1, Currency o2) { return o1.getSymbol().compareTo(o2.getSymbol()); } }); }
From source file:Main.java
/** * Given an un-encoded URI query string, this will return a normalized, properly encoded URI query string. * <b>Important:</b> This method uses java's URLEncoder, which returns things that are * application/x-www-form-urlencoded, instead of things that are properly octet-esacped as the URI spec * requires. As a result, some substitutions are made to properly translate space characters to meet the * URI spec./*from w w w . ja v a 2s .co m*/ * @param queryString * @return */ private static String normalizeQueryString(String queryString) throws UnsupportedEncodingException { if ("".equals(queryString) || queryString == null) return queryString; String[] pieces = queryString.split("&"); HashMap<String, String> kvp = new HashMap<String, String>(); StringBuffer builder = new StringBuffer(""); for (int x = 0; x < pieces.length; x++) { String[] bs = pieces[x].split("=", 2); bs[0] = URLEncoder.encode(bs[0], "UTF-8"); if (bs.length == 1) kvp.put(bs[0], null); else { kvp.put(bs[0], URLEncoder.encode(bs[1], "UTF-8").replaceAll("\\+", "%20")); } } // Sort the keys alphabetically, ignoring case. ArrayList<String> keys = new ArrayList<String>(kvp.keySet()); Collections.sort(keys, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); // With the alphabetic list of parameter names, re-build the query string. for (int x = 0; x < keys.size(); x++) { // Some parameters have no value, and are simply present. If so, we put null in kvp, // and we just put the parameter name, no "=value". if (kvp.get(keys.get(x)) == null) builder.append(keys.get(x)); else builder.append(keys.get(x) + "=" + kvp.get(keys.get(x))); if (x < (keys.size() - 1)) builder.append("&"); } return builder.toString(); }
From source file:br.edu.ifpb.controllers.SimpleGetPagesController.java
@GetMapping("/home") public ModelAndView home() { ModelAndView mav = new ModelAndView("home"); List<Topic> topics = topicRepository.findAll(); Collections.sort(topics, Topic.Comparators.DATA); mav.addObject("topics", topics); return mav;/*from w ww.j a v a 2s . c o m*/ }
From source file:Main.java
private DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) { String curPath = dir.getPath(); DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath); if (curTop != null) { curTop.add(curDir);//w w w .ja v a 2 s . c om } Vector<String> ol = new Vector<String>(); String[] tmp = dir.list(); for (int i = 0; i < tmp.length; i++) { ol.addElement(tmp[i]); } Collections.sort(ol, String.CASE_INSENSITIVE_ORDER); File f; Vector<Object> files = new Vector<Object>(); for (int i = 0; i < ol.size(); i++) { String thisObject = ol.elementAt(i); String newPath; if (curPath.equals(".")) { newPath = thisObject; } else { newPath = curPath + File.separator + thisObject; } if ((f = new File(newPath)).isDirectory()) { addNodes(curDir, f); } else { files.addElement(thisObject); } } for (int fnum = 0; fnum < files.size(); fnum++) { curDir.add(new DefaultMutableTreeNode(files.elementAt(fnum))); } return curDir; }
From source file:com.cladonia.xngreditor.ErrorList.java
public void sortErrorsByLineNumber() { Collections.sort(errors, this); }
From source file:com.agiletec.apsadmin.user.UserFinderAction.java
@Override public List<UserDetails> getUsers() { try {//from w ww .j a v a 2s . co m List<UserDetails> users = this.getUserManager().searchUsers(this.getText()); BeanComparator comparator = new BeanComparator("username"); Collections.sort(users, comparator); return users; } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "getUsers"); throw new RuntimeException("Errore in ricerca utenti", t); } }
From source file:net.sf.jabref.model.database.EntrySorter.java
public EntrySorter(List<BibEntry> entries, Comparator<BibEntry> comparator) { this.entries = new ArrayList<>(entries); Collections.sort(this.entries, comparator); }
From source file:de.mpg.imeji.presentation.license.LicenseViewer.java
/** * Sort the license by the start date/*w w w . j a v a 2s . co m*/ * * @param licenses * @return */ public List<License> getLicensesSortedByDate(List<License> licenses) { final List<License> sorted = new ArrayList<>(licenses); Collections.sort(sorted, (l1, l2) -> l1.getStart() > l2.getStart() ? -1 : 1); return sorted; }