109 protected PreHashedMap(int rows, int size, int shift, int mask) {
110 this.rows = rows;
111 this.size = size;
112 this.shift = shift;
113 this.mask = mask;
114 this.ht = new Object[rows];
115 init(ht);
116 }
117
118 /**
119 * Initializes this map.
120 *
121 * <p> This method must construct the map's hash chains and store them into
122 * the appropriate elements of the given hash-table row array.
123 *
124 * @param rows
125 * The row array to be initialized
126 */
127 protected abstract void init(Object[] ht);
128
129 // @SuppressWarnings("unchecked")
130 private V toV(Object x) {
131 return (V)x;
132 }
133
134 public V get(Object k) {
135 int h = (k.hashCode() >> shift) & mask;
136 Object[] a = (Object[])ht[h];
137 if (a == null) return null;
138 for (;;) {
139 if (a[0].equals(k))
140 return toV(a[1]);
141 if (a.length < 3)
142 return null;
143 a = (Object[])a[2];
144 }
145 }
146
147 /**
148 * @throws UnsupportedOperationException
149 * If the given key is not part of this map's initial key set
242 return i.hasNext();
243 }
244
245 public Map.Entry<String,V> next() {
246 return new Map.Entry<String,V>() {
247 String k = i.next();
248 public String getKey() { return k; }
249 public V getValue() { return get(k); }
250 public int hashCode() {
251 V v = get(k);
252 return (k.hashCode()
253 + (v == null
254 ? 0
255 : v.hashCode()));
256 }
257 public boolean equals(Object ob) {
258 if (ob == this)
259 return true;
260 if (!(ob instanceof Map.Entry))
261 return false;
262 Map.Entry<String,V> that
263 = (Map.Entry<String,V>)ob;
264 return ((this.getKey() == null
265 ? that.getKey() == null
266 : this.getKey()
267 .equals(that.getKey()))
268 &&
269 (this.getValue() == null
270 ? that.getValue() == null
271 : this.getValue()
272 .equals(that.getValue())));
273 }
274 public V setValue(V v) {
275 throw new UnsupportedOperationException();
276 }
277 };
278 }
279
280 public void remove() {
281 throw new UnsupportedOperationException();
282 }
283
|
109 protected PreHashedMap(int rows, int size, int shift, int mask) {
110 this.rows = rows;
111 this.size = size;
112 this.shift = shift;
113 this.mask = mask;
114 this.ht = new Object[rows];
115 init(ht);
116 }
117
118 /**
119 * Initializes this map.
120 *
121 * <p> This method must construct the map's hash chains and store them into
122 * the appropriate elements of the given hash-table row array.
123 *
124 * @param rows
125 * The row array to be initialized
126 */
127 protected abstract void init(Object[] ht);
128
129 @SuppressWarnings("unchecked")
130 private V toV(Object x) {
131 return (V)x;
132 }
133
134 public V get(Object k) {
135 int h = (k.hashCode() >> shift) & mask;
136 Object[] a = (Object[])ht[h];
137 if (a == null) return null;
138 for (;;) {
139 if (a[0].equals(k))
140 return toV(a[1]);
141 if (a.length < 3)
142 return null;
143 a = (Object[])a[2];
144 }
145 }
146
147 /**
148 * @throws UnsupportedOperationException
149 * If the given key is not part of this map's initial key set
242 return i.hasNext();
243 }
244
245 public Map.Entry<String,V> next() {
246 return new Map.Entry<String,V>() {
247 String k = i.next();
248 public String getKey() { return k; }
249 public V getValue() { return get(k); }
250 public int hashCode() {
251 V v = get(k);
252 return (k.hashCode()
253 + (v == null
254 ? 0
255 : v.hashCode()));
256 }
257 public boolean equals(Object ob) {
258 if (ob == this)
259 return true;
260 if (!(ob instanceof Map.Entry))
261 return false;
262 Map.Entry<?,?> that = (Map.Entry<?,?>)ob;
263 return ((this.getKey() == null
264 ? that.getKey() == null
265 : this.getKey()
266 .equals(that.getKey()))
267 &&
268 (this.getValue() == null
269 ? that.getValue() == null
270 : this.getValue()
271 .equals(that.getValue())));
272 }
273 public V setValue(V v) {
274 throw new UnsupportedOperationException();
275 }
276 };
277 }
278
279 public void remove() {
280 throw new UnsupportedOperationException();
281 }
282
|