List of usage examples for java.util Comparator Comparator
Comparator
From source file:com.sisrni.managedbean.ReporteNoticias.java
public void obtenerDatos(String formato) { List<String> categoriaList = categoriaNoticiaService.getCategoriaNoticiaName(); List<RptNoticiasPojo> list = new ArrayList<RptNoticiasPojo>(); RptNoticiasPojo aux;//from w ww . jav a 2 s . c om for (String cat : categoriaList) { aux = new RptNoticiasPojo(); aux.setCategoria(cat); aux.setCantidad(noticiaService.getCountNoticiasByCat(cat, desde, hasta)); list.add(aux); } Collections.sort(list, new Comparator<RptNoticiasPojo>() { @Override public int compare(RptNoticiasPojo p1, RptNoticiasPojo p2) { return p1.getCategoria().compareTo(p2.getCategoria()); } }); print(list, formato); }
From source file:de.burrotinto.jKabel.config.trommelSort.AbstractTrommelSort.java
protected int getAusleihMinuten(ITrommelE t) { List<IStreckeE> strecken = t.getStrecken(); Collections.sort(strecken, new Comparator<IStreckeE>() { @Override//from w w w .jav a 2s . c o m public int compare(IStreckeE iStreckeE, IStreckeE t1) { return -((Long) iStreckeE.getVerlegedatum()).compareTo(t1.getVerlegedatum()); } }); if (strecken.size() == 0) { return 0; } else { return (int) ((System.currentTimeMillis() - strecken.get(0).getVerlegedatum()) / ((long) (1000 * 60))); } }
From source file:i2p.bote.web.PeerInfoTag.java
@Override public void doTag() { PageContext pageContext = (PageContext) getJspContext(); JspWriter out = pageContext.getOut(); try {/*from w w w . ja v a2s.co m*/ // Print DHT peer info DhtPeerStats dhtStats = I2PBote.getInstance().getDhtStats(); if (dhtStats == null) return; int numDhtPeers = dhtStats.getData().size(); // Get a sorted list of relay peers RelayPeer[] relayPeers = I2PBote.getInstance().getRelayPeers().toArray(new RelayPeer[0]); Arrays.sort(relayPeers, new Comparator<RelayPeer>() { @Override public int compare(RelayPeer peer1, RelayPeer peer2) { return peer2.getReachability() - peer1.getReachability(); } }); // Print charts out.println("<div class=\"network-charts\">"); out.println("<div class=\"chart\">"); out.println("<img src=\"displayChart?filename=" + createDhtChart(dhtStats) + "\"/>"); out.println("<div class=\"chart-text\">" + numDhtPeers + "</div>"); out.println("</div>"); out.println("<div class=\"chart\">"); out.println("<img src=\"displayChart?filename=" + createRelayChart(relayPeers) + "\"/>"); out.println("<div class=\"chart-text\">" + relayPeers.length + "</div>"); out.println("</div>"); out.println("</div>"); out.println("<br>"); out.println("<span class=\"subheading\">" + _t("Kademlia Peers:") + " " + numDhtPeers + "</span>"); if (numDhtPeers > 0) { out.println("<table"); // header out.println("<tr>"); for (String columnHeader : dhtStats.getHeader()) out.println("<th>" + columnHeader + "</th>"); out.println("</tr>"); // data for (List<String> row : dhtStats.getData()) { out.println("<tr>"); for (String cellData : row) out.println("<td class=\"ellipsis\">" + cellData + "</td>"); out.println("</tr>"); } out.println("</table>"); } out.println("<br/>"); // Print relay peer info out.println("<span class=\"subheading\">" + _t("Relay Peers:") + " " + relayPeers.length + "</span>"); if (relayPeers.length > 0) { out.println("<table"); out.println("<tr>"); out.println("<th>" + _t("Peer") + "</th>"); out.println("<th>" + _t("I2P Destination") + "</th>"); out.println("<th>" + _t("Reachability %") + "</th>"); out.println("</tr>"); int i = 1; for (RelayPeer peer : relayPeers) { out.println("<tr>"); out.println("<td>" + i + "</td>"); out.println("<td class=\"ellipsis\">" + Util.toBase32(peer) + "</td>"); int reachability = peer.getReachability(); out.println("<td>" + (reachability == 0 ? _t("Untested") : reachability) + "</td>"); out.println("</tr>"); i++; } out.println("</table>"); } out.println("<br/>"); // List banned peers Collection<BannedPeer> bannedPeers = I2PBote.getInstance().getBannedPeers(); out.println("<span class=\"subheading\">" + _t("Banned Peers:") + " " + bannedPeers.size() + "</span>"); if (bannedPeers.size() > 0) { out.println("<table>"); out.println("<tr>"); out.println("<th>" + _t("Peer") + "</th>"); out.println("<th>" + _t("Destination Hash") + "</th>"); out.println("<th>" + _t("Ban Reason") + "</th>"); out.println("</tr>"); int peerIndex = 1; for (BannedPeer peer : bannedPeers) { out.println("<tr>"); out.println("<td>" + peerIndex++ + "</td>"); out.println("<td class=\"ellipsis\">" + Util.toBase32(peer.getDestination()) + "</td>"); out.println("<td>" + (peer.getBanReason() == null ? "" : peer.getBanReason()) + "</td>"); out.println("</tr>"); } out.println("</table>"); } } catch (IOException e) { log.error("Can't write output to HTML page", e); } }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReader.java
/** * Tries to extract all files in the archives and adds them as resources to * the normal MultiResourceItemReader. Overwrites the Comparator from * the super class to get it working with itemstreams. * * @param executionContext/* ww w . j ava 2 s . com*/ * @throws ItemStreamException */ @Override public void open(ExecutionContext executionContext) throws ItemStreamException { // really used with archives? if (archives != null) { // overwrite the comparator to use description // instead of filename, the itemStream can only // have that description this.setComparator(new Comparator<Resource>() { /** Compares resource descriptions. */ @Override public int compare(Resource r1, Resource r2) { return r1.getDescription().compareTo(r2.getDescription()); } }); // get the inputStreams from all files inside the archives zipFiles = new ZipFile[archives.length]; List<Resource> extractedResources = new ArrayList<Resource>(); try { for (int i = 0; i < archives.length; i++) { // find files inside the current zip resource zipFiles[i] = new ZipFile(archives[i].getFile()); extractFiles(zipFiles[i], extractedResources); } } catch (Exception ex) { throw new ItemStreamException(ex); } // propagate extracted resources this.setResources(extractedResources.toArray(new Resource[extractedResources.size()])); } super.open(executionContext); }
From source file:springfox.documentation.spi.service.contexts.Orderings.java
public static Comparator<RequestMappingContext> methodComparator() { return new Comparator<RequestMappingContext>() { @Override/* w ww. j a v a 2 s . co m*/ public int compare(RequestMappingContext first, RequestMappingContext second) { return qualifiedMethodName(first).compareTo(qualifiedMethodName(second)); } }; }
From source file:edu.uiowa.icts.bluebutton.json.view.StatsFinder.java
public Double getMax() { List<Double> dList = this.getDoubleList(); Double max = Collections.max(dList, new Comparator<Double>() { public int compare(Double d, Double d2) { if (d > d2) { return 1; } else if (d < d2) { return -1; }/*from w w w. j a v a 2s .c o m*/ return 0; } }); return max; }
From source file:com.mmounirou.spotirss.rss.ChartRss.java
@SuppressWarnings("unchecked") public static ChartRss getInstance(String strUrl, final EntryToTrackConverter converter) throws MalformedURLException, ChartRssException { File rssCache = new File(FileUtils.getTempDirectory(), "billboard-charts"); rssCache.mkdirs();/*from w ww . j a v a2 s. c o m*/ FeedFetcherCache feedFetcherCache = new DiskFeedInfoCache(rssCache.getAbsolutePath()); FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedFetcherCache); URL feedUrl = new URL(strUrl); try { SyndFeed retrievedFeed = feedFetcher.retrieveFeed(feedUrl); String title = retrievedFeed.getTitle(); ImmutableSortedSet<Track> songs = FluentIterable.from((List<SyndEntry>) retrievedFeed.getEntries()) .transform(new Function<SyndEntry, Track>() { @Override @Nonnull public Track apply(@Nonnull SyndEntry entry) { try { return converter.apply(entry.getTitle()); } catch (Exception e) { SpotiRss.LOGGER.error(String.format("fail to parse %s ", entry.getTitle())); return null; } } }).filter(Predicates.notNull()).toImmutableSortedSet(new Comparator<Track>() { @Override public int compare(Track o1, Track o2) { return Integer.valueOf(o1.getRank()).compareTo(Integer.valueOf(o2.getRank())); } }); return new ChartRss(title, songs); } catch (IllegalArgumentException e) { throw new ChartRssException(e); } catch (IOException e) { throw new ChartRssException(e); } catch (FeedException e) { throw new ChartRssException(e); } catch (FetcherException e) { throw new ChartRssException(e); } }
From source file:ca.uhn.fhir.rest.server.provider.ServerProfileProvider.java
@Search() public List<Profile> getAllProfiles(HttpServletRequest theRequest) { final String serverBase = getServerBase(theRequest); List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>( myContext.getResourceDefinitionsWithExplicitId()); Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() { @Override// ww w . j a v a 2 s.c o m public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) { int cmp = theO1.getName().compareTo(theO2.getName()); if (cmp == 0) { cmp = theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase)); } return cmp; } }); ArrayList<Profile> retVal = new ArrayList<Profile>(); for (RuntimeResourceDefinition next : defs) { retVal.add((Profile) next.toProfile(serverBase)); } return retVal; }
From source file:com.evolveum.midpoint.util.MiscUtil.java
public static boolean unorderedCollectionEquals(Collection a, Collection b) { Comparator<?> comparator = new Comparator<Object>() { @Override/* w w w . ja v a2s. c om*/ public int compare(Object o1, Object o2) { return o1.equals(o2) ? 0 : 1; } }; return unorderedCollectionEquals(a, b, comparator); }
From source file:com.chinamobile.bcbsp.bspcontroller.FCFSQueue.java
@Override public void resortQueue() { Comparator<JobInProgress> comp = new Comparator<JobInProgress>() { @Override/* w ww . jav a 2 s . c o m*/ public int compare(JobInProgress o1, JobInProgress o2) { int res = o1.getPriority().compareTo(o2.getPriority()); if (res == 0) { if (o1.getStartTime() < o2.getStartTime()) { res = -1; } else { res = (o1.getStartTime() == o2.getStartTime() ? 0 : 1); } } return res; } }; synchronized (queue) { try { resort_tmp.clear(); int wait_count = queue.size(); int i = 0; for (i = 0; i < wait_count; i++) { resort_tmp.add(queue.take()); } Collections.sort(resort_tmp, comp); for (i = 0; i < wait_count; i++) { queue.put(resort_tmp.get(i)); } } catch (Exception e) { //LOG.error("resort error: " + e.toString()); throw new RuntimeException("resort error: ", e); } } }