jdk/src/java.base/share/classes/sun/util/PreHashedMap.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 14342 jdk/src/share/classes/sun/util/PreHashedMap.java@8435a30053c1
child 29986 97167d851fc4
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13795
diff changeset
     2
 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.AbstractMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.AbstractSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A precomputed hash map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p> Subclasses of this class are of the following form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * class FooMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     extends sun.util.PreHashedMap&lt;String&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     private FooMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *         super(ROWS, SIZE, SHIFT, MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     protected void init(Object[] ht) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *         ht[0] = new Object[] { "key-1", value_1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *         ht[1] = new Object[] { "key-2", value_2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *                      new Object { "key-3", value_3 } };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *         ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * }</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p> The <tt>init</tt> method is invoked by the <tt>PreHashedMap</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * constructor with an object array long enough for the map's rows.  The method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * must construct the hash chain for each row and store it in the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * element of the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p> Each entry in the map is represented by a unique hash-chain node.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * final node of a hash chain is a two-element object array whose first element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * is the entry's key and whose second element is the entry's value.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * non-final node of a hash chain is a three-element object array whose first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * two elements are the entry's key and value and whose third element is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * next node in the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p> Instances of this class are mutable and are not safe for concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * access.  They may be made immutable and thread-safe via the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * methods in the {@link java.util.Collections} utility class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p> In the JDK build, subclasses of this class are typically created via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <tt>Hasher</tt> program in the <tt>make/tools/Hasher</tt> directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see java.util.AbstractMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public abstract class PreHashedMap<V>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    extends AbstractMap<String,V>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private final int rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private final int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private final int shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private final int mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private final Object[] ht;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Creates a new map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <p> This constructor invokes the {@link #init init} method, passing it a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * newly-constructed row array that is <tt>rows</tt> elements long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *        The number of rows in the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *        The number of entries in the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param shift
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *        The value by which hash codes are right-shifted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *        The value with which hash codes are masked after being shifted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected PreHashedMap(int rows, int size, int shift, int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.rows = rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.size = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.shift = shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.mask = mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.ht = new Object[rows];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        init(ht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Initializes this map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <p> This method must construct the map's hash chains and store them into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * the appropriate elements of the given hash-table row array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *        The row array to be initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected abstract void init(Object[] ht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 5506
diff changeset
   129
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private V toV(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return (V)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public V get(Object k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        int h = (k.hashCode() >> shift) & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Object[] a = (Object[])ht[h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (a == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (a[0].equals(k))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                return toV(a[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (a.length < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @throws UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *         If the given key is not part of this map's initial key set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public V put(String k, V v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        int h = (k.hashCode() >> shift) & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Object[] a = (Object[])ht[h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (a == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new UnsupportedOperationException(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (a[0].equals(k)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                V ov = toV(a[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                a[1] = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                return ov;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (a.length < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                throw new UnsupportedOperationException(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public Set<String> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return new AbstractSet<String> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            public Iterator<String> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                return new Iterator<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    private int i = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    Object[] a = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    String cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    private boolean findNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            if (a.length == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                cur = (String)a[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            a = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        if (i >= rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        if (i < 0 || ht[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                if (++i >= rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                            } while (ht[i] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        a = (Object[])ht[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        cur = (String)a[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        if (cur != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        return findNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    public String next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        if (cur == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            if (!findNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        String s = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Set<Map.Entry<String,V>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return new AbstractSet<Map.Entry<String,V>> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            public Iterator<Map.Entry<String,V>> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                return new Iterator<Map.Entry<String,V>>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    final Iterator<String> i = keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        return i.hasNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    public Map.Entry<String,V> next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        return new Map.Entry<String,V>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            String k = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            public String getKey() { return k; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            public V getValue() { return get(k); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                V v = get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                return (k.hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                        + (v == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                           ? 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                           : v.hashCode()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                            public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                if (ob == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                if (!(ob instanceof Map.Entry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                    return false;
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 5506
diff changeset
   262
                                Map.Entry<?,?> that = (Map.Entry<?,?>)ob;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                return ((this.getKey() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                         ? that.getKey() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                         : this.getKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                               .equals(that.getKey()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                        &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                        (this.getValue() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                         ? that.getValue() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                         : this.getValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                               .equals(that.getValue())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                            public V setValue(V v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}