jdk/src/java.base/share/classes/sun/misc/SoftCache.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2014, 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.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.ref.ReferenceQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.AbstractMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.AbstractSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A memory-sensitive implementation of the <code>Map</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p> A <code>SoftCache</code> object uses {@link java.lang.ref.SoftReference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * soft references} to implement a memory-sensitive hash map.  If the garbage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * collector determines at a certain point in time that a value object in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>SoftCache</code> entry is no longer strongly reachable, then it may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * remove that entry in order to release the memory occupied by the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * object.  All <code>SoftCache</code> objects are guaranteed to be completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * cleared before the virtual machine will throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>OutOfMemoryError</code>.  Because of this automatic clearing feature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the behavior of this class is somewhat different from that of other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <code>Map</code> implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p> Both null values and the null key are supported.  This class has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * same performance characteristics as the <code>HashMap</code> class, and has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the same efficiency parameters of <em>initial capacity</em> and <em>load
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * factor</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p> Like most collection classes, this class is not synchronized.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * synchronized <code>SoftCache</code> may be constructed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>Collections.synchronizedMap</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p> In typical usage this class will be subclassed and the <code>fill</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * method will be overridden.  When the <code>get</code> method is invoked on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * key for which there is no mapping in the cache, it will in turn invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>fill</code> method on that key in an attempt to construct a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * corresponding value.  If the <code>fill</code> method returns such a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * then the cache will be updated and the new value will be returned.  Thus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * for example, a simple URL-content cache can be constructed as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *     public class URLCache extends SoftCache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *         protected Object fill(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *             return ((URL)key).getContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p> The behavior of the <code>SoftCache</code> class depends in part upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * the actions of the garbage collector, so several familiar (though not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * required) <code>Map</code> invariants do not hold for this class.  <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Because entries are removed from a <code>SoftCache</code> in response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * dynamic advice from the garbage collector, a <code>SoftCache</code> may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * behave as though an unknown thread is silently removing entries.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * particular, even if you synchronize on a <code>SoftCache</code> instance and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * invoke none of its mutator methods, it is possible for the <code>size</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * method to return smaller values over time, for the <code>isEmpty</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * method to return <code>false</code> and then <code>true</code>, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>containsKey</code> method to return <code>true</code> and later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <code>false</code> for a given key, for the <code>get</code> method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * return a value for a given key but later return <code>null</code>, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <code>put</code> method to return <code>null</code> and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <code>remove</code> method to return <code>false</code> for a key that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * previously appeared to be in the map, and for successive examinations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * key set, the value set, and the entry set to yield successively smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * numbers of elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @author      Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @since       1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see         java.util.HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see         java.lang.ref.SoftReference
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   102
 * @deprecated No direct replacement; {@link java.util.WeakHashMap}
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   103
 * addresses a related by different use-case.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   106
@Deprecated
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   107
public class SoftCache extends AbstractMap<Object, Object> implements Map<Object, Object> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* The basic idea of this implementation is to maintain an internal HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
       that maps keys to soft references whose referents are the keys' values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
       the various accessor methods dereference these soft references before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
       returning values.  Because we don't have access to the innards of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
       HashMap, each soft reference must contain the key that maps to it so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
       that the processQueue method can remove keys whose values have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
       discarded.  Thus the HashMap actually maps keys to instances of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
       ValueCell class, which is a simple extension of the SoftReference class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   120
    private static class ValueCell extends SoftReference<Object> {
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   121
        private static Object INVALID_KEY = new Object();
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   122
        private static int dropped = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        private Object key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   125
        private ValueCell(Object key, Object value, ReferenceQueue<Object> queue) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            super(value, queue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            this.key = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        private static ValueCell create(Object key, Object value,
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   131
                                        ReferenceQueue<Object> queue)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (value == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return new ValueCell(key, value, queue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        private static Object strip(Object val, boolean drop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            if (val == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            ValueCell vc = (ValueCell)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Object o = vc.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (drop) vc.drop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        private boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return (key != INVALID_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        private void drop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            super.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            key = INVALID_KEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            dropped++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* Hash table mapping keys to ValueCells */
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   159
    private Map<Object, Object> hash;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* Reference queue for cleared ValueCells */
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   162
    private ReferenceQueue<Object> queue = new ReferenceQueue<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* Process any ValueCells that have been cleared and enqueued by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
       garbage collector.  This method should be invoked once by each public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
       mutator in this class.  We don't invoke this method in public accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
       because that can lead to surprising ConcurrentModificationExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private void processQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        ValueCell vc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        while ((vc = (ValueCell)queue.poll()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (vc.isValid()) hash.remove(vc.key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            else ValueCell.dropped--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /* -- Constructors -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Construct a new, empty <code>SoftCache</code> with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * initial capacity and the given load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param  initialCapacity  The initial capacity of the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param  loadFactor       A number between 0.0 and 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @throws IllegalArgumentException  If the initial capacity is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *                                   or equal to zero, or if the load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *                                   factor is less than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public SoftCache(int initialCapacity, float loadFactor) {
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   194
        hash = new HashMap<>(initialCapacity, loadFactor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Construct a new, empty <code>SoftCache</code> with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * initial capacity and the default load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param  initialCapacity  The initial capacity of the cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @throws IllegalArgumentException  If the initial capacity is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *                                   or equal to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public SoftCache(int initialCapacity) {
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   207
        hash = new HashMap<>(initialCapacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Construct a new, empty <code>SoftCache</code> with the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * capacity and the default load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public SoftCache() {
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   215
        hash = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* -- Simple queries -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Return the number of key-value mappings in this cache.  The time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * required by this operation is linear in the size of the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return entrySet().size();
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
     * Return <code>true</code> if this cache contains no key-value mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return entrySet().isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Return <code>true</code> if this cache contains a mapping for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * specified key.  If there is no mapping for the key, this method will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * attempt to construct one by invoking the <code>fill</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param   key   The key whose presence in the cache is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public boolean containsKey(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return ValueCell.strip(hash.get(key), false) != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /* -- Lookup and modification operations -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Create a value object for the given <code>key</code>.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * invoked by the <code>get</code> method when there is no entry for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <code>key</code>.  If this method returns a non-<code>null</code> value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * then the cache will be updated to map <code>key</code> to that value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * and that value will be returned by the <code>get</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p> The default implementation of this method simply returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <code>null</code> for every <code>key</code> value.  A subclass may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * override this method to provide more useful behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param  key  The key for which a value is to be computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return      A value for <code>key</code>, or <code>null</code> if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *              could not be computed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see #get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    protected Object fill(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Return the value to which this cache maps the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>key</code>.  If the cache does not presently contain a value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * this key, then invoke the <code>fill</code> method in an attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * compute such a value.  If that method returns a non-<code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * value, then update the cache and return the new value.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * return <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p> Note that because this method may update the cache, it is considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * a mutator and may cause <code>ConcurrentModificationException</code>s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * be thrown if invoked while an iterator is in use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param  key  The key whose associated value, if any, is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see #fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        Object v = hash.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (v == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            v = fill(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                hash.put(key, ValueCell.create(key, v, queue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return ValueCell.strip(v, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Update this cache so that the given <code>key</code> maps to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <code>value</code>.  If the cache previously contained a mapping for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <code>key</code> then that mapping is replaced and the old value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @param  key    The key that is to be mapped to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *                <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param  value  The value to which the given <code>key</code> is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *                mapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return  The previous value to which this key was mapped, or
23006
7cb4567eb213 8023022: Some more typos in javadoc
igerasim
parents: 22123
diff changeset
   312
     *          <code>null</code> if there was no mapping for the key
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        ValueCell vc = ValueCell.create(key, value, queue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return ValueCell.strip(hash.put(key, vc), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Remove the mapping for the given <code>key</code> from this cache, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param  key  The key whose mapping is to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return  The value to which this key was mapped, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *          there was no mapping for the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public Object remove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return ValueCell.strip(hash.remove(key), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Remove all mappings from this cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        hash.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /* -- Views -- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private static boolean valEquals(Object o1, Object o2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return (o1 == null) ? (o2 == null) : o1.equals(o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /* Internal class for entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
       Because it uses SoftCache.this.queue, this class cannot be static.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   353
    private class Entry implements Map.Entry<Object, Object> {
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   354
        private Map.Entry<Object, Object> ent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        private Object value;   /* Strong reference to value, to prevent the GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                   from flushing the value while this Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                   exists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   359
        Entry(Map.Entry<Object, Object> ent, Object value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            this.ent = ent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        public Object getKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return ent.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public Object setValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            return ent.setValue(ValueCell.create(ent.getKey(), value, queue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   376
        @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (! (o instanceof Map.Entry)) return false;
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   379
            Map.Entry<Object, Object> e = (Map.Entry<Object, Object>)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            return (valEquals(ent.getKey(), e.getKey())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    && valEquals(value, e.getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            Object k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return ((((k = getKey()) == null) ? 0 : k.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    ^ ((value == null) ? 0 : value.hashCode()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /* Internal class for entry sets */
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   394
    private class EntrySet extends AbstractSet<Map.Entry<Object, Object>> {
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   395
        Set<Map.Entry<Object, Object>> hashEntries = hash.entrySet();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   397
        public Iterator<Map.Entry<Object, Object>> iterator() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   399
            return new Iterator<Map.Entry<Object, Object>>() {
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   400
                Iterator<Map.Entry<Object, Object>> hashIterator = hashEntries.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                Entry next = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    while (hashIterator.hasNext()) {
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   405
                        Map.Entry<Object, Object> ent = hashIterator.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        ValueCell vc = (ValueCell)ent.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        Object v = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                        if ((vc != null) && ((v = vc.get()) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                            /* Value has been flushed by GC */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        next = new Entry(ent, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   418
                public Map.Entry<Object, Object> next() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if ((next == null) && !hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    Entry e = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    next = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    hashIterator.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return !(iterator().hasNext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            int j = 0;
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   439
            for (Iterator<Map.Entry<Object, Object>> i = iterator(); i.hasNext(); i.next()) j++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        public boolean remove(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            processQueue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (o instanceof Entry) return hashEntries.remove(((Entry)o).ent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            else return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   452
    private Set<Map.Entry<Object, Object>> entrySet = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Return a <code>Set</code> view of the mappings in this cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
22123
fac5d9194929 8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
darcy
parents: 5506
diff changeset
   457
    public Set<Map.Entry<Object, Object>> entrySet() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (entrySet == null) entrySet = new EntrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return entrySet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}