Java Code Examples for java.util.Objects#compare()
The following examples show how to use
java.util.Objects#compare() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LessonBuilderStatImpl.java From sakai with Educational Community License v2.0 | 6 votes |
@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; }
Example 2
Source File: LocalDateRange.java From pgadba with BSD 2-Clause "Simplified" License | 6 votes |
@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); }
Example 3
Source File: OffsetDateTimeRange.java From pgadba with BSD 2-Clause "Simplified" License | 6 votes |
@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); }
Example 4
Source File: LocalDateTimeRange.java From pgadba with BSD 2-Clause "Simplified" License | 6 votes |
@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); }
Example 5
Source File: SortableTableModel.java From java-swing-tips with MIT License | 5 votes |
@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; }
Example 6
Source File: DetailId.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
@Override public int compareTo(@Nullable final DetailId o) { if (o == null) { return 1; } return Objects.compare(toJson(), o.toJson(), Comparator.naturalOrder()); }
Example 7
Source File: AddressComparator.java From IPAddress with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: SortableTableModel.java From java-swing-tips with MIT License | 5 votes |
@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; }
Example 9
Source File: TableSorter.java From java-swing-tips with MIT License | 5 votes |
@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; }
Example 10
Source File: ObjectsUtils.java From Learn-Java-12-Programming with MIT License | 5 votes |
@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()); }
Example 11
Source File: GITMergeUnit.java From MergeProcessor with Apache License 2.0 | 5 votes |
/** * {@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()); }
Example 12
Source File: NewUnsafeString.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 13
Source File: NewUnsafeString.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 14
Source File: NewUnsafeString.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 15
Source File: NewUnsafeString.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 16
Source File: TestBase.java From IPAddress with Apache License 2.0 | 4 votes |
@Override int compareOptions(IPAddressStringParameters otherOptions){ return Objects.compare(options, otherOptions, comparator); }
Example 17
Source File: NewUnsafeString.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 18
Source File: NewUnsafeString.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 19
Source File: NewUnsafeString.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 20
Source File: NewUnsafeString.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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"); } }