List of usage examples for java.util Collections max
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
public RegistrationState getLastActiveState() { List<RegistrationState> activeStateList = new ArrayList<RegistrationState>(); CollectionUtils.select(getRegistrationStatesSet(), new Predicate() { @Override//from w ww .j a v a 2s . com public boolean evaluate(Object arg0) { return ((RegistrationState) arg0).getStateType().isActive(); } }, activeStateList); return !activeStateList.isEmpty() ? Collections.max(activeStateList, RegistrationState.DATE_COMPARATOR) : null; }
From source file:org.opencms.db.CmsDriverManager.java
/** * Selects the best url name for a given resource and locale.<p> * /* w w w . ja va2s .co m*/ * @param dbc the database context * @param id the resource's structure id * @param locale the requested locale * @param defaultLocales the default locales to use if the locale isn't available * * @return the URL name which was found * * @throws CmsDataAccessException if the database operation failed */ public String readBestUrlName(CmsDbContext dbc, CmsUUID id, Locale locale, List<Locale> defaultLocales) throws CmsDataAccessException { List<CmsUrlNameMappingEntry> entries = getVfsDriver(dbc).readUrlNameMappingEntries(dbc, dbc.currentProject().isOnlineProject(), CmsUrlNameMappingFilter.ALL.filterStructureId(id)); if (entries.isEmpty()) { return null; } ArrayListMultimap<String, CmsUrlNameMappingEntry> entriesByLocale = ArrayListMultimap.create(); for (CmsUrlNameMappingEntry entry : entries) { entriesByLocale.put(entry.getLocale(), entry); } List<CmsUrlNameMappingEntry> lastEntries = new ArrayList<CmsUrlNameMappingEntry>(); Comparator<CmsUrlNameMappingEntry> dateChangedComparator = new UrlNameMappingComparator(); for (String localeKey : entriesByLocale.keySet()) { // for each locale select the latest mapping entry CmsUrlNameMappingEntry latestEntryForLocale = Collections.max(entriesByLocale.get(localeKey), dateChangedComparator); lastEntries.add(latestEntryForLocale); } CmsLocaleManager localeManager = OpenCms.getLocaleManager(); List<Locale> availableLocales = new ArrayList<Locale>(); for (CmsUrlNameMappingEntry entry : lastEntries) { availableLocales.add(CmsLocaleManager.getLocale(entry.getLocale())); } Locale bestLocale = localeManager.getBestMatchingLocale(locale, defaultLocales, availableLocales); String bestLocaleStr = bestLocale.getLanguage(); for (CmsUrlNameMappingEntry entry : lastEntries) { if (entry.getLocale().equals(bestLocaleStr)) { return entry.getName(); } } return null; }
From source file:org.opencms.db.CmsDriverManager.java
/** * Reads the newest URL names of a resource for all locales.<p> * // ww w .ja v a2 s .c o m * @param dbc the database context * @param id the resource's structure id * * @return the url names for the locales * * @throws CmsDataAccessException if the database operation failed */ public List<String> readUrlNamesForAllLocales(CmsDbContext dbc, CmsUUID id) throws CmsDataAccessException { List<String> result = new ArrayList<String>(); List<CmsUrlNameMappingEntry> entries = getVfsDriver(dbc).readUrlNameMappingEntries(dbc, dbc.currentProject().isOnlineProject(), CmsUrlNameMappingFilter.ALL.filterStructureId(id)); ArrayListMultimap<String, CmsUrlNameMappingEntry> entriesByLocale = ArrayListMultimap.create(); for (CmsUrlNameMappingEntry entry : entries) { String localeKey = entry.getLocale(); entriesByLocale.put(localeKey, entry); } for (String localeKey : entriesByLocale.keySet()) { List<CmsUrlNameMappingEntry> entrs = entriesByLocale.get(localeKey); CmsUrlNameMappingEntry maxEntryForLocale = Collections.max(entrs, new UrlNameMappingComparator()); result.add(maxEntryForLocale.getName()); } return result; }