Example usage for java.util Collections reverseOrder

List of usage examples for java.util Collections reverseOrder

Introduction

In this page you can find the example usage for java.util Collections reverseOrder.

Prototype

@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp) 

Source Link

Document

Returns a comparator that imposes the reverse ordering of the specified comparator.

Usage

From source file:org.wso2.carbon.andes.admin.AndesAdminService.java

/**
 * Gets all local temporary queue subscriptions
 * Suppressing 'MismatchedQueryAndUpdateOfCollection' as 'allSubscriptions' is used to convert
 * to an array./* www.j  av a 2 s .  com*/
 *
 * @return An array of {@link Subscription}.
 * @throws BrokerManagerAdminException
 */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
public Subscription[] getAllLocalTempQueueSubscriptions() throws BrokerManagerAdminException {
    List<Subscription> allSubscriptions = new ArrayList<Subscription>();
    Subscription[] subscriptionsDTO;
    try {
        SubscriptionManagerService subscriptionManagerService = AndesBrokerManagerAdminServiceDSHolder
                .getInstance().getSubscriptionManagerService();
        List<org.wso2.carbon.andes.core.types.Subscription> subscriptions = subscriptionManagerService
                .getAllLocalTempQueueSubscriptions();
        subscriptionsDTO = new Subscription[subscriptions.size()];
        for (org.wso2.carbon.andes.core.types.Subscription sub : subscriptions) {
            Subscription subscriptionDTO = new Subscription();
            subscriptionDTO.setSubscriptionIdentifier(sub.getSubscriptionIdentifier());
            subscriptionDTO.setSubscribedQueueOrTopicName(sub.getSubscribedQueueOrTopicName());
            subscriptionDTO.setSubscriberQueueBoundExchange(sub.getSubscriberQueueBoundExchange());
            subscriptionDTO.setSubscriberQueueName(sub.getSubscriberQueueName());
            subscriptionDTO.setDurable(sub.isDurable());
            subscriptionDTO.setActive(sub.isActive());
            subscriptionDTO
                    .setNumberOfMessagesRemainingForSubscriber(sub.getNumberOfMessagesRemainingForSubscriber());
            subscriptionDTO.setSubscriberNodeAddress(sub.getSubscriberNodeAddress());

            allSubscriptions.add(subscriptionDTO);
        }
        CustomSubscriptionComparator comparator = new CustomSubscriptionComparator();
        Collections.sort(allSubscriptions, Collections.reverseOrder(comparator));
        allSubscriptions.toArray(subscriptionsDTO);
    } catch (SubscriptionManagerException e) {
        String errorMessage = e.getMessage();
        log.error(errorMessage, e);
        throw new BrokerManagerAdminException(errorMessage, e);
    }
    return subscriptionsDTO;
}

From source file:mondrian.olap.fun.FunUtil.java

/**
 * Sorts a list of Tuples by the value of an applied expression. Stable
 * sort.//  ww  w  .  j a va2s . c o m
 *
 * <p>Helper function for MDX functions TopCount, TopSum, TopPercent,
 * BottomCount, BottomSum, BottomPercent, but not the MDX function Order.
 *
 * <p>NOTE: This function does not preserve the contents of the validator.
 *
 * <p>If you specify {@code tupleList}, the list is sorted in place, and
 * tupleList is returned.
 *
 * @param evaluator Evaluator
 * @param tupleIterable Iterator over tuples
 * @param tupleList List of tuples, if known, otherwise null
 * @param exp Expression to sort on
 * @param desc Whether to sort descending
 * @param brk Whether to break
 * @param arity Number of members in each tuple
 * @return sorted list (never null)
 */
public static TupleList sortTuples(Evaluator evaluator, TupleIterable tupleIterable, TupleList tupleList,
        Calc exp, boolean desc, boolean brk, int arity) {
    // NOTE: This method does not implement the iterable/list concept
    // as fully as sortMembers. This is because sortMembers evaluates all
    // sort expressions up front. There, it is efficient to unravel the
    // iterator and evaluate the sort expressions at the same time.
    List<List<Member>> tupleArrayList;
    if (tupleList == null) {
        tupleArrayList = new ArrayList<List<Member>>();
        final TupleCursor cursor = tupleIterable.tupleCursor();
        while (cursor.forward()) {
            tupleArrayList.add(cursor.current());
        }
        if (tupleArrayList.size() <= 1) {
            return new DelegatingTupleList(tupleIterable.getArity(), tupleArrayList);
        }
    } else {
        if (tupleList.size() <= 1) {
            return tupleList;
        }
        tupleArrayList = tupleList;
    }

    @SuppressWarnings({ "unchecked" })
    List<Member>[] tuples = tupleArrayList.toArray(new List[tupleArrayList.size()]);
    final DelegatingTupleList result = new DelegatingTupleList(tupleIterable.getArity(), Arrays.asList(tuples));

    Comparator<List<Member>> comparator;
    if (brk) {
        comparator = new BreakTupleComparator(evaluator, exp, arity);
        if (desc) {
            comparator = Collections.reverseOrder(comparator);
        }
    } else {
        comparator = new HierarchicalTupleComparator(evaluator, exp, arity, desc);
    }

    Arrays.sort(tuples, comparator);

    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("FunUtil.sortTuples returned:");
        for (List<Member> tuple : tuples) {
            sb.append("\n");
            sb.append(tuple.toString());
        }
        LOGGER.debug(sb.toString());
    }

    return result;
}

From source file:com.jaspersoft.jasperserver.api.engine.scheduling.hibernate.HibernateReportJobsPersistenceService.java

public List<ReportJobSummary> listJobs(final ExecutionContext context, final ReportJobModel reportJobCriteria,
        final int startIndex, final int numberOfRows, final ReportJobModel.ReportJobSortType sortType,
        final boolean isAscending) throws ReportJobRuntimeInfoException {
    // require report scheduling service to display/ sort by runtime information
    if (sortType != null) {
        switch (sortType) {
        case SORTBY_STATUS:
        case SORTBY_LASTRUN:
        case SORTBY_NEXTRUN:
            throw new ReportJobRuntimeInfoException(sortType);
        }//from   w  w  w  .  ja v  a2s. c  o m
    }
    return (List) executeCallback(new DaoCallback() {
        public Object execute() {
            List persistentJobs = getReportUnitJobs(reportJobCriteria, context);
            List<ReportJobSummary> jobs = toClientSummary(persistentJobs);
            // apply sorting
            Comparator<ReportJobSummary> comparator = getComparator(context, sortType);
            if (comparator != null) {
                if (!isAscending)
                    comparator = Collections.reverseOrder(comparator);
                Collections.sort(jobs, comparator);
            } else if (!isAscending) {
                Collections.reverse(jobs);
            }
            // apply pagination
            int beginningIndex = 0;
            if (startIndex > 0)
                beginningIndex = startIndex;
            if ((beginningIndex == 0) && (numberOfRows == -1))
                return jobs;
            List<ReportJobSummary> newList = new ArrayList<ReportJobSummary>();
            if (beginningIndex >= jobs.size())
                return newList;
            int showRowCount = numberOfRows;
            if ((numberOfRows < 0) || (numberOfRows > (jobs.size() - startIndex)))
                showRowCount = jobs.size() - beginningIndex;
            for (int i = beginningIndex; i < (showRowCount + beginningIndex); i++) {
                newList.add(jobs.get(i));
            }
            return newList;
        }
    });
}

From source file:org.wso2.carbon.andes.admin.AndesAdminService.java

/**
 * Gets all durable topic subscriptions/*from   w  ww .ja  v  a  2s  .  co m*/
 * Suppressing 'MismatchedQueryAndUpdateOfCollection' as 'allSubscriptions' is used to convert
 * to an array.
 *
 * @return An array of {@link Subscription}.
 * @throws BrokerManagerAdminException
 */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
public Subscription[] getAllDurableTopicSubscriptions() throws BrokerManagerAdminException {
    List<Subscription> allSubscriptions = new ArrayList<Subscription>();
    Subscription[] subscriptionsDTO;
    try {
        SubscriptionManagerService subscriptionManagerService = AndesBrokerManagerAdminServiceDSHolder
                .getInstance().getSubscriptionManagerService();
        List<org.wso2.carbon.andes.core.types.Subscription> subscriptions = subscriptionManagerService
                .getAllDurableTopicSubscriptions();
        subscriptionsDTO = new Subscription[subscriptions.size()];
        for (org.wso2.carbon.andes.core.types.Subscription sub : subscriptions) {
            Subscription subscriptionDTO = new Subscription();
            subscriptionDTO.setSubscriptionIdentifier(sub.getSubscriptionIdentifier());
            subscriptionDTO.setSubscribedQueueOrTopicName(sub.getSubscribedQueueOrTopicName());
            subscriptionDTO.setSubscriberQueueBoundExchange(sub.getSubscriberQueueBoundExchange());
            subscriptionDTO.setSubscriberQueueName(sub.getSubscriberQueueName());
            subscriptionDTO.setDurable(sub.isDurable());
            subscriptionDTO.setActive(sub.isActive());
            subscriptionDTO
                    .setNumberOfMessagesRemainingForSubscriber(sub.getNumberOfMessagesRemainingForSubscriber());
            subscriptionDTO.setSubscriberNodeAddress(sub.getSubscriberNodeAddress());
            subscriptionDTO.setDestination(sub.getDestination());

            allSubscriptions.add(subscriptionDTO);
        }
        CustomSubscriptionComparator comparator = new CustomSubscriptionComparator();
        Collections.sort(allSubscriptions, Collections.reverseOrder(comparator));
        allSubscriptions.toArray(subscriptionsDTO);
    } catch (SubscriptionManagerException e) {
        String errorMessage = e.getMessage();
        log.error(errorMessage, e);
        throw new BrokerManagerAdminException(errorMessage, e);
    }
    return subscriptionsDTO;
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

@SuppressWarnings("unchecked")
public void testDescendingKeySet_iterator() {
    NavigableMap<K, V> map = createNavigableMap();
    map.putAll(makeFullMap());/*w ww .  j  a va  2  s  .com*/
    resetFull();
    ArrayList<K> keys = new ArrayList<K>();
    for (Object key : getSampleKeys()) {
        keys.add((K) key);
    }

    // JDK < 7 does not handle null keys correctly.
    if (useNullKey() && TestUtils.isJvm() && TestUtils.getJdkVersion() < 7) {
        map.remove(null);
        keys.remove(null);
    }

    Comparator<? super K> cmp = ((TreeMap<K, V>) map).comparator();
    Collections.sort(keys, Collections.reverseOrder(cmp));
    Iterator<K> it = map.descendingKeySet().iterator();
    for (K key : keys) {
        assertTrue(it.hasNext());
        K rem = it.next();
        it.remove();
        assertEquals(key, rem);
    }
    try {
        it.next();
        fail("should throw NoSuchElementException");
    } catch (NoSuchElementException expected) {
    }
    _assertEmpty(map);
}

From source file:org.wso2.carbon.andes.admin.AndesAdminService.java

/**
 * Gets all local temporary topic subscriptions.
 * Suppressing 'MismatchedQueryAndUpdateOfCollection' as 'allSubscriptions' is used to convert
 * to an array./*from   ww  w  .  j a v a 2 s.  c  o  m*/
 *
 * @return An array of {@link Subscription}.
 * @throws BrokerManagerAdminException
 */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
public Subscription[] getAllLocalTempTopicSubscriptions() throws BrokerManagerAdminException {
    List<Subscription> allSubscriptions = new ArrayList<Subscription>();
    Subscription[] subscriptionsDTO;
    try {
        SubscriptionManagerService subscriptionManagerService = AndesBrokerManagerAdminServiceDSHolder
                .getInstance().getSubscriptionManagerService();
        List<org.wso2.carbon.andes.core.types.Subscription> subscriptions = subscriptionManagerService
                .getAllLocalTempTopicSubscriptions();
        subscriptionsDTO = new Subscription[subscriptions.size()];
        for (org.wso2.carbon.andes.core.types.Subscription sub : subscriptions) {
            Subscription subscriptionDTO = new Subscription();
            subscriptionDTO.setSubscriptionIdentifier(sub.getSubscriptionIdentifier());
            subscriptionDTO.setSubscribedQueueOrTopicName(sub.getSubscribedQueueOrTopicName());
            subscriptionDTO.setSubscriberQueueBoundExchange(sub.getSubscriberQueueBoundExchange());
            subscriptionDTO.setSubscriberQueueName(sub.getSubscriberQueueName());
            subscriptionDTO.setDurable(sub.isDurable());
            subscriptionDTO.setActive(sub.isActive());
            subscriptionDTO
                    .setNumberOfMessagesRemainingForSubscriber(sub.getNumberOfMessagesRemainingForSubscriber());
            subscriptionDTO.setSubscriberNodeAddress(sub.getSubscriberNodeAddress());
            subscriptionDTO.setDestination(sub.getDestination());

            allSubscriptions.add(subscriptionDTO);
        }
        CustomSubscriptionComparator comparator = new CustomSubscriptionComparator();
        Collections.sort(allSubscriptions, Collections.reverseOrder(comparator));
        allSubscriptions.toArray(subscriptionsDTO);
    } catch (SubscriptionManagerException e) {
        String errorMessage = e.getMessage();
        log.error(errorMessage, e);
        throw new BrokerManagerAdminException(errorMessage, e);
    }
    return subscriptionsDTO;
}

From source file:org.caleydo.core.data.collection.table.Table.java

private List<Integer> sampleMostVariableDimensions(int sampleSize, List<Integer> recordIDs,
        List<Integer> dimensionIDs) {

    if (dimensionIDs.size() <= sampleSize)
        return dimensionIDs;

    List<Pair<Double, Integer>> allDimVar = new ArrayList<Pair<Double, Integer>>();

    for (Integer dimID : dimensionIDs) {
        double[] allDimsPerRecordArray = new double[recordIDs.size()];

        for (int i = 0; i < recordIDs.size(); i++) {
            // allDimsPerRecordArray[i] = dataDomain.getNormalizedValue(dataDomain.getDimensionIDType(), dimID,
            // dataDomain.getRecordIDType(), recordIDs.get(i));
            allDimsPerRecordArray[i] = (Float) getRaw(dimID, recordIDs.get(i));
        }/*from   w w w .  j av a  2s . co m*/

        AdvancedDoubleStatistics stats = AdvancedDoubleStatistics.of(allDimsPerRecordArray);
        // throwing out all values with more than 80% NAN
        if (stats.getNaNs() < stats.getN() * NAN_THRESHOLD) {
            allDimVar.add(new Pair<Double, Integer>(stats.getMedianAbsoluteDeviation(), dimID));
        }
    }

    Collections.sort(allDimVar, Collections.reverseOrder(Pair.<Double>compareFirst()));

    allDimVar = allDimVar.subList(0, sampleSize);

    List<Integer> sampledDimensionIDs = new ArrayList<>();
    for (Pair<Double, Integer> recordVar : allDimVar) {
        sampledDimensionIDs.add(recordVar.getSecond());
    }
    return sampledDimensionIDs;
}

From source file:mondrian.olap.fun.FunUtil.java

/**
 * Partially sorts a list of Tuples by the value of an applied expression.
 *
 * <p>Avoids sorting the whole list, finds only the <i>n</i> top (or bottom)
 * valued Tuples, and returns them as a new List. Helper function for MDX
 * functions TopCount and BottomCount./*www . j a va 2 s .  c o  m*/
 *
 * <p>NOTE: Does not preserve the contents of the validator. The returned
 * list is immutable.
 *
 * @param evaluator Evaluator
 * @param list a list of tuples
 * @param exp a Calc applied to each tuple to find its sort-key
 * @param limit maximum count of tuples to return.
 * @param desc true to sort descending (and find TopCount),
 *  false to sort ascending (and find BottomCount).
 * @return the top or bottom tuples, as a new list.
 */
public static List<List<Member>> partiallySortTuples(Evaluator evaluator, TupleList list, Calc exp, int limit,
        boolean desc) {
    assert list.size() > 0;
    assert limit <= list.size();
    Comparator<List<Member>> comp = new BreakTupleComparator(evaluator, exp, list.getArity());
    if (desc) {
        comp = Collections.reverseOrder(comp);
    }
    return stablePartialSort(list, comp, limit);
}

From source file:edu.upenn.ircs.lignos.morsel.MorphLearner.java

/**
 * Sort transforms in-place according to the previously set sorting method.
 * Depends on the WEIGHTED_TRANSFORMS member for the sorting method.
 * @param transforms the transforms to be sorted
 *//*from ww w .  ja  v  a  2s.  com*/
public void sortTransforms(List<Transform> transforms) {
    if (WEIGHTED_TRANSFORMS) {
        Collections.sort(transforms, Collections.reverseOrder(new WeightedTypeCountComparator()));
    } else {
        Collections.sort(transforms, Collections.reverseOrder(new TypeCountComparator()));
    }
}

From source file:org.kuali.rice.krad.lookup.LookupableImpl.java

/**
 * Sorts the given list of search results based on the lookup view's configured sort attributes.
 *
 * <p>First if the posted view exists we grab the sort attributes from it. This will take into account expressions
 * that might have been configured on the sort attributes. If the posted view does not exist (because we did a
 * search from a get request or form session storage is off), we get the sort attributes from the view that we
 * will be rendered (and was initialized before controller call). However, expressions will not be evaluated yet,
 * thus if expressions were configured we don't know the results and can not sort the list</p>
 *
 * @param form lookup form instance containing view information
 * @param searchResults list of search results to sort
 * @TODO: revisit this when we have a solution for the posted view problem
 *//*w  ww.  ja v a  2  s  .com*/
protected void sortSearchResults(LookupForm form, List<?> searchResults) {
    List<String> defaultSortColumns = null;
    boolean defaultSortAscending = true;

    if (form.getView() != null) {
        defaultSortColumns = ((LookupView) form.getView()).getDefaultSortAttributeNames();
        defaultSortAscending = ((LookupView) form.getView()).isDefaultSortAscending();
    }

    boolean hasExpression = false;
    if (defaultSortColumns != null) {
        for (String sortColumn : defaultSortColumns) {
            if (sortColumn == null) {
                hasExpression = true;
            }
        }
    }

    if (hasExpression) {
        defaultSortColumns = null;
    }

    if ((defaultSortColumns != null) && (!defaultSortColumns.isEmpty())) {
        BeanPropertyComparator comparator = new BeanPropertyComparator(defaultSortColumns, true);
        if (defaultSortAscending) {
            Collections.sort(searchResults, comparator);
        } else {
            Collections.sort(searchResults, Collections.reverseOrder(comparator));
        }
    }
}