List of usage examples for java.util Comparator Comparator
Comparator
From source file:models.Comment.java
public static Comparator<Comment> comparator() { return new Comparator<Comment>() { @Override/*from ww w . java 2 s.c om*/ public int compare(Comment o1, Comment o2) { return o1.createdDate.compareTo(o2.createdDate); } }; }
From source file:com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList.java
public List<AgentActiveThreadCount> getAgentActiveThreadRepository() { // sort agentId agentActiveThreadRepository.sort(new Comparator<AgentActiveThreadCount>() { @Override// w w w.j ava2s . c o m public int compare(AgentActiveThreadCount o1, AgentActiveThreadCount o2) { final String agentId1 = StringUtils.defaultString(o1.getAgentId(), ""); final String agentId2 = StringUtils.defaultString(o2.getAgentId(), ""); return agentId1.compareTo(agentId2); } }); return agentActiveThreadRepository; }
From source file:org.schedulesdirect.grabber.ScheduleTask.java
static void commit(FileSystem vfs) throws IOException { Iterator<String> itr = FULL_SCHEDS.keySet().iterator(); while (itr.hasNext()) { String id = itr.next();// w w w .j a va 2s . c o m JSONObject sched = new JSONObject(); List<JSONObject> airs = FULL_SCHEDS.get(id); Collections.sort(airs, new Comparator<JSONObject>() { @Override public int compare(JSONObject arg0, JSONObject arg1) { return arg0.getString("airDateTime").compareTo(arg1.getString("airDateTime")); } }); sched.put("programs", airs); Path p = vfs.getPath("schedules", String.format("%s.txt", id)); Files.write(p, sched.toString(3).getBytes(ZipEpgClient.ZIP_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); } FULL_SCHEDS.clear(); }
From source file:fr.aliasource.webmail.proxy.impl.CompletionRegistry.java
public CompletionRegistry(ProxyConfiguration conf, LocatorRegistry locator) { logger = LogFactory.getLog(getClass()); this.conf = conf; completionComparator = new Comparator<Completion>() { public int compare(Completion o1, Completion o2) { return o1.getCompareValue().compareTo(o2.getCompareValue()); }//from w w w. j a va2s .co m }; factories = new LinkedList<ICompletionSourceFactory>(); loadPlugins(conf); }
From source file:org.freeeed.search.web.controller.ListCasesController.java
@Override public ModelAndView execute() { log.debug("List cases called..."); if (!loggedSiteVisitor.getUser().hasRight(User.Right.CASES)) { try {//from www. j a va2s.c o m response.sendRedirect(WebConstants.MAIN_PAGE_REDIRECT); } catch (IOException e) { } } List<Case> cases = caseDao.listCases(); Collections.sort(cases, new Comparator<Case>() { @Override public int compare(Case o1, Case o2) { return o1.getName().compareTo(o2.getName()); } }); valueStack.put("cases", cases); return new ModelAndView(WebConstants.LIST_CASES_PAGE); }
From source file:com.kevinquan.google.activityrecoginition.model.MotionHelper.java
public static List<MotionSnapshot> parseMotionSnapshots(Cursor result, final boolean sortDescending) { if (!CursorUtils.hasResults(result)) { Log.d(TAG, "No results were provided to parse motion snapshots from"); return new ArrayList<MotionSnapshot>(); }//from w ww. j av a 2s .com Hashtable<Long, MotionSnapshot> snapshots = new Hashtable<Long, MotionSnapshot>(); do { Motion thisMotion = new Motion(result); if (thisMotion.getTimestamp() == 0) { Log.w(TAG, "Current motion seems corrupt: " + thisMotion); continue; } if (!snapshots.containsKey(thisMotion.getTimestamp())) { MotionSnapshot snapshot = new MotionSnapshot(thisMotion); snapshots.put(snapshot.getTimestamp(), snapshot); } else { if (!snapshots.get(thisMotion.getTimestamp()).addMotion(thisMotion)) { Log.w(TAG, "Could not add motion to snapshot: " + thisMotion.toString()); } } } while (result.moveToNext()); List<MotionSnapshot> results = new ArrayList<MotionSnapshot>(); results.addAll(snapshots.values()); Collections.sort(results, new Comparator<MotionSnapshot>() { @Override public int compare(MotionSnapshot lhs, MotionSnapshot rhs) { int result = ((Long) lhs.getTimestamp()).compareTo((Long) rhs.getTimestamp()); return sortDescending ? -1 * result : result; } }); return results; }
From source file:com.ricemap.spateDB.core.PrismNN.java
/** * @param R//from ww w . ja v a 2 s. com * @param S * @param output * @return * @throws IOException */ public static <S1 extends Shape, S2 extends Shape> int SpatialJoin_planeSweep(List<S1> R, List<S2> S, ResultCollector2<S1, S2> output) throws IOException { int count = 0; Comparator<Shape> comparator = new Comparator<Shape>() { @Override public int compare(Shape o1, Shape o2) { return o1.getMBR().x1 < o2.getMBR().x1 ? -1 : 1; } }; LOG.info("Joining " + R.size() + " with " + S.size()); Collections.sort(R, comparator); Collections.sort(S, comparator); int i = 0, j = 0; while (i < R.size() && j < S.size()) { S1 r; S2 s; if (comparator.compare(R.get(i), S.get(j)) < 0) { r = R.get(i); int jj = j; while ((jj < S.size()) && ((s = S.get(jj)).getMBR().x1 <= r.getMBR().x2)) { if (r.isIntersected(s)) { if (output != null) output.collect(r, s); count++; } jj++; } i++; } else { s = S.get(j); int ii = i; while ((ii < R.size()) && ((r = R.get(ii)).getMBR().x1 <= s.getMBR().x2)) { if (r.isIntersected(s)) { if (output != null) output.collect(r, s); count++; } ii++; } j++; } } LOG.info("Finished plane sweep and found " + count + " pairs"); return count; }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
public HttpHeaders() { super(new Comparator<String>() { @Override/* w w w. ja va2 s . co m*/ public int compare(String o1, String o2) { return o1.compareTo(o2); } }); }
From source file:com.js.quickestquail.ui.stats.YearStat.java
private CategoryDataset generateDataset() { Map<Integer, Integer> yearFrequency = new HashMap<>(); for (String id : DriveManager.get().getSelected().values()) { Movie mov = CachedMovieProvider.get().getMovieByID(id); int year = mov.getYear(); if (!yearFrequency.containsKey(year)) { yearFrequency.put(year, 1);//from www . jav a2s .co m } else { yearFrequency.put(year, yearFrequency.get(year) + 1); } } List<Entry<Integer, Integer>> entries = new ArrayList<>(yearFrequency.entrySet()); java.util.Collections.sort(entries, new Comparator<Entry<Integer, Integer>>() { @Override public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) { return o1.getKey().compareTo(o2.getKey()); } }); // convert to proper format DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Entry<Integer, Integer> en : entries) { dataset.addValue(en.getValue(), java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.year.xaxis"), en.getKey()); } // return return dataset; }
From source file:Main.java
DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) { DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(dir); if (curTop != null) { curTop.add(curDir);/*ww w . ja va2 s .c o m*/ } File[] tmp = dir.listFiles(); Vector<File> ol = new Vector<File>(); ol.addAll(Arrays.asList(tmp)); Collections.sort(ol, new Comparator<File>() { @Override public int compare(File o1, File o2) { int result = o1.getName().compareTo(o2.getName()); if (o1.isDirectory() && o2.isFile()) { result = -1; } else if (o2.isDirectory() && o1.isFile()) { result = 1; } return result; } }); for (int i = 0; i < ol.size(); i++) { File file = ol.elementAt(i); DefaultMutableTreeNode node = new DefaultMutableTreeNode(file); if (file.isDirectory()) { addNodes(node, file); } curDir.add(node); } return curDir; }