KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > collections > _AbstractOzoneMap_AbstractOzoneNode


1 /*
2  * _AbstractOzoneMap_AbstractOzoneNode.java
3  * $Id: _AbstractOzoneMap_AbstractOzoneNode.java,v 1.3 2003/11/05 11:50:06 leomekenkamp Exp $
4  * This file is based on AbstractMap.java from GNU Classpath. Quote:
5  
6 AbstractMap.java -- Abstract implementation of most of Map
7 Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
8  
9 This file is part of GNU Classpath.
10  
11 GNU Classpath is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
14 any later version.
15  
16 GNU Classpath is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
20  
21 You should have received a copy of the GNU General Public License
22 along with GNU Classpath; see the file COPYING. If not, write to the
23 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 02111-1307 USA.
25  
26 Linking this library statically or dynamically with other modules is
27 making a combined work based on this library. Thus, the terms and
28 conditions of the GNU General Public License cover the whole
29 combination.
30  
31 As a special exception, the copyright holders of this library give you
32 permission to link this library with independent modules to produce an
33 executable, regardless of the license terms of these independent
34 modules, and to copy and distribute the resulting executable under
35 terms of your choice, provided that you also meet, for each linked
36 independent module, the terms and conditions of the license of that
37 module. An independent module is a module which is not derived from
38 or based on this library. If you modify this library, you may extend
39 this exception to your version of the library, but you are not
40 obligated to do so. If you do not wish to do so, delete this
41 exception statement from your version.
42  
43  * end quote.
44  *
45  * This file is licenced under the same conditions as its original (GPL +
46  * "special exception").
47  */

48
49 package org.ozoneDB.collections;
50
51 import java.util.Map JavaDoc;
52 import org.ozoneDB.OzoneObject;
53
54 /**
55  *
56  * @author <a HREF="mailto:ozoneATmekenkampD0Tcom">Leo Mekenkamp (mind the anti-sp@m)</a>
57  */

58 public class _AbstractOzoneMap_AbstractOzoneNode extends OzoneObject implements _AbstractOzoneMap_OzoneNode {
59     
60     private static final long serialVersionUID = 1L;
61
62     private Object JavaDoc key;
63
64     private Object JavaDoc value;
65
66     /**
67      * Basic constructor initializes the fields.
68      * @param newKey the key
69      * @param newValue the value
70      */

71     public _AbstractOzoneMap_AbstractOzoneNode(Object JavaDoc newKey, Object JavaDoc newValue) {
72         key = newKey;
73         value = newValue;
74     }
75
76     /**
77      * Compares the specified object with this entry. Returns true only if
78      * the object is a mapping of identical key and value.
79      *
80      * @param o the object to compare
81      *
82      * @return <code>true</code> if it is equal
83      */

84     public final boolean equals(Object JavaDoc o) {
85         boolean result;
86         if (super.equals(o)) {
87             result = true;
88         } else if (! (o instanceof Map.Entry JavaDoc)) {
89             result = false;
90         // Optimize for our own entries.
91
} else if (o instanceof _AbstractOzoneMap_AbstractOzoneNode) {
92             _AbstractOzoneMap_AbstractOzoneNode e = (_AbstractOzoneMap_AbstractOzoneNode) o;
93             result = (AbstractOzoneMap.equals(key, e.key) && AbstractOzoneMap.equals(value, e.value));
94         } else {
95             Map.Entry JavaDoc e = (Map.Entry JavaDoc) o;
96             result = (AbstractOzoneMap.equals(key, e.getKey()) && AbstractOzoneMap.equals(value, e.getValue()));
97         }
98         return result;
99     }
100
101     /**
102      * Get the key corresponding to this entry.
103      *
104      * @return the key
105      */

106     public final Object JavaDoc getKey() {
107         return key;
108     }
109
110     /**
111      * Get the value corresponding to this entry. If you already called
112      * Iterator.remove(), the behavior undefined, but in this case it works.
113      *
114      * @return the value
115      */

116     public final Object JavaDoc getValue() {
117         return value;
118     }
119
120     /**
121      * Returns the hash code of the entry. This is defined as the exclusive-or
122      * of the hashcodes of the key and value (using 0 for null). In other
123      * words, this must be:
124      *
125 <pre>(getKey() == null ? 0 : getKey().hashCode())
126 ^ (getValue() == null ? 0 : getValue().hashCode())</pre>
127      *
128      * @return the hash code
129      */

130     public final int hashCode() {
131         return (AbstractOzoneMap.hashCode(key) ^ AbstractOzoneMap.hashCode(value));
132     }
133
134     /**
135      * Replaces the value with the specified object. This writes through
136      * to the map, unless you have already called Iterator.remove(). It
137      * may be overridden to restrict a null value.
138      *
139      * @param newVal the new value to store
140      * @return the old value
141      * @throws NullPointerException if the map forbids null values
142      */

143     public Object JavaDoc setValue(Object JavaDoc newVal) {
144         Object JavaDoc r = value;
145         value = newVal;
146         return r;
147     }
148
149     /**
150      * This provides a string representation of the entry. It is of the form
151      * "key=value", where string concatenation is used on key and value.
152      *
153      * @return the string representation
154      */

155     public final String JavaDoc toString() {
156         return key + "=" + value;
157     }
158
159     public void setKey(Object JavaDoc key) {
160         this.key = key;
161     }
162
163 }
164
165
Popular Tags