List of usage examples for java.util Comparator Comparator
Comparator
From source file:nz.net.orcon.kanban.controllers.UiController.java
@RequestMapping(value = "/boards/{boardId}", method = RequestMethod.GET) public String board(@PathVariable String boardId, Model model) throws Exception { log.info("Board UI - " + boardId); model.addAttribute("boardId", boardId); Board board = boardsCache.getItem(boardId); model.addAttribute("board", board); Map<String, SimpleTemplate> values = board.getTemplates(); if (values != null) { SimpleTemplate templateId = values.values().iterator().next(); model.addAttribute("templateId", templateId.getId()); }//w w w. java 2 s.c o m List<Phase> phases = new ArrayList<Phase>(board.getPhases().values()); Collections.sort(phases, new Comparator<Phase>() { @Override public int compare(Phase phase0, Phase phase1) { return phase0.getIndex() - phase1.getIndex(); } }); model.addAttribute("phases", phases); return "board"; }
From source file:com.chintans.venturebox.server.VentureServer.java
@Override public List<PackageInfo> createPackageInfoList(JSONObject response) throws Exception { mError = null;/* ww w . j a v a 2 s . c om*/ List<PackageInfo> list = new ArrayList<PackageInfo>(); mError = response.optString("error"); if (mError == null || mError.isEmpty()) { JSONArray updates = response.getJSONArray("updates"); for (int i = updates.length() - 1; i >= 0; i--) { JSONObject file = updates.getJSONObject(i); String filename = file.optString("name"); String stripped = filename.replace(".zip", ""); String[] parts = stripped.split("-"); boolean isNew = parts[parts.length - 1].matches("[-+]?\\d*\\.?\\d+"); if (!isNew) { continue; } Version version = new Version(filename); if (Version.compare(mVersion, version) < 0) { list.add(new UpdatePackage(mDevice, filename, version, file.getString("size"), file.getString("url"), file.getString("md5"), false)); } } } Collections.sort(list, new Comparator<PackageInfo>() { @Override public int compare(Updater.PackageInfo lhs, Updater.PackageInfo rhs) { return Version.compare(lhs.getVersion(), rhs.getVersion()); } }); Collections.reverse(list); return list; }
From source file:com.stratio.cassandra.index.query.SortingField.java
public Comparator<Columns> comparator() { return new Comparator<Columns>() { public int compare(Columns o1, Columns o2) { if (o1 == null) { return o2 == null ? 0 : 1; }//ww w . ja va2 s . c o m if (o2 == null) { return -1; } Column column1 = o1.getCell(field); Column column2 = o2.getCell(field); if (column1 == null) { return column2 == null ? 0 : 1; } if (column2 == null) { return -1; } AbstractType<?> type = column1.getType(); ByteBuffer value1 = column1.getRawValue(); ByteBuffer value2 = column2.getRawValue(); return reverse ? type.compare(value2, value1) : type.compare(value1, value2); } }; }
From source file:io.lavagna.service.CardService.java
public List<CardFullWithCounts> fetchAllInColumn(int columnId) { List<CardFull> cards = cardRepository.findAllByColumnId(columnId); if (cards.isEmpty()) { return Collections.emptyList(); }/*from www.j a va2s.c o m*/ List<CardFullWithCounts> res = fetchCardFull(cards); Collections.sort(res, new Comparator<CardFullWithCounts>() { @Override public int compare(CardFullWithCounts o1, CardFullWithCounts o2) { return new CompareToBuilder().append(o1.getOrder(), o2.getOrder()).toComparison(); } }); // return res; }
From source file:net.chrissearle.flickrvote.web.admin.ScoreAction.java
@Override public String input() throws Exception { if (logger.isLoggable(Level.FINE)) { logger.fine("Challenge ID " + tag); }/* w w w .jav a 2s .c o m*/ ChallengeSummary challengeSummary = challengeService.getChallengeSummary(tag); if (logger.isLoggable(Level.FINE)) { logger.fine("Challenge " + challengeSummary); } if (challengeSummary != null) { challenge = new DisplayChallengeSummary(challengeSummary); ChallengeItem challengeItem = photographyService.getChallengeImages(challengeSummary.getTag()); scores = new ArrayList<ScoreAdmin>(challengeItem.getImages().size()); for (ImageItem image : challengeItem.getImages()) { scores.add(new ScoreAdmin(image)); } Collections.sort(scores, new Comparator<ScoreAdmin>() { public int compare(ScoreAdmin o1, ScoreAdmin o2) { return o2.getScore().compareTo(o1.getScore()); } }); } return INPUT; }
From source file:net.hockeyapp.android.internal.VersionHelper.java
private void sortVersions() { Collections.sort(sortedVersions, new Comparator<JSONObject>() { public int compare(JSONObject object1, JSONObject object2) { try { if (object1.getInt("version") > object2.getInt("version")) { return 0; }//w w w.ja va 2 s. com } catch (JSONException e) { } return 0; } }); }
From source file:com.googlesource.gerrit.plugins.verifystatus.server.GetVerifications.java
private void sortJobs(List<PatchSetVerification> jobs, String order) { if (order.equals("REPORTER")) { // sort the jobs list by reporter(A-Z)/Name(A-Z)/Granted(Z-A) Collections.sort(jobs, new Comparator<PatchSetVerification>() { @Override// w ww.j a v a 2s .c om public int compare(PatchSetVerification a, PatchSetVerification b) { return new CompareToBuilder().append(a.getReporter(), b.getReporter()) .append(a.getName(), b.getName()).append(b.getGranted(), a.getGranted()).toComparison(); } }); } else if (order.equals("NAME")) { // sort the jobs list by Name(A-Z)/Granted(Z-A) Collections.sort(jobs, new Comparator<PatchSetVerification>() { @Override public int compare(PatchSetVerification a, PatchSetVerification b) { return new CompareToBuilder().append(a.getName(), b.getName()) .append(b.getGranted(), a.getGranted()).toComparison(); } }); } else if (order.equals("DATE")) { // sort the jobs list by Granted(Z-A) Collections.sort(jobs, new Comparator<PatchSetVerification>() { @Override public int compare(PatchSetVerification a, PatchSetVerification b) { return new CompareToBuilder().append(b.getGranted(), a.getGranted()).toComparison(); } }); } }
From source file:jetbrains.exodus.io.FileDataReader.java
public static void sortBlocks(Block[] result) { Arrays.sort(result, new Comparator<Block>() { @Override/* w w w. ja v a2s . c om*/ public int compare(Block o1, Block o2) { if (o1.getAddress() < o2.getAddress()) { return -1; } if (o1.getAddress() > o2.getAddress()) { return 1; } return 0; } }); }
From source file:models.Milestone.java
public List<Issue> sortedByNumberOfIssue() { List<Issue> sortedIssues = new ArrayList<>(this.issues); Collections.sort(sortedIssues, new Comparator<Issue>() { @Override//from w w w .ja v a2 s. com public int compare(Issue a, Issue b) { return b.getNumber().compareTo(a.getNumber()); } }); return sortedIssues; }
From source file:gemlite.shell.commands.admin.Monitor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @CliCommand(value = "list services", help = "list services") public String services() { Set<ObjectInstance> names = jmxSrv.listMBeans(); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); if (names == null) return "no services"; Object[] a = names.toArray(); //???//from w w w. j a v a2 s .c om Arrays.sort(a, (Comparator) new Comparator<ObjectInstance>() { @Override public int compare(ObjectInstance o1, ObjectInstance o2) { return (o1.getObjectName().toString()).compareTo(o2.getObjectName().toString()); } }); if (LogUtil.getCoreLog().isDebugEnabled()) LogUtil.getCoreLog().debug("get names size:{} values:{}", names.size(), names.toString()); //?service? for (int i = 0; i < a.length; i++) { ObjectInstance oi = (ObjectInstance) a[i]; // service?,??? HashMap<String, Object> service = new HashMap<String, Object>(); service.put(oi.getObjectName().toString(), service); service.put("serviceName", service); try { Map<String, Object> map = jmxSrv.getAttributesValues(oi.getObjectName().toString()); if (map.size() <= 0) { map.put("serviceName", oi.getObjectName().toString()); LogUtil.getCoreLog().warn("jmxSrv.getAttributesValues is null ,ObjectName {}", oi.getObjectName().toString()); result.add(map); } else { result.add(map); } } catch (Exception e) { LogUtil.getCoreLog().error("jmxSrv.getAttributesValues is null ,ObjectName {},error:{}", oi.getObjectName().toString(), e); } } LinkedHashMap<String, HashMap<String, Object>> rs = (LinkedHashMap<String, HashMap<String, Object>>) get( CommandMeta.LIST_SERVICES); if (rs == null) rs = new LinkedHashMap<String, HashMap<String, Object>>(); for (Map<String, Object> map : result) { // ? HashMap<String, Object> service = rs.get(map.get("serviceName")); if (service == null) { service = new HashMap<String, Object>(); } service.putAll(map); // ? rs.put((String) map.get("serviceName"), service); } // ws?? put(CommandMeta.LIST_SERVICES, rs); if (!result.isEmpty()) return result.toString(); return "no services"; }