java.util.Objects#compare ( )源码实例Demo

下面列出了java.util.Objects#compare ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sakai   文件: LessonBuilderStatImpl.java
@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;
}
 
源代码2 项目: pgadba   文件: LocalDateRange.java
@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);
}
 
源代码3 项目: pgadba   文件: OffsetDateTimeRange.java
@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);
}
 
源代码4 项目: pgadba   文件: LocalDateTimeRange.java
@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);
}
 
源代码5 项目: MergeProcessor   文件: GITMergeUnit.java
/**
 * {@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());
}
 
源代码6 项目: java-swing-tips   文件: SortableTableModel.java
@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;
}
 
源代码7 项目: Learn-Java-12-Programming   文件: ObjectsUtils.java
@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());
}
 
源代码8 项目: java-swing-tips   文件: TableSorter.java
@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;
}
 
源代码9 项目: java-swing-tips   文件: SortableTableModel.java
@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;
}
 
源代码10 项目: IPAddress   文件: AddressComparator.java
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;
}
 
源代码11 项目: metasfresh-webui-api-legacy   文件: DetailId.java
@Override
public int compareTo(@Nullable final DetailId o)
{
	if (o == null)
	{
		return 1;
	}

	return Objects.compare(toJson(), o.toJson(), Comparator.naturalOrder());
}
 
源代码12 项目: jdk8u60   文件: NewUnsafeString.java
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");
    }

}
 
源代码13 项目: IPAddress   文件: TestBase.java
@Override
int compareOptions(IPAddressStringParameters otherOptions){
	return Objects.compare(options, otherOptions, comparator);
}
 
源代码14 项目: openjdk-jdk8u   文件: NewUnsafeString.java
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");
    }

}
 
源代码15 项目: jdk8u_jdk   文件: NewUnsafeString.java
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");
    }

}
 
源代码16 项目: jdk8u-jdk   文件: NewUnsafeString.java
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");
    }

}
 
源代码17 项目: openjdk-jdk8u-backup   文件: NewUnsafeString.java
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");
    }

}
 
源代码18 项目: jdk8u-jdk   文件: NewUnsafeString.java
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");
    }

}
 
源代码19 项目: jdk8u-dev-jdk   文件: NewUnsafeString.java
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");
    }

}
 
源代码20 项目: openjdk-8-source   文件: NewUnsafeString.java
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");
    }

}