xiazcy commented on code in PR #3195:
URL: https://github.com/apache/tinkerpop/pull/3195#discussion_r2320495814


##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java:
##########
@@ -331,17 +307,74 @@ private static boolean naturallyComparable(final Object 
f, final Object s) {
     /**
      * Return true if the two objects are of the same comparison type 
(although they may not be the exact same Class)
      */
-    private static boolean comparable(final Object f, final Object s) {
+    public static boolean comparable(final Object f, final Object s) {
         if (f == null || s == null)
             return f == s; // true iff both in the null space
 
+        if (eitherAreNaN(f, s))
+            return false;
+
         final Type ft = Type.type(f);
         final Type st = Type.type(s);
 
+        // if objects are collections or composites, their contents must be 
mutually comparable
+        if (ft == Type.List && st == Type.List) {
+            return contentsComparable(((List) f).iterator(), ((List) 
s).iterator());
+        }
+        else if (ft == Type.Path && st == Type.Path) {
+            return contentsComparable(((Path) f).iterator(), ((Path) 
s).iterator());
+        }
+        else if (ft == Type.Set && st == Type.Set) {
+            final List l1 = new ArrayList((Set) f);
+            final List l2 = new ArrayList((Set) s);
+            Collections.sort(l1, ORDERABILITY);
+            Collections.sort(l2, ORDERABILITY);
+
+            return contentsComparable(l1.iterator(), l2.iterator());
+        }
+        else if (ft == Type.Map && st == Type.Map) {
+            final List l1 = new ArrayList(((Map) f).entrySet());
+            final List l2 = new ArrayList(((Map) s).entrySet());
+            Collections.sort(l1, ORDERABILITY);
+            Collections.sort(l2, ORDERABILITY);
+
+            return contentsComparable(l1.iterator(), l2.iterator());
+        }
+        else if (ft == Type.MapEntry && st == Type.MapEntry) {
+            return comparable(((Map.Entry) f).getKey(), ((Map.Entry) 
s).getKey()) &&
+                    comparable(((Map.Entry) f).getValue(), ((Map.Entry) 
s).getValue());
+        }
+        else if (ft == Type.MapEntry && st == Type.MapEntry) {
+            return comparable(((Map.Entry) f).getKey(), ((Map.Entry) 
s).getKey()) &&
+                    comparable(((Map.Entry) f).getValue(), ((Map.Entry) 
s).getValue());
+        }

Review Comment:
   ```suggestion
   ```
   Looks like a duplicated case of `MapEntry`. Or did you mean to compare a 
different type?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tinkerpop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to