Example usage for java.util Comparator getClass

List of usage examples for java.util Comparator getClass

Introduction

In this page you can find the example usage for java.util Comparator getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.kuali.rice.kns.lookup.LookupUtils.java

/**
 * Given a list of results from a lookup, determines the best comparator to use on the String values of each of these columns
 *
 * This method exists because each cell (represented by the Column object) lists the comparator that should be used within it based on the property value class,
 * so we gotta go thru the whole list and determine the best comparator to use
 *
 * @param resultsTable// w ww . ja  va2 s.  com
 * @param column
 * @return
 */
public static Comparator findBestValueComparatorForColumn(List<ResultRow> resultTable, int column) {
    // BIG HACK
    Comparator comp = NullValueComparator.getInstance();
    for (ResultRow row : resultTable) {
        Comparator tempComp = row.getColumns().get(column).getValueComparator();
        if (tempComp != null && !NullValueComparator.class.equals(tempComp.getClass())) {
            return tempComp;
        }
    }
    return comp;
}

From source file:org.openanzo.glitter.query.SPARQLAlgebra.java

private static Comparator<Value> getComparator(SolutionSet set1, SolutionSet set2) {

    Comparator<Value> comparator = CustomCompareSolutionSet.LEXICAL_COMPARATOR;
    if (set1 instanceof CustomCompareSolutionSet && set2 instanceof CustomCompareSolutionSet
            && ((CustomCompareSolutionSet) set1).getComparator()
                    .equals(((CustomCompareSolutionSet) set2).getComparator())) {
        comparator = ((CustomCompareSolutionSet) set1).getComparator();
    }/* ww w  .j a v a 2  s  . c  o m*/
    log.debug(LogUtils.GLITTER_MARKER, "using comparator: {}", comparator.getClass());
    return comparator;
}

From source file:org.sakaiproject.tool.gradebook.ui.OverviewBean.java

@SuppressWarnings("unchecked")
private void ensureAssignmentsSorted(List assignments, Comparator comparator, boolean save) {
    if (logger.isDebugEnabled()) {
        logger.debug("ensureAssignmentsSorted: comparator=" + comparator + ", save=" + save + ", assignments= "
                + Arrays.toString(assignments.toArray()));
    }//w  w  w.j  av a2  s . c  o m
    // remove any non-assignments first
    List gradeables = new ArrayList();
    for (Iterator iterator = assignments.iterator(); iterator.hasNext();) {
        GradableObject go = (GradableObject) iterator.next();
        if (!(go instanceof Assignment)) { // ! go.isAssignment()) {
            gradeables.add(go);
            iterator.remove();
        }
    }
    Collections.sort(gradeables, GradableObject.nameComparator);

    // put everything in the established sort order first (if needed)
    if (comparator == null) {
        comparator = GradableObject.dateComparator;
        if (logger.isDebugEnabled()) {
            logger.debug("ensureAssignmentsSorted: setting default comparator=" + comparator);
        }
    }
    if (!NoChangeMarkerComparator.class.isAssignableFrom(comparator.getClass())) {
        // only sort if this is not the no-sort marker
        if (logger.isDebugEnabled()) {
            logger.debug("ensureAssignmentsSorted: sorting with comparator=" + comparator);
        }
        Collections.sort(assignments, comparator);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("ensureAssignmentsSorted: no sort, using NoChangeMarkerComparator=" + comparator);
        }
    }
    // always need to sort by category
    Collections.sort(assignments, GradableObject.categoryComparator);
    // now ensure the numbering is set and correct
    int saveCount = 0;
    int updateCount = 0;
    for (int i = 0; i < assignments.size(); i++) {
        Assignment assignment = (Assignment) assignments.get(i);
        Integer curOrder = assignment.getSortOrder();
        if (logger.isDebugEnabled()) {
            logger.debug("ensureAssignmentsSorted: checking if current order (" + curOrder
                    + ") matches correct order (" + i + ") for assignment: " + assignment);
        }
        if (curOrder == null || i != curOrder.intValue()) {
            // no match so we need to update it (else it is already set correctly, only save if needed)
            assignment.setSortOrder(i);
            updateCount++;
            if (logger.isDebugEnabled()) {
                logger.debug("ensureAssignmentsSorted: setting sort order (" + i + ") for assignment: "
                        + assignment);
            }
            if (save) {
                getGradebookManager().updateAssignment(assignment);
                saveCount++;
                if (logger.isDebugEnabled()) {
                    logger.debug("ensureAssignmentsSorted: saving assignment: " + assignment);
                }
            }
        }
    }

    // set the ordering up in the assignment with support for categories
    Map<String, List<Assignment>> categoryAssignments = new LinkedHashMap<String, List<Assignment>>();
    for (Assignment assignment : (List<Assignment>) assignments) {
        String category = "NULL";
        if (assignment.getCategory() != null) {
            category = assignment.getCategory().getName();
        }
        if (!categoryAssignments.containsKey(category)) {
            categoryAssignments.put(category, new ArrayList<Assignment>());
        }
        categoryAssignments.get(category).add(assignment);
        //assignment.assignSorting(assignments.size(), i);
    }
    for (Entry<String, List<Assignment>> entry : categoryAssignments.entrySet()) {
        List<Assignment> l = entry.getValue();
        for (int i = 0; i < l.size(); i++) {
            Assignment assignment = l.get(i);
            // assign the counter for ordering
            assignment.assignSorting(l.size(), i);
            if (logger.isDebugEnabled()) {
                logger.debug("ensureAssignmentsSorted: ordered: " + i + " : " + assignment);
            }
        }
    }
    // add back in the gradeables to the end
    for (Object gradeable : gradeables) {
        assignments.add(gradeable);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("ensureAssignmentsSorted: sorted assignments (updated=" + updateCount + ", saved="
                + saveCount + "): " + Arrays.toString(assignments.toArray()));
    }
}