src/java.base/share/classes/sun/util/PreHashedMap.java
author michaelm
Thu, 14 Nov 2019 15:01:49 +0000
branchunixdomainchannels
changeset 59082 5e250ee9259e
parent 47216 71c04702a3d5
permissions -rw-r--r--
unixdomainchannels: fix some sockaddr_un address handling
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
 *
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 31061
diff changeset
    59
 * <p> The {@code init} method is invoked by the {@code PreHashedMap}
2
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
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 31061
diff changeset
    76
 * {@code Hasher} program in the {@code make/tools/Hasher} directory.
2
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
32210
958d823579c3 8133480: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents: 31061
diff changeset
    98
     * newly-constructed row array that is {@code rows} elements long.
2
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
     *
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 29986
diff changeset
   124
     * @param ht The row array to be initialized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected abstract void init(Object[] ht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 5506
diff changeset
   128
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private V toV(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return (V)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public V get(Object k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int h = (k.hashCode() >> shift) & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        Object[] a = (Object[])ht[h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (a == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            if (a[0].equals(k))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                return toV(a[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (a.length < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
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
     * @throws UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         If the given key is not part of this map's initial key set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public V put(String k, V v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int h = (k.hashCode() >> shift) & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        Object[] a = (Object[])ht[h];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (a == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throw new UnsupportedOperationException(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (a[0].equals(k)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                V ov = toV(a[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                a[1] = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return ov;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (a.length < 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                throw new UnsupportedOperationException(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public Set<String> keySet() {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   168
        return new AbstractSet<> () {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            public Iterator<String> iterator() {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   175
                return new Iterator<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    private int i = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    Object[] a = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    String cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    private boolean findNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            if (a.length == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                a = (Object[])a[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                cur = (String)a[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                            a = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        if (i >= rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        if (i < 0 || ht[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                            do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                if (++i >= rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                            } while (ht[i] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        a = (Object[])ht[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        cur = (String)a[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        if (cur != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        return findNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    public String next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        if (cur == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            if (!findNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        String s = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        cur = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    }
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
    public Set<Map.Entry<String,V>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return new AbstractSet<Map.Entry<String,V>> () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            public Iterator<Map.Entry<String,V>> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                return new Iterator<Map.Entry<String,V>>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    final Iterator<String> i = keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        return i.hasNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    public Map.Entry<String,V> next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        return new Map.Entry<String,V>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            String k = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            public String getKey() { return k; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                            public V getValue() { return get(k); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                V v = get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                return (k.hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                        + (v == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                           ? 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                           : v.hashCode()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                            public boolean equals(Object ob) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                if (ob == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                if (!(ob instanceof Map.Entry))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                    return false;
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 5506
diff changeset
   261
                                Map.Entry<?,?> that = (Map.Entry<?,?>)ob;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                return ((this.getKey() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                         ? that.getKey() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                         : this.getKey()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                               .equals(that.getKey()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                        &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                        (this.getValue() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                         ? that.getValue() == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                         : this.getValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                               .equals(that.getValue())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            public V setValue(V v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            }
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
                    public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
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
}