[ https://issues.apache.org/jira/browse/TINKERPOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18018008#comment-18018008 ]
ASF GitHub Bot commented on TINKERPOP-3173: ------------------------------------------- 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? > Simplify Comparability Semantics > -------------------------------- > > Key: TINKERPOP-3173 > URL: https://issues.apache.org/jira/browse/TINKERPOP-3173 > Project: TinkerPop > Issue Type: Improvement > Components: process > Affects Versions: 3.7.3 > Reporter: Cole Greer > Priority: Major > > As recently discussed on the > [devlist|https://lists.apache.org/thread/hsqw2tvc72dw4z40nnbbdmygrqx43syr], > our current system of ternary boolean logic should be simplified to binary > boolean logic where invalid comparisons simply return false. -- This message was sent by Atlassian Jira (v8.20.10#820010)