Java 类org.springframework.util.comparator.NullSafeComparator 实例源码

项目:spring-rich-client    文件:ValidationMessageComparator.java   
public int compare(Object o1, Object o2) {
    ValidationMessage m1 = (ValidationMessage) o1;
    ValidationMessage m2 = (ValidationMessage) o2;
    int c;
    if (m1.getTimestamp() == m2.getTimestamp()) {
        c = NullSafeComparator.NULLS_HIGH.compare(m1.getProperty(), m2.getProperty());
        if (c == 0) {
            c = m1.getSeverity().compareTo(m2.getSeverity());
            if (c == 0) {
                c = m1.getMessage().compareTo(m2.getMessage());
            }
        }
    }
    else {
        c = (m1.getTimestamp() > m2.getTimestamp()) ? -1 : 1;
    }
    return c;
}
项目:spring-richclient    文件:ValidationMessageComparator.java   
public int compare(Object o1, Object o2) {
    ValidationMessage m1 = (ValidationMessage) o1;
    ValidationMessage m2 = (ValidationMessage) o2;
    int c;
    if (m1.getTimestamp() == m2.getTimestamp()) {
        c = NullSafeComparator.NULLS_HIGH.compare(m1.getProperty(), m2.getProperty());
        if (c == 0) {
            c = m1.getSeverity().compareTo(m2.getSeverity());
            if (c == 0) {
                c = m1.getMessage().compareTo(m2.getMessage());
            }
        }
    }
    else {
        c = (m1.getTimestamp() > m2.getTimestamp()) ? -1 : 1;
    }
    return c;
}
项目:powop    文件:ReferenceComparator.java   
public ReferenceComparator() {
    Comparator<String> stringComparator = new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }

    };
    nullSafeStringComparator = new NullSafeComparator<>(stringComparator, false);
}
项目:eHMP    文件:JsonVistaAccountDao.java   
@Override
public List<VistaAccount> findAll(final Sort sort) {
    List<VistaAccount> accounts = getVistaAccounts();
    if (sort == null) return Collections.unmodifiableList(accounts);

    Collections.sort(accounts, new Comparator<VistaAccount>() {

        private Comparator nullSafeComparableComparator = new NullSafeComparator(new ComparableComparator(), false);

        @Override
        public int compare(VistaAccount a1, VistaAccount a2) {
            BeanWrapper b1 = new BeanWrapperImpl(a1);
            BeanWrapper b2 = new BeanWrapperImpl(a2);

            for (Sort.Order order : sort) {
                Object val1 = b1.getPropertyValue(order.getProperty());
                Object val2 = b2.getPropertyValue(order.getProperty());

                int val = nullSafeComparableComparator.compare(val1, val2);
                if (val != 0) return val;
            }

            return 0;
        }
    });
    return Collections.unmodifiableList(accounts);
}
项目:spring-rich-client    文件:ComparisonBinaryPredicate.java   
/**
 * Creates a comparing binary predicate which compares using the provided
 * <code>Comparator</code>.
 *
 * @param comparator
 *            the comparator, may be null
 */
protected ComparisonBinaryPredicate(Comparator comparator) {
    if (!(comparator instanceof NullSafeComparator)) {
        this.comparator = new NullSafeComparator(comparator, true);
    }
    else {
        this.comparator = comparator;
    }
}
项目:screensaver    文件:WellSearchResultsTest.java   
@SuppressWarnings("unchecked")
private <R> void doTestSort(DataTableModel<R> dataModel,
                            TableColumn<R,?> sortColumn,
                            SortDirection sortDirection,
                            int expectedSize)
{
  log.info("testing sort on " + sortColumn + " in " + sortDirection);
  dataModel.sort(Arrays.asList(sortColumn), sortDirection);
  assertEquals("row count after sort", expectedSize, dataModel.getRowCount()); // ensure nothing funky occurring on query when sorting on entity types that are related to table's root entity (i.e. cross-product query results)
  List<Comparable> actualSortedValues = new ArrayList<Comparable>();
  List<Comparable> expectedSortedValues = new ArrayList<Comparable>();
  for (int i = 0; i < expectedSize; i++) {
    dataModel.setRowIndex(i);
    R rowData = (R) dataModel.getRowData();
    assertNotNull("row data not null for row " + i + ", column " + sortColumn,
                  rowData);
    Object o = sortColumn.getCellValue(rowData);
    if(o != null && (o instanceof Set)) {  // Hack to handle TextSetColumns -sde4
      actualSortedValues.add(Joiner.on(',').join((Set)o));
    }else {
      actualSortedValues.add((Comparable) o);
    }
  }
  expectedSortedValues.addAll(actualSortedValues);
  Collections.sort(expectedSortedValues, NullSafeComparator.NULLS_LOW);
  if (sortDirection == SortDirection.DESCENDING) {
    Collections.reverse(expectedSortedValues);
  }
  assertEquals("sorted values on " + sortColumn.getName() + ", " + sortDirection,
               expectedSortedValues,
               actualSortedValues);
}
项目:spring-richclient    文件:ComparisonBinaryPredicate.java   
/**
 * Creates a comparing binary predicate which compares using the provided
 * <code>Comparator</code>.
 *
 * @param comparator
 *            the comparator, may be null
 */
protected ComparisonBinaryPredicate(Comparator comparator) {
    if (!(comparator instanceof NullSafeComparator)) {
        this.comparator = new NullSafeComparator(comparator, true);
    }
    else {
        this.comparator = comparator;
    }
}
项目:perecoder    文件:Comparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Identifying o1, Identifying o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getId(), o2.getId());
}
项目:perecoder    文件:Comparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(MetaField o1, MetaField o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getOrdinal(), o2.getOrdinal());
}
项目:perecoder    文件:Comparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Field o1, Field o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getValue(), o2.getValue());
}
项目:perecoder    文件:NotificationComparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Notification o1, Notification o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getType(), o2.getType());
}
项目:perecoder    文件:NotificationComparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Notification o1, Notification o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getFromGroupName(), o2.getFromGroupName());
}
项目:perecoder    文件:NotificationComparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Notification o1, Notification o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getFromDictionaryName(), o2.getFromDictionaryName());
}
项目:perecoder    文件:NotificationComparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Notification o1, Notification o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getToGroupName(), o2.getToGroupName());
}
项目:perecoder    文件:NotificationComparators.java   
@Override
@SuppressWarnings("unchecked")
public int compare(Notification o1, Notification o2) {
    return NullSafeComparator.NULLS_LOW.compare(o1.getToDictionaryName(), o2.getToDictionaryName());
}
项目:class-guard    文件:LabeledEnum.java   
public int compare(Object o1, Object o2) {
    LabeledEnum e1 = (LabeledEnum) o1;
    LabeledEnum e2 = (LabeledEnum) o2;
    Comparator comp = new NullSafeComparator(String.CASE_INSENSITIVE_ORDER, true);
    return comp.compare(e1.getLabel(), e2.getLabel());
}
项目:spring-osgi    文件:LabeledEnum.java   
public int compare(Object o1, Object o2) {
    LabeledEnum e1 = (LabeledEnum) o1;
    LabeledEnum e2 = (LabeledEnum) o2;
    Comparator comp = new NullSafeComparator(String.CASE_INSENSITIVE_ORDER, true);
    return comp.compare(e1.getLabel(), e2.getLabel());
}