• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * [The "BSD licence"]
3  * Copyright (c) 2005-2008 Terence Parr
4  * All rights reserved.
5  *
6  * Conversion to C#:
7  * Copyright (c) 2008 Sam Harwell, Pixel Mine, Inc.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 using System;
34 
35 namespace Antlr.Runtime.JavaExtensions
36 {
37     public static class ObjectExtensions
38     {
39 #if DEBUG
40         [Obsolete]
booleanValue( this bool value )41         public static bool booleanValue( this bool value )
42         {
43             return value;
44         }
45 
46         [Obsolete]
getClass( this object o )47         public static Type getClass( this object o )
48         {
49             return o.GetType();
50         }
51 #endif
52 
ShiftPrimeXOR( int a, int b )53         public static int ShiftPrimeXOR( int a, int b )
54         {
55             int hash = 23;
56             hash = ( ( hash << 5 ) * 37 ) ^ a;
57             hash = ( ( hash << 5 ) * 37 ) ^ b;
58             return hash;
59         }
60 
ShiftPrimeXOR( int a, int b, int c )61         public static int ShiftPrimeXOR( int a, int b, int c )
62         {
63             int hash = 23;
64             hash = ( ( hash << 5 ) * 37 ) ^ a;
65             hash = ( ( hash << 5 ) * 37 ) ^ b;
66             hash = ( ( hash << 5 ) * 37 ) ^ c;
67             return hash;
68         }
69 
ShiftPrimeXOR( int a, int b, int c, int d )70         public static int ShiftPrimeXOR( int a, int b, int c, int d )
71         {
72             int hash = 23;
73             hash = ( ( hash << 5 ) * 37 ) ^ a;
74             hash = ( ( hash << 5 ) * 37 ) ^ b;
75             hash = ( ( hash << 5 ) * 37 ) ^ c;
76             hash = ( ( hash << 5 ) * 37 ) ^ d;
77             return hash;
78         }
79 
ShiftPrimeXOR( params int[] a )80         public static int ShiftPrimeXOR( params int[] a )
81         {
82             int hash = 23;
83             foreach ( int i in a )
84                 hash = ( ( hash << 5 ) * 37 ) ^ i;
85             return hash;
86         }
87 
ShiftPrimeAdd( int a, int b )88         public static int ShiftPrimeAdd( int a, int b )
89         {
90             int hash = 23;
91             hash = ( ( hash << 5 ) * 37 ) + a;
92             hash = ( ( hash << 5 ) * 37 ) + b;
93             return hash;
94         }
95 
ShiftPrimeAdd( int a, int b, int c )96         public static int ShiftPrimeAdd( int a, int b, int c )
97         {
98             int hash = 23;
99             hash = ( ( hash << 5 ) * 37 ) + a;
100             hash = ( ( hash << 5 ) * 37 ) + b;
101             hash = ( ( hash << 5 ) * 37 ) + c;
102             return hash;
103         }
104 
ShiftPrimeAdd( int a, int b, int c, int d )105         public static int ShiftPrimeAdd( int a, int b, int c, int d )
106         {
107             int hash = 23;
108             hash = ( ( hash << 5 ) * 37 ) + a;
109             hash = ( ( hash << 5 ) * 37 ) + b;
110             hash = ( ( hash << 5 ) * 37 ) + c;
111             hash = ( ( hash << 5 ) * 37 ) + d;
112             return hash;
113         }
114 
ShiftPrimeAdd( params int[] a )115         public static int ShiftPrimeAdd( params int[] a )
116         {
117             int hash = 23;
118             foreach ( int i in a )
119                 hash = ( ( hash << 5 ) * 37 ) + i;
120             return hash;
121         }
122     }
123 }
124