Package org.mozilla.javascript
Class EqualObjectGraphs
- java.lang.Object
-
- org.mozilla.javascript.EqualObjectGraphs
-
final class EqualObjectGraphs extends java.lang.Object
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 Modifier and Type Field Description private java.util.Map<java.lang.Object,java.lang.Object>
currentlyCompared
private static java.lang.ThreadLocal<EqualObjectGraphs>
instance
private java.util.Map<java.lang.Object,java.lang.Object>
knownEquals
-
Constructor Summary
Constructors Constructor Description EqualObjectGraphs()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) boolean
equalGraphs(java.lang.Object o1, java.lang.Object o2)
private boolean
equalGraphsNoMemo(java.lang.Object o1, java.lang.Object o2)
private static boolean
equalInterpretedFunctions(InterpretedFunction f1, InterpretedFunction f2)
private boolean
equalLists(java.util.List<?> l1, java.util.List<?> l2)
private boolean
equalMaps(java.util.Map<?,?> m1, java.util.Map<?,?> m2)
private boolean
equalObjectArrays(java.lang.Object[] a1, java.lang.Object[] a2)
private boolean
equalScriptables(Scriptable s1, Scriptable s2)
private boolean
equalSets(java.util.Set<?> s1, java.util.Set<?> s2)
private static java.lang.Object[]
getIds(Scriptable s)
private static java.lang.Object[]
getSortedIds(Scriptable s)
private static java.lang.String
getSymbolName(Symbol s)
private static java.lang.Object
getValue(Scriptable s, java.lang.Object id)
private static java.util.Iterator<java.util.Map.Entry>
sortedEntries(java.util.Map m)
private static java.lang.Object[]
sortedSet(java.util.Set<?> s)
(package private) static <T> T
withThreadLocal(java.util.function.Function<EqualObjectGraphs,T> action)
-
-
-
Field Detail
-
instance
private static final java.lang.ThreadLocal<EqualObjectGraphs> instance
-
knownEquals
private final java.util.Map<java.lang.Object,java.lang.Object> knownEquals
-
currentlyCompared
private final java.util.Map<java.lang.Object,java.lang.Object> currentlyCompared
-
-
Method Detail
-
withThreadLocal
static <T> T withThreadLocal(java.util.function.Function<EqualObjectGraphs,T> action)
-
equalGraphs
boolean equalGraphs(java.lang.Object o1, java.lang.Object o2)
-
equalGraphsNoMemo
private boolean equalGraphsNoMemo(java.lang.Object o1, java.lang.Object o2)
-
equalScriptables
private boolean equalScriptables(Scriptable s1, Scriptable s2)
-
equalObjectArrays
private boolean equalObjectArrays(java.lang.Object[] a1, java.lang.Object[] a2)
-
equalLists
private boolean equalLists(java.util.List<?> l1, java.util.List<?> l2)
-
equalMaps
private boolean equalMaps(java.util.Map<?,?> m1, java.util.Map<?,?> m2)
-
sortedEntries
private static java.util.Iterator<java.util.Map.Entry> sortedEntries(java.util.Map m)
-
equalSets
private boolean equalSets(java.util.Set<?> s1, java.util.Set<?> s2)
-
sortedSet
private static java.lang.Object[] sortedSet(java.util.Set<?> s)
-
equalInterpretedFunctions
private static boolean equalInterpretedFunctions(InterpretedFunction f1, InterpretedFunction f2)
-
getSortedIds
private static java.lang.Object[] getSortedIds(Scriptable s)
-
getSymbolName
private static java.lang.String getSymbolName(Symbol s)
-
getIds
private static java.lang.Object[] getIds(Scriptable s)
-
getValue
private static java.lang.Object getValue(Scriptable s, java.lang.Object id)
-
-