KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > misc > ObjectUtil


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.appserv.management.util.misc;
24
25 /**
26     Provides a variety of useful utilities for computing hashCode().
27  */

28  
29 public final class ObjectUtil
30 {
31         private
32     ObjectUtil( )
33     {
34         // disallow instantiation
35
}
36     
37     
38         public static int
39     hashCode( final boolean value )
40     {
41         return value ? 1 : 0;
42     }
43     
44         public static int
45     hashCode( final Object JavaDoc... items )
46     {
47         int result = 0;
48         
49         for( final Object JavaDoc item : items )
50         {
51             result ^= hashCode( item );
52         }
53         return result;
54     }
55     
56         public static int
57     hashCode( final Object JavaDoc o )
58     {
59         return o == null ? 0 : o.hashCode();
60     }
61     
62         public static int
63     hashCode( final long value )
64     {
65         return (int)value ^ (int)(value >> 32);
66     }
67     
68         public static int
69     hashCode( final double value )
70     {
71         return new Double JavaDoc( value ).hashCode();
72     }
73     
74         public static boolean
75     equals( final Object JavaDoc s1, final Object JavaDoc s2 )
76     {
77         boolean equals = false;
78         
79         if ( s1 == s2 )
80         {
81             equals = true;
82         }
83         else if ( s1 != null )
84         {
85             equals = s1.equals( s2 );
86         }
87         else
88         {
89             // s1 is null and s2 isn't
90
equals = false;
91         }
92         
93         return equals;
94     }
95 }
96
97
Popular Tags