List of usage examples for java.util Collections reverseOrder
@SuppressWarnings("unchecked") public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
From source file:com.thesoftwareguild.capstoneblog.dao.BlogDaoDbImpl.java
@Override public List<Post> getAllPublishedPosts() { // List<Post> posts = new ArrayList<>(); List<Post> posts = jdbcTemplate.query(SQL_SELECT_ALL_PUBLISHED_POSTS, new PostMapper()); // Get associated categories for (Post p : posts) { setPostCategories(p);// w w w . j a v a 2 s. com setPostTags(p); setPostComments(p); } Collections.sort(posts, Collections .reverseOrder((Post o1, Post o2) -> o1.getLocalDatePosted().compareTo(o2.getLocalDatePosted()))); return posts; }
From source file:org.pentaho.reporting.designer.core.editor.expressions.ExpressionPropertiesTableModel.java
protected void updateData(final Expression[] elements) throws IntrospectionException { this.elements = elements.clone(); this.editors = new BeanUtility[elements.length]; for (int i = 0; i < elements.length; i++) { this.editors[i] = new BeanUtility(elements[i]); }/*from w w w.j a v a 2 s .c o m*/ final ExpressionPropertyMetaData[] metaData = selectCommonAttributes(); if (tableStyle == TableStyle.ASCENDING) { Arrays.sort(metaData, new PlainMetaDataComparator()); this.groupings = new GroupingHeader[metaData.length]; this.metaData = metaData; } else if (tableStyle == TableStyle.DESCENDING) { Arrays.sort(metaData, Collections.reverseOrder(new PlainMetaDataComparator())); this.groupings = new GroupingHeader[metaData.length]; this.metaData = metaData; } else { Arrays.sort(metaData, new GroupedMetaDataComparator()); int groupCount = 0; final Locale locale = Locale.getDefault(); if (metaData.length > 0) { String oldValue = null; for (int i = 0; i < metaData.length; i++) { if (groupCount == 0) { groupCount = 1; final ExpressionPropertyMetaData firstdata = metaData[i]; oldValue = firstdata.getGrouping(locale); continue; } final ExpressionPropertyMetaData data = metaData[i]; final String grouping = data.getGrouping(locale); if ((ObjectUtilities.equal(oldValue, grouping)) == false) { oldValue = grouping; groupCount += 1; } } } final ExpressionPropertyMetaData[] groupedMetaData = new ExpressionPropertyMetaData[metaData.length + groupCount]; this.groupings = new GroupingHeader[groupedMetaData.length]; int targetIdx = 0; GroupingHeader group = null; for (int sourceIdx = 0; sourceIdx < metaData.length; sourceIdx++) { final ExpressionPropertyMetaData data = metaData[sourceIdx]; if (sourceIdx == 0) { group = new GroupingHeader(data.getGrouping(locale)); groupings[targetIdx] = group; targetIdx += 1; } else { final String newgroup = data.getGrouping(locale); if ((ObjectUtilities.equal(newgroup, group.getHeaderText())) == false) { group = new GroupingHeader(newgroup); groupings[targetIdx] = group; targetIdx += 1; } } groupings[targetIdx] = group; groupedMetaData[targetIdx] = data; targetIdx += 1; } this.metaData = groupedMetaData; } fireTableDataChanged(); }
From source file:org.opentestsystem.shared.security.service.AbsractRolesAndPermissionsService.java
private void setupEffectiveTenantsForRoles(final List<SbacRole> roleList) { final Map<String, SbacRole> roleNameMap = Maps.uniqueIndex( Iterables.filter(roleList, ROLE_APPLICABLE_TO_COMPONENT_FILTER), ROLE_NAME_MAP_TRANSFORMER); for (final Map.Entry<String, SbacRole> roleMapEntry : roleNameMap.entrySet()) { SbacRole role = roleMapEntry.getValue(); final List<Tenant> tenantsComponentRole = getApplicableTenants(Sets.newHashSet(role.getEntities())); // may not always be present due to tenancy roles if (tenantsComponentRole != null) { Collections.sort(tenantsComponentRole, Collections.reverseOrder(new Tenant.TenantTypeComparator())); for (Tenant tenant : tenantsComponentRole) { if (role.getEffectiveEntity().getEntityType().equals(tenant.getType()) && role.getEffectiveEntity().getEntityId().equals(tenant.getName())) { //first check to see if the effective entity (the one the role is assigned at) has a valid tenant) //if so, just use that one roleMapEntry.getValue().setEffectiveTenant(tenant); } else if (!TenantType.CLIENT.equals(tenant.getType())) { //otherwise 'walk the tenant tree' to see if there is a non-client tenant that matches the roles hierarchy. for (SbacEntity entity : role.getEntities()) { if (entity.getEntityId() != null && entity.getEntityId().equals(tenant.getName()) && entity.getEntityType().equals(tenant.getType())) { //build a new tenant (since one wasn't matched) with the roles effective tenant level, //but with the subscription details from the matched tenant higher in the hierarchy. Tenant newTenant = new Tenant(); newTenant.setTenantSubscriptions(tenant.getTenantSubscriptions()); newTenant.setId(role.getEffectiveEntity().getEntityId()); newTenant.setName(role.getEffectiveEntity().getEntityName()); newTenant.setType(role.getEffectiveEntity().getEntityType()); roleMapEntry.getValue().setEffectiveTenant(newTenant); }/*from ww w. j ava 2 s .c o m*/ } } } } } }
From source file:com.datumbox.framework.common.utilities.PHPMethods.java
private static <T extends Comparable<T>> Integer[] _asort(T[] array, boolean reverse) { //create an array with the indexes Integer[] indexes = new Integer[array.length]; for (int i = 0; i < array.length; ++i) { indexes[i] = i;//from w w w.jav a2 s. c o m } //sort the indexes first Comparator<Integer> c = (Integer index1, Integer index2) -> array[index1].compareTo(array[index2]); c = reverse ? Collections.reverseOrder(c) : c; Arrays.sort(indexes, c); //rearrenage the array based on the order of indexes arrangeByIndex(array, indexes); return indexes; }
From source file:org.openmrs.module.casereport.CaseReportUtil.java
/** * Gets the last visit made by the specified patient * * @param patient the patient to match against * @return the last visit for the specified patient * @should return the last visit for the specified patient */// w ww .j ava 2s. c om public static Visit getLastVisit(Patient patient) { final List<Visit> visits = Context.getVisitService().getVisitsByPatient(patient, true, false); Collections.sort(visits, Collections.reverseOrder(new Comparator<Visit>() { @Override public int compare(Visit v1, Visit v2) { return OpenmrsUtil.compare(v1.getStartDatetime(), v2.getStartDatetime()); } })); if (visits.isEmpty()) { return null; } return visits.get(0); }
From source file:org.kew.rmf.core.lucene.LuceneMatcher.java
public void sortMatches(List<Map<String, String>> matches) { final String sortOn = config.getSortFieldName(); try {/*from ww w.j av a 2 s . co m*/ Collections.sort(matches, Collections.reverseOrder(new Comparator<Map<String, String>>() { @Override public int compare(final Map<String, String> m1, final Map<String, String> m2) { return Integer.valueOf(m1.get(sortOn)).compareTo(Integer.valueOf(m2.get(sortOn))); } })); } catch (NumberFormatException e) { // if the String can't be converted to an integer we do String comparison Collections.sort(matches, Collections.reverseOrder(new Comparator<Map<String, String>>() { @Override public int compare(final Map<String, String> m1, final Map<String, String> m2) { return m1.get(sortOn).compareTo(m2.get(sortOn)); } })); } }
From source file:com.thesoftwareguild.capstoneblog.dao.BlogDaoDbImpl.java
@Override public List<Post> getAllPendingPosts() { // List<Post> posts = new ArrayList<>(); List<Post> posts = jdbcTemplate.query(SQL_SELECT_ALL_PENDING_POSTS, new PostMapper()); // Get associated categories for (Post p : posts) { setPostCategories(p);/* w ww . java2 s . co m*/ setPostTags(p); setPostComments(p); } Collections.sort(posts, Collections.reverseOrder((Post o1, Post o2) -> o1.getDateCreated().compareTo(o2.getDateCreated()))); return posts; }
From source file:at.ac.tuwien.qse.sepm.service.impl.TagServiceImpl.java
@Override public List<Tag> getMostFrequentTags(List<Photo> photos) throws ServiceException { LOGGER.debug("Entering getMostFrequentTags with {}", photos); HashMap<Tag, Integer> counter = new HashMap<>(); // count the frequency of each tag for (Photo photo : photos) { for (Tag tag : photo.getData().getTags()) { if (counter.containsKey(tag)) { counter.put(tag, counter.get(tag) + 1); } else { counter.put(tag, 1);//from w ww. ja v a 2s. co m } } } if (counter.size() == 0) { throw new ServiceException("No Tags found"); } // return the most frequent tags return counter.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(5) .map(Map.Entry::getKey).collect(Collectors.toList()); }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityIndividualApplication.java
public ApprovedLearningAgreementDocumentFile getMostRecentApprovedLearningAgreement() { if (!hasAnyActiveApprovedLearningAgreements()) { return null; }//from ww w . j a v a2 s .c om List<ApprovedLearningAgreementDocumentFile> approvedLearningAgreement = new ArrayList<ApprovedLearningAgreementDocumentFile>( getActiveApprovedLearningAgreements()); Collections.sort(approvedLearningAgreement, Collections.reverseOrder(ApprovedLearningAgreementDocumentFile.SUBMISSION_DATE_COMPARATOR)); return approvedLearningAgreement.iterator().next(); }
From source file:org.openengsb.opencit.ui.web.ProjectDetails.java
@SuppressWarnings("serial") private IModel<List<Report>> createReportsModel() { return new LoadableDetachableModel<List<Report>>() { @Override/*from w ww. ja va 2s . c o m*/ protected List<Report> load() { String projectId = ContextHolder.get().getCurrentContextId(); ReportDomain reportDomain; WiringService ws = osgiUtilsService.getService(WiringService.class); reportDomain = ws.getDomainEndpoint(ReportDomain.class, "report"); List<Report> reports = new ArrayList<Report>(reportDomain.getAllReports(projectId)); Comparator<Report> comparator = Collections.reverseOrder(new Comparator<Report>() { @Override public int compare(Report report1, Report report2) { String name1 = report1.getName(); String name2 = report2.getName(); try { SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss:SSS"); Date date1 = format.parse(name1); Date date2 = format.parse(name2); return date1.compareTo(date2); } catch (ParseException pe) { return name1.compareTo(name2); } } }); Collections.sort(reports, comparator); return reports; } }; }