下面列出了java.util.Objects#compare ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int compareTo(LessonBuilderStat other) {
int val = Objects.compare(siteId, other.getSiteId(), Comparator.nullsFirst(String::compareToIgnoreCase));
if (val != 0) return val;
val = Objects.compare(userId, other.getUserId(), Comparator.nullsFirst(String::compareToIgnoreCase));
if (val != 0) return val;
val = Objects.compare(pageRef, other.getPageRef(), Comparator.nullsFirst(String::compareToIgnoreCase));
if (val != 0) return val;
val = Objects.compare(pageAction, other.getPageAction(), Comparator.nullsFirst(String::compareToIgnoreCase));
if (val != 0) return val;
val = Objects.compare(pageTitle, other.getPageTitle(), Comparator.nullsFirst(String::compareToIgnoreCase));
if (val != 0) return val;
val = Long.signum(pageId - other.getPageId());
if (val != 0) return val;
val = Objects.compare(date, other.getDate(), Comparator.nullsFirst(Date::compareTo));
if (val != 0) return val;
val = Long.signum(count - other.getCount());
if (val != 0) return val;
val = Long.signum(id - other.getId());
return val;
}
@Override
public int compareTo(LocalDateRange lr) {
if (empty && lr.empty) {
return 0;
}
int c = Objects.compare(lr.lower, lower, LocalDate::compareTo);
if (c != 0) {
return c;
}
c = Objects.compare(lr.upper, upper, LocalDate::compareTo);
if (c != 0) {
return c;
}
c = Boolean.compare(lr.lowerInclusive, lowerInclusive);
if (c != 0) {
return c;
}
return Boolean.compare(lr.upperInclusive, upperInclusive);
}
@Override
public int compareTo(OffsetDateTimeRange lr) {
if (empty && lr.empty) {
return 0;
}
int c = Objects.compare(lr.lower, lower, OffsetDateTime::compareTo);
if (c != 0) {
return c;
}
c = Objects.compare(lr.upper, upper, OffsetDateTime::compareTo);
if (c != 0) {
return c;
}
c = Boolean.compare(lr.lowerInclusive, lowerInclusive);
if (c != 0) {
return c;
}
return Boolean.compare(lr.upperInclusive, upperInclusive);
}
@Override
public int compareTo(LocalDateTimeRange lr) {
if (empty && lr.empty) {
return 0;
}
int c = Objects.compare(lr.lower, lower, LocalDateTime::compareTo);
if (c != 0) {
return c;
}
c = Objects.compare(lr.upper, upper, LocalDateTime::compareTo);
if (c != 0) {
return c;
}
c = Boolean.compare(lr.lowerInclusive, lowerInclusive);
if (c != 0) {
return c;
}
return Boolean.compare(lr.upperInclusive, upperInclusive);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public int compareTo(IMergeUnit o) {
if (o == null) {
return 1;
}
final int dateCompare = Objects.compare(getDate(), o.getDate(), (Comparator<LocalDateTime>) DEFAULT_COMPARATOR);
if (dateCompare != 0) {
return dateCompare;
}
final int repoCompare = Objects.compare(getRepository(), o.getRepository(),
(Comparator<String>) DEFAULT_COMPARATOR);
if (repoCompare != 0) {
return repoCompare;
}
final int hostCompare = Objects.compare(getHost(), o.getHost(), (Comparator<String>) DEFAULT_COMPARATOR);
if (hostCompare != 0) {
return hostCompare;
}
final int revisionCompare = Objects.compare(getRevisionInfo(), o.getRevisionInfo(),
(Comparator<String>) DEFAULT_COMPARATOR);
if (revisionCompare != 0) {
return revisionCompare;
}
final int branchTargetCompare = Objects.compare(getBranchTarget(), o.getBranchTarget(),
(Comparator<String>) DEFAULT_COMPARATOR);
if (branchTargetCompare != 0) {
return branchTargetCompare;
}
return getClass().toString().compareTo(o.getClass().toString());
}
@SuppressWarnings("unchecked")
@Override public int compare(Object one, Object two) {
if (one instanceof List && two instanceof List) {
Comparable<Object> o1 = (Comparable<Object>) ((List<Object>) one).get(index);
Comparable<Object> o2 = (Comparable<Object>) ((List<Object>) two).get(index);
int c = Objects.compare(o1, o2, Comparator.nullsFirst(Comparator.<Comparable<Object>>naturalOrder()));
return c * (ascending ? 1 : -1);
}
return 0;
}
@Override
public int compareTo(Person p){
int result = Objects.compare(name, p.getName(),
Comparator.naturalOrder());
if (result != 0) {
return result;
}
return Objects.compare(age, p.getAge(),
Comparator.naturalOrder());
}
@Override public int compare(Row r1, Row r2) {
int row1 = r1.modelIndex;
int row2 = r2.modelIndex;
for (Directive directive: sortingColumns) {
int column = directive.column;
Object o1 = tableModel.getValueAt(row1, column);
Object o2 = tableModel.getValueAt(row2, column);
// int comparison;
// // Define null less than everything, except null.
// if (o1 == null && o2 == null) {
// comparison = 0;
// } else if (o1 == null) {
// comparison = -1;
// } else if (o2 == null) {
// comparison = 1;
// } else {
// @SuppressWarnings("unchecked")
// Comparator<Object> comparator = getComparator(column);
// comparison = comparator.compare(o1, o2);
// }
// if (comparison != 0) {
// return directive.direction == DESCENDING ? -comparison : comparison;
// }
@SuppressWarnings("unchecked")
Comparator<Object> comparator = getComparator(column);
int comparison = Objects.compare(o1, o2, Comparator.nullsFirst(comparator));
if (comparison != 0) {
return directive.direction == DESCENDING ? ~comparison + 1 : comparison;
}
}
return row1 - row2;
}
@SuppressWarnings("unchecked")
@Override public int compare(Object one, Object two) {
if (one instanceof List && two instanceof List) {
Comparable<Object> o1 = (Comparable<Object>) ((List<Object>) one).get(index);
Comparable<Object> o2 = (Comparable<Object>) ((List<Object>) two).get(index);
int c = Objects.compare(o1, o2, Comparator.nullsFirst(Comparator.<Comparable<Object>>naturalOrder()));
return c * (ascending ? 1 : -1);
}
return 0;
}
public int compare(Address one, Address two) {
if(one == two) {
return 0;
}
int result = compare(one.getSection(), two.getSection());
if(result == 0 && one instanceof IPv6Address) {
IPv6Address oneIPv6 = (IPv6Address) one;
IPv6Address twoIPv6 = (IPv6Address) two;
result = Objects.compare(oneIPv6.getZone(), twoIPv6.getZone(), Comparator.nullsFirst(String::compareTo));
}
return result;
}
@Override
public int compareTo(@Nullable final DetailId o)
{
if (o == null)
{
return 1;
}
return Objects.compare(toJson(), o.toJson(), Comparator.naturalOrder());
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
@Override
int compareOptions(IPAddressStringParameters otherOptions){
return Objects.compare(options, otherOptions, comparator);
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}
public static void testNewUnsafeString() {
String benchmark = "exemplar";
String constructorCopy = new String(benchmark);
char[] jlaChars = benchmark.toCharArray();
String jlaCopy = jla.newStringUnsafe(jlaChars);
if (benchmark == constructorCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(constructorCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, constructorCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (benchmark == jlaCopy) {
throw new Error("should be different instances");
}
if (!benchmark.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(benchmark, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
if (constructorCopy == jlaCopy) {
throw new Error("should be different instances");
}
if (!constructorCopy.equals(jlaCopy)) {
throw new Error("Copy not equal");
}
if (0 != Objects.compare(constructorCopy, jlaCopy, Comparator.naturalOrder())) {
throw new Error("Copy not equal");
}
// The following is extremely "evil". Never ever do this in non-test code.
jlaChars[0] = 'X';
if (!"Xxemplar".equals(jlaCopy)) {
throw new Error("jla.newStringUnsafe did not use provided string");
}
}