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             return 0;
30         }
31         return obj.toHash >> 3;
32     }
33 
34     public static bool opEquals(Object a, Object b)
35     {
36 	if (a is null) {
37             return b is null;
38         }
39         return a is b;
40     }
41 
42     /**
43      * Creates the single instance of ObjectEqualityComparator.
44      */
45     private shared static this()
46     {
47         instance_ = new ObjectEqualityComparator;
48     }
49 
50     /**
51      * Returns: A single instance of ObjectEqualityComparator.
52      */
53     public static ObjectEqualityComparator instance()
54     {
55         return instance_;
56     }
57 
58 }