You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/03/07 15:07:03 UTC
[isis] branch master updated: ISIS-2969: fixes NATURAL_NULL_FIRST comp.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new ecb6676 ISIS-2969: fixes NATURAL_NULL_FIRST comp.
ecb6676 is described below
commit ecb6676879f894da2da0dd3240e47ffecccd704d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Mar 7 16:04:42 2022 +0100
ISIS-2969: fixes NATURAL_NULL_FIRST comp.
---
.../isis/core/metamodel/spec/ManagedObjects.java | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/ManagedObjects.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/ManagedObjects.java
index 652698b..607d0ab 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/ManagedObjects.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/ManagedObjects.java
@@ -261,21 +261,23 @@ public final class ManagedObjects {
private static final Comparator<ManagedObject> NATURAL_NULL_FIRST = new Comparator<ManagedObject>(){
@SuppressWarnings({"rawtypes" })
@Override
- public int compare(final @Nullable ManagedObject p, final @Nullable ManagedObject q) {
- val pPojo = UnwrapUtil.single(p);
- val qPojo = UnwrapUtil.single(q);
- if(pPojo instanceof Comparable && qPojo instanceof Comparable) {
- return _Objects.compareNullsFirst((Comparable)pPojo, (Comparable)qPojo);
- }
- if(Objects.equals(pPojo, qPojo)) {
+ public int compare(final @Nullable ManagedObject a, final @Nullable ManagedObject b) {
+ val aPojo = UnwrapUtil.single(a);
+ val bPojo = UnwrapUtil.single(b);
+ if(Objects.equals(aPojo, bPojo)) {
return 0;
}
-
- final int hashCompare = Integer.compare(Objects.hashCode(pPojo), Objects.hashCode(qPojo));
+ if((aPojo==null
+ || aPojo instanceof Comparable)
+ && (bPojo==null
+ || bPojo instanceof Comparable)) {
+ return _Objects.compareNullsFirst((Comparable)aPojo, (Comparable)bPojo);
+ }
+ final int hashCompare = Integer.compare(Objects.hashCode(aPojo), Objects.hashCode(bPojo));
if(hashCompare!=0) {
return hashCompare;
}
- //XXX what to return on hash-collision?
+ //XXX on hash-collision we return an arbitrary non-equal relation (unspecified behavior)
return -1;
}