1 module antlr.v4.runtime.misc.ObjectEqualityComparator;
2 
3 import antlr.v4.runtime.misc.AbstractEqualityComparator;
4 
5 /**
6  * This default implementation of {@link EqualityComparator} uses object equality
7  * for comparisons by calling {@link Object#hashCode} and {@link Object#equals}.
8  *
9  * @author Sam Harwell
10  */
11 class ObjectEqualityComparator : AbstractEqualityComparator!Object
12 {
13 
14     /**
15      * The single instance of ObjectEqualityComparator.
16      */
17     private static __gshared ObjectEqualityComparator instance_;
18 
19     /**
20      * <p>This implementation returns
21      * {@code obj.}{@link Object#hashCode hashCode()}.</p>
22      * @uml
23      * @safe
24      * @nothrow
25      */
26     public static size_t hashOf(Object obj) @safe nothrow
27     {
28         if (obj is null)
29         {
30             return 0;
31         }
32         return obj.toHash >> 3;
33     }
34 
35     public static bool opEquals(Object a, Object b)
36     {
37         if (a is null)
38         {
39             return b is null;
40         }
41         return a is b;
42     }
43 
44     /**
45      * Creates the single instance of ObjectEqualityComparator.
46      */
47     private shared static this()
48     {
49         instance_ = new ObjectEqualityComparator;
50     }
51 
52     /**
53      * Returns: A single instance of ObjectEqualityComparator.
54      */
55     public static ObjectEqualityComparator instance()
56     {
57         return instance_;
58     }
59 
60 }