Class EqualObjectGraphs
java.lang.Object
org.mozilla.javascript.EqualObjectGraphs
An object that implements deep equality test of objects, including their
reference graph topology, that is in addition to establishing by-value
equality of objects, it also establishes that their reachable object graphs
have identical shape. It is capable of custom-comparing a wide range of
various objects, including various Rhino Scriptables, Java arrays, Java
Lists, and to some degree Java Maps and Sets (sorted Maps are okay, as well
as Sets with elements that can be sorted using their Comparable
implementation, and Maps whose keysets work the same). The requirement for
sortable maps and sets is to ensure deterministic order of traversal, which
is necessary for establishing structural equality of object graphs.
An instance of this object is stateful in that it memoizes pairs of objects
that already compared equal, so reusing an instance for repeated equality
tests of potentially overlapping object graph is beneficial for performance
as long as all equality test invocations returns true. Reuse is not advised
after an equality test returned false since there is a heuristic in comparing
cyclic data structures that can memoize false equalities if two cyclic data
structures end up being unequal.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
equalGraphs
(Object o1, Object o2) private boolean
equalGraphsNoMemo
(Object o1, Object o2) private static boolean
private boolean
equalLists
(List<?> l1, List<?> l2) private boolean
private boolean
equalObjectArrays
(Object[] a1, Object[] a2) private boolean
equalScriptables
(Scriptable s1, Scriptable s2) private boolean
private static Object[]
getIds
(Scriptable s) private static Object[]
private static String
private static Object
getValue
(Scriptable s, Object id) sortedEntries
(Map m) private static Object[]
(package private) static <T> T
withThreadLocal
(Function<EqualObjectGraphs, T> action)
-
Field Details
-
instance
-
knownEquals
-
currentlyCompared
-
-
Constructor Details
-
EqualObjectGraphs
EqualObjectGraphs()
-
-
Method Details
-
withThreadLocal
-
equalGraphs
-
equalGraphsNoMemo
-
equalScriptables
-
equalObjectArrays
-
equalLists
-
equalMaps
-
sortedEntries
-
equalSets
-
sortedSet
-
equalInterpretedFunctions
-
getSortedIds
-
getSymbolName
-
getIds
-
getValue
-