KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fri > util > Equals


1 package fri.util;
2
3 /**
4  * Object utility. Equality and hash code for objects that may be null.
5     
6   @author Ritzberger Fritz
7 */

8
9 public abstract class Equals
10 {
11     /**
12      * Returns false if objects are not equal or one of them is null and the other not.
13      */

14     public static boolean equals(Object JavaDoc o1, Object JavaDoc o2) {
15         return o1 == o2 ? true : o1 == null || o2 == null ? false : o1.equals(o2);
16     } // null == null is true in Java
17

18     /**
19      * Returns zero for a null object, else the objects hash code.
20      */

21     public static int hashCode(Object JavaDoc o) {
22         return o == null ? 0 : o.hashCode();
23     }
24
25     private Equals() {}
26     
27 }
Popular Tags