< prev index next >

src/java.base/share/classes/sun/misc/Cache.java

Print this page




 179      * @see Cache#elements
 180      * @see Enumeration
 181      */
 182     public synchronized Enumeration<Object> keys() {
 183         return new CacheEnumerator(table, true);
 184     }
 185 
 186     /**
 187      * Returns an enumeration of the elements. Use the Enumeration methods
 188      * on the returned object to fetch the elements sequentially.
 189      * @see Cache#keys
 190      * @see Enumeration
 191      */
 192     public synchronized Enumeration<Object> elements() {
 193         return new CacheEnumerator(table, false);
 194     }
 195 
 196     /**
 197      * Gets the object associated with the specified key in the Cache.
 198      * @param key the key in the hash table
 199      * @returns the element for the key or null if the key
 200      *          is not defined in the hash table.
 201      * @see Cache#put
 202      */
 203     public synchronized Object get(Object key) {
 204         CacheEntry tab[] = table;
 205         int hash = key.hashCode();
 206         int index = (hash & 0x7FFFFFFF) % tab.length;
 207         for (CacheEntry e = tab[index]; e != null; e = e.next) {
 208             if ((e.hash == hash) && e.key.equals(key)) {
 209                 return e.get();
 210             }
 211         }
 212         return null;
 213     }
 214 
 215     /**
 216      * Rehashes the contents of the table into a bigger table.
 217      * This is method is called automatically when the Cache's
 218      * size exceeds the threshold.
 219      */




 179      * @see Cache#elements
 180      * @see Enumeration
 181      */
 182     public synchronized Enumeration<Object> keys() {
 183         return new CacheEnumerator(table, true);
 184     }
 185 
 186     /**
 187      * Returns an enumeration of the elements. Use the Enumeration methods
 188      * on the returned object to fetch the elements sequentially.
 189      * @see Cache#keys
 190      * @see Enumeration
 191      */
 192     public synchronized Enumeration<Object> elements() {
 193         return new CacheEnumerator(table, false);
 194     }
 195 
 196     /**
 197      * Gets the object associated with the specified key in the Cache.
 198      * @param key the key in the hash table
 199      * @return the element for the key or null if the key
 200      *         is not defined in the hash table.
 201      * @see Cache#put
 202      */
 203     public synchronized Object get(Object key) {
 204         CacheEntry tab[] = table;
 205         int hash = key.hashCode();
 206         int index = (hash & 0x7FFFFFFF) % tab.length;
 207         for (CacheEntry e = tab[index]; e != null; e = e.next) {
 208             if ((e.hash == hash) && e.key.equals(key)) {
 209                 return e.get();
 210             }
 211         }
 212         return null;
 213     }
 214 
 215     /**
 216      * Rehashes the contents of the table into a bigger table.
 217      * This is method is called automatically when the Cache's
 218      * size exceeds the threshold.
 219      */


< prev index next >