OSDN Git Service

Jumbo patch:
[pf3gnuchains/gcc-fork.git] / libjava / gnu / java / io / ObjectIdentityWrapper.java
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.
4
5 This file is part of GNU Classpath.
6
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)
10 any later version.
11  
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.
16
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
20 02111-1307 USA.
21
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. */
27
28
29 package gnu.java.io;
30
31 /**
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.
35 */
36 public class ObjectIdentityWrapper
37 {
38
39   /**
40      Constructs a <code>ObjectIdentityWrapper</code> that is wrapped
41      around o.
42   */
43   public ObjectIdentityWrapper( Object o )
44   {
45     object = o;
46   }
47
48   /**
49      Uses <code>System.identityHashCode(Object)</code> to compute a
50      hash code for the object wrapped by this
51      <code>ObjectIdentityWrapper</code>.
52
53      @see java.lang.System#identityHashCode(java.lang.Object)
54      @see java.util.Hashtable
55      @see java.lang.Object#hashCode()
56   */
57   public int hashCode()
58   {
59     return System.identityHashCode( object );
60   }
61
62   /**
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>.
67
68      @see java.util.Hashtable
69      @see java.lang.Object#equals()
70   */
71   public boolean equals( Object o )
72   {
73     if( o instanceof ObjectIdentityWrapper )
74       return object == ((ObjectIdentityWrapper)o).object;
75     else
76       return false;
77   }
78
79   public String toString()
80   {
81     return "ObjectIdentityWrapper< " + object + ", " + hashCode() + " >";
82   }
83
84   /**
85      The <code>Object</code> wrapped by this
86      <code>ObjectIdentityWrapper</code>.
87   */
88   public Object object;
89 }