1 /* ObjectIdentityWrapper.java -- Wrapper class used to override equals()
2 and hashCode() to be as discriminating as possible
3 Copyright (C) 1998 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 As a special exception, if you link this library with other files to
23 produce an executable, this library does not by itself cause the
24 resulting executable to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why the
26 executable file might be covered by the GNU General Public License. */
32 This class is a thin wrapper around <code>Object</code> that makes
33 the methods <code>hashCode()</code> and <code>equals(Object)</code>
34 as discriminating as possible.
36 public class ObjectIdentityWrapper
40 Constructs a <code>ObjectIdentityWrapper</code> that is wrapped
43 public ObjectIdentityWrapper( Object o )
49 Uses <code>System.identityHashCode(Object)</code> to compute a
50 hash code for the object wrapped by this
51 <code>ObjectIdentityWrapper</code>.
53 @see java.lang.System#identityHashCode(java.lang.Object)
54 @see java.util.Hashtable
55 @see java.lang.Object#hashCode()
59 return System.identityHashCode( object );
63 Uses the <code>==</code> operator to test for equality between
64 the object wrapped by this <code>ObjectIdentityWrapper</code> and
65 the object wrapped by the <code>ObjectIdentityWrapper</code> o.
66 Returns false if o is not a <code>ObjectIdentityWrapper</code>.
68 @see java.util.Hashtable
69 @see java.lang.Object#equals()
71 public boolean equals( Object o )
73 if( o instanceof ObjectIdentityWrapper )
74 return object == ((ObjectIdentityWrapper)o).object;
79 public String toString()
81 return "ObjectIdentityWrapper< " + object + ", " + hashCode() + " >";
85 The <code>Object</code> wrapped by this
86 <code>ObjectIdentityWrapper</code>.