List of usage examples for java.util Comparator Comparator
Comparator
From source file:com.clustercontrol.monitor.run.util.EventCache.java
public static void initEventCache() { eventCache = new ConcurrentSkipListSet<EventLogEntity>(new Comparator<EventLogEntity>() { @Override//from ww w .j a va 2 s . c o m public int compare(EventLogEntity o1, EventLogEntity o2) { return (int) (-o1.getId().getOutputDate() + o2.getId().getOutputDate()); } }); new JpaTransactionManager().getEntityManager().clear(); for (EventLogEntity e : QueryUtil.getEventLogByFilter(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, getEventCacheLimit())) { addEventCache(e); } if (eventCache.size() == getEventCacheLimit()) { eventCacheFull = true; } else { eventCacheFull = false; } m_log.info("eventCacheFull=" + eventCacheFull); }
From source file:com.projity.contrib.calendar.ContribIntervals.java
/** * *//* www . j a va 2 s .co m*/ public ContribIntervals() { super(new Comparator() { public int compare(Object o1, Object o2) { DateSpan d1 = (DateSpan) o1; //Only want to compare DateSpan no need to use instanceof DateSpan d2 = (DateSpan) o2; if (d1.getStart() < d2.getStart() || (d1.getStart() == d2.getStart() && d1.getEnd() < d2.getEnd())) return -1; else if (d1.getStart() > d2.getStart() || (d1.getStart() == d2.getStart() && d1.getEnd() > d2.getEnd())) return 1; else return 0; } }); }
From source file:cc.kave.commons.pointsto.evaluation.cv.ProjectCVFoldBuilder.java
@Override public List<List<Usage>> createFolds(Map<ProjectIdentifier, List<Usage>> projectUsages) { List<ProjectIdentifier> projects = new ArrayList<>(projectUsages.keySet()); // sort projects in ascending order according to the number of usages projects.sort(new Comparator<ProjectIdentifier>() { @Override//from www . ja v a2 s . co m public int compare(ProjectIdentifier o1, ProjectIdentifier o2) { return projectUsages.get(o1).size() - projectUsages.get(o2).size(); } }); List<List<Usage>> folds = createFolds(calcAvgFoldSize(projectUsages.values())); for (int i = projects.size() - 1; i >= 0; --i) { ProjectIdentifier project = projects.get(i); List<Usage> fold = getSmallestFold(folds); fold.addAll(projectUsages.remove(project)); } shuffleUsages(folds); return folds; }
From source file:architecture.common.util.LocaleUtils.java
public static Locale[] getAvailableLocales() { Locale locales[] = Locale.getAvailableLocales(); Arrays.sort(locales, new Comparator<Locale>() { public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayName().compareTo(locale2.getDisplayName()); }/*from w w w. j a va2 s. c o m*/ }); return locales; }
From source file:azkaban.flow.GroupedFlow.java
public GroupedFlow(Flow... flows) { this.flows = flows; this.sortedFlows = Arrays.copyOf(this.flows, this.flows.length); Arrays.sort(this.sortedFlows, new Comparator<Flow>() { @Override/*from w w w . j av a 2 s . c om*/ public int compare(Flow o1, Flow o2) { return o1.getName().compareTo(o2.getName()); } }); }
From source file:com.autburst.picture.Utilities.java
public static Comparator<String> getAlbumNameComparator() { return new Comparator<String>() { @Override//from w w w.j a v a2 s . c o m public int compare(String arg0, String arg1) { String decodeName0 = new String(Base64.decodeBase64(arg0.getBytes())); String decodeName1 = new String(Base64.decodeBase64(arg1.getBytes())); return decodeName0.compareTo(decodeName1); } }; }
From source file:org.woofenterprise.dogs.web.controllers.WelcomeController.java
@RequestMapping("/") public String welcomePage(Model model) { List<AppointmentDTO> appointments = new ArrayList<>(facade.findAllAppointmentsForToday()); Collections.sort(appointments, new Comparator<AppointmentDTO>() { @Override/*from w w w . ja v a2s. c om*/ public int compare(AppointmentDTO o1, AppointmentDTO o2) { return o1.getStartTime().compareTo(o2.getStartTime()); } }); model.addAttribute("appointments", appointments); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); for (GrantedAuthority auth : authentication.getAuthorities()) { log.warn("SECURITY PRINCIPLES ROLES: {}", auth.getAuthority()); } return "welcome"; }
From source file:org.freeeed.search.web.controller.ListUsersController.java
@Override public ModelAndView execute() { log.debug("List users called..."); if (!loggedSiteVisitor.getUser().hasRight(User.Right.USERS_ADMIN)) { try {//from w w w.j a va 2s .c om response.sendRedirect(WebConstants.MAIN_PAGE_REDIRECT); } catch (IOException e) { } } List<User> users = userDao.listUsers(); Collections.sort(users, new Comparator<User>() { @Override public int compare(User o1, User o2) { return o1.getUsername().compareTo(o2.getUsername()); } }); valueStack.put("users", users); return new ModelAndView(WebConstants.LIST_USERS_PAGE); }
From source file:it.geosolutions.geoserver.jms.JMSManager.java
/** * Method to make lookup using the type of the passed eventType. * // www. j a v a2s . c o m * @param <S> * @param <O> * @param eventType * @return the handler * @throws IllegalArgumentException */ public <S extends Serializable, O> JMSEventHandler<S, O> getHandler(final O eventType) throws IllegalArgumentException { final Set<?> beanSet = beans.entrySet(); // declare a tree set to define the handler priority final Set<JMSEventHandlerSPI<S, O>> candidates = new TreeSet<JMSEventHandlerSPI<S, O>>( new Comparator<JMSEventHandlerSPI<S, O>>() { @Override public int compare(JMSEventHandlerSPI<S, O> o1, JMSEventHandlerSPI<S, O> o2) { if (o1.getPriority() < o2.getPriority()) return -1; else if (o1.getPriority() == o2.getPriority()) { return 0; // } else if (o1.getPriority()>o2.getPriority()){ } else { return 1; } } }); // for each handler check if it 'canHandle' the incoming object if so // add it to the tree for (final Iterator<?> it = beanSet.iterator(); it.hasNext();) { final Map.Entry<String, ?> entry = (Entry<String, ?>) it.next(); final JMSEventHandlerSPI<S, O> spi = (JMSEventHandlerSPI) entry.getValue(); if (spi != null) { if (spi.canHandle(eventType)) { if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Creating an instance of: " + spi.getClass()); candidates.add(spi); } } } // TODO return the entire tree leaving choice to the caller (useful to // build a failover list) // return the first available handler final Iterator<JMSEventHandlerSPI<S, O>> it = candidates.iterator(); while (it.hasNext()) { try { final JMSEventHandler<S, O> handler = it.next().createHandler(); if (handler != null) return handler; } catch (Exception e) { if (LOGGER.isLoggable(Level.WARNING)) LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); } } final String message = "Unable to find the needed Handler SPI for event of type: " + eventType.getClass().getCanonicalName(); if (LOGGER.isLoggable(Level.WARNING)) LOGGER.warning(message); throw new IllegalArgumentException(message); }
From source file:org.lieuofs.extraction.commune.ExtractionGeTax.java
public void extraire() throws IOException { CommuneCritere critere = new CommuneCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.JANUARY, 1); critere.setDateValiditeApres(cal.getTime()); cal.set(2012, Calendar.DECEMBER, 31); critere.setDateValiditeAvant(cal.getTime()); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); Collections.sort(communes, new Comparator<ICommuneSuisse>() { @Override/* www .ja v a 2s . c o m*/ public int compare(ICommuneSuisse o1, ICommuneSuisse o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); // Attention, le fichier est une iste historise des communes. // Une commune peut donc figurer 2 fois dans le fichier Set<Integer> numOFS = new HashSet<Integer>(3000); int nbreCommune = 0; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionCommuneGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (ICommuneSuisse commune : communes) { if (!numOFS.contains(commune.getNumeroOFS())) { nbreCommune++; numOFS.add(commune.getNumeroOFS()); writer.write(String.valueOf(commune.getNumeroOFS())); writer.write(";"); writer.write(commune.getNomCourt()); writer.write(";"); writer.write(commune.getCanton().getCodeIso2()); writer.newLine(); System.out.println(commune.getNumeroOFS() + " " + commune.getNomCourt()); } } writer.close(); System.out.println("Nbre commune : " + nbreCommune); }