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:com.model.database.Databases.java
public static HashMap<String, String[]> getDbInfo() { HashMap<String, String[]> infoMap = new HashMap<String, String[]>(); try {/*from w w w . j a v a2 s.c o m*/ path = Databases.class.getProtectionDomain().getCodeSource().getLocation().getPath(); BufferedReader reader = new BufferedReader( new FileReader(path + "../../src/main/resources/admin/resources/dbInfo.csv")); String[] keys = reader.readLine().trim().split(","); ArrayList<String[]> elem = new ArrayList<String[]>(); String line = reader.readLine(); while (line != null && !line.equals("")) { elem.add(line.trim().split(",")); line = reader.readLine(); } Collections.sort(elem, new Comparator<String[]>() { public int compare(String[] l1, String[] l2) { return Integer.parseInt(l1[0]) - Integer.parseInt(l2[0]); } }); reader.close(); for (int i = 0; i < keys.length; i++) { String[] tmp = new String[elem.size()]; for (int j = 0; j < elem.size(); j++) { tmp[j] = elem.get(j)[i]; } infoMap.put(keys[i], tmp); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("The database size is : " + String.valueOf(infoMap.get("databaseIndex").length)); return infoMap; }
From source file:com.tassadar.multirommgr.installfragment.UbuntuImage.java
public UbuntuImage(JSONObject img) throws JSONException { version = img.getInt("version"); description = img.getString("description"); JSONArray f = img.getJSONArray("files"); for (int i = 0; i < f.length(); ++i) { JSONObject file = f.getJSONObject(i); files.add(new UbuntuFile(file)); }//from w ww . j a va2 s . co m Collections.sort(files, this); }
From source file:com.local.ask.controller.spring.HomeController.java
@RequestMapping(value = "/home/hottest", method = RequestMethod.GET) public String loadHomeHottestQuestionForm(Model m) { List<Question> questions = dbHelper.getRecentForHottestQuestions(); Collections.sort(questions, hottestComparator); m.addAttribute("qtag", false); m.addAttribute("questions", questions); m.addAttribute("tags", dbHelper.getRecentTags()); m.addAttribute("tab", 1); return "home"; }
From source file:com.xebia.devradar.Timeline.java
public void update(Collection<Event> workspaceEvents) { List<Event> workspaceSortedEvents = new ArrayList<Event>(workspaceEvents); Collections.sort(workspaceSortedEvents, Collections.reverseOrder(new Comparator<Event>() { @Override/*from ww w . jav a 2s . c o m*/ public int compare(Event o1, Event o2) { return new CompareToBuilder().append(o1.timestamp, o2.timestamp).toComparison(); } })); if (workspaceSortedEvents.size() < MAX_SIZE) { this.events = workspaceSortedEvents; } else { this.events = workspaceSortedEvents.subList(0, MAX_SIZE); } }
From source file:com.gemalto.split.additionalservices.ViveService_SortingByField.java
public void addAndSortRecords(HeaderKey toAdd, Map<String, List<Record>> mapGroupBySortfield) { logger.info("Sorting Header(Rememsa)..." + toAdd.getHeaderKey()); Set<String> sortingFields = mapGroupBySortfield.keySet(); logger.info("Sorting Mensajera"); List<String> mensajerias = new ArrayList<String>(sortingFields); Collections.sort(mensajerias, new StringComparator()); for (String sortingField : mensajerias) { //sort by PAN logger.info(" Sorting Array of Field (Mensajeria):" + sortingField + " Qty of records:" + mapGroupBySortfield.get(sortingField).size()); Collections.sort(mapGroupBySortfield.get(sortingField), new PanComparator()); //allRecords.put(toAdd, mapGroupBySortfield.get(sortingField)); //After sorting the sets of records by PAN we add them to the AllRecrods Map if (allRecords.get(toAdd) == null) { List<Record> tmp = new ArrayList<Record>(); allRecords.put(toAdd, tmp);/*from ww w .j a va2s .c om*/ } allRecords.get(toAdd).addAll(mapGroupBySortfield.get(sortingField)); } logger.info(" Records sorted :" + allRecords.get(toAdd).size()); }
From source file:net.landora.video.properties.Languages.java
public static List<String> getAllLanguages() { ArrayList<String> result = new ArrayList<String>(new HashSet<String>(langMap.values())); Collections.sort(result, new LangSorter()); return result; }
From source file:com.ciphertool.genetics.algorithms.selection.modes.TournamentSelector.java
@Override public int getNextIndex(List<Chromosome> individuals, Double totalFitness) { Collections.sort(individuals, fitnessComparator); for (int i = 0; i < individuals.size(); i++) { if (Math.random() <= selectionAccuracy) { return i; }/*from w ww .jav a 2 s . c om*/ } // return the least fit individual since it won the tournament return individuals.size() - 1; }
From source file:com.indeed.imhotep.web.RunningController.java
@RequestMapping("/running") @ResponseBody//from w w w .j a v a2 s . c o m public State handle() { List<ExecutionManager.QueryTracker> queries = executionManager.getRunningQueries(); Collections.sort(queries, new Comparator<ExecutionManager.QueryTracker>() { @Override public int compare(ExecutionManager.QueryTracker o1, ExecutionManager.QueryTracker o2) { return o1.getStartedTime().compareTo(o2.getStartedTime()); } }); return new State(queries); }
From source file:de.pixida.logtest.designer.automaton.LineIntersector.java
static List<Intersection> calculateIntersections(final Point2D point, final Point2D vec, final List<Line> lines) { Validate.notNull(point);/*from w ww . ja va 2 s. c om*/ Validate.notNull(vec); Validate.notNull(lines); final List<Intersection> results = new ArrayList<>(); for (final Line line : lines) { final Point2D intersection = calculateIntersection(point, vec, line); if (intersection == null) { continue; } if (!checkIfPointIsOnTheLine(intersection, line)) { continue; } results.add(new Intersection(intersection, line, point.distance(intersection))); } Collections.sort(results, (r0, r1) -> Double.compare(r0.getDistance(), r1.getDistance())); return results; }
From source file:com.aqnote.app.wifianalyzer.wifi.band.Country.java
public Country() { countries = new ArrayList<>(); for (Locale locale : Locale.getAvailableLocales()) { String countryCode = locale.getCountry(); if (StringUtils.isNotEmpty(countryCode)) { countries.add(locale);/* www.j a v a2s .c o m*/ } } Collections.sort(countries, new LocaleCountryComparator()); }