8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}

Reviewed-by: mduigou, lancea
This commit is contained in:
Joe Darcy 2014-01-07 19:19:32 -08:00
parent 62d1965059
commit c3404f0380
2 changed files with 35 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -73,9 +73,11 @@ class CacheEntry extends Ref {
* @see java.lang.Object#hashCode * @see java.lang.Object#hashCode
* @see java.lang.Object#equals * @see java.lang.Object#equals
* @see sun.misc.Ref * @see sun.misc.Ref
* @deprecated Consider {@link java.util.LinkedHashMap} for LRU caches.
*/ */
@Deprecated
public public
class Cache extends Dictionary { class Cache extends Dictionary<Object, Object> {
/** /**
* The hash table data. * The hash table data.
*/ */
@ -163,7 +165,7 @@ class Cache extends Dictionary {
* @see Cache#elements * @see Cache#elements
* @see Enumeration * @see Enumeration
*/ */
public synchronized Enumeration keys() { public synchronized Enumeration<Object> keys() {
return new CacheEnumerator(table, true); return new CacheEnumerator(table, true);
} }
@ -173,7 +175,7 @@ class Cache extends Dictionary {
* @see Cache#keys * @see Cache#keys
* @see Enumeration * @see Enumeration
*/ */
public synchronized Enumeration elements() { public synchronized Enumeration<Object> elements() {
return new CacheEnumerator(table, false); return new CacheEnumerator(table, false);
} }
@ -305,7 +307,7 @@ class Cache extends Dictionary {
* A Cache enumerator class. This class should remain opaque * A Cache enumerator class. This class should remain opaque
* to the client. It will use the Enumeration interface. * to the client. It will use the Enumeration interface.
*/ */
class CacheEnumerator implements Enumeration { class CacheEnumerator implements Enumeration<Object> {
boolean keys; boolean keys;
int index; int index;
CacheEntry table[]; CacheEntry table[];

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -99,10 +99,12 @@ import java.util.NoSuchElementException;
* @since 1.2 * @since 1.2
* @see java.util.HashMap * @see java.util.HashMap
* @see java.lang.ref.SoftReference * @see java.lang.ref.SoftReference
* @deprecated No direct replacement; {@link java.util.WeakHashMap}
* addresses a related by different use-case.
*/ */
@Deprecated
public class SoftCache extends AbstractMap implements Map { public class SoftCache extends AbstractMap<Object, Object> implements Map<Object, Object> {
/* The basic idea of this implementation is to maintain an internal HashMap /* The basic idea of this implementation is to maintain an internal HashMap
that maps keys to soft references whose referents are the keys' values; that maps keys to soft references whose referents are the keys' values;
@ -115,18 +117,18 @@ public class SoftCache extends AbstractMap implements Map {
*/ */
static private class ValueCell extends SoftReference { static private class ValueCell extends SoftReference<Object> {
static private Object INVALID_KEY = new Object(); static private Object INVALID_KEY = new Object();
static private int dropped = 0; static private int dropped = 0;
private Object key; private Object key;
private ValueCell(Object key, Object value, ReferenceQueue queue) { private ValueCell(Object key, Object value, ReferenceQueue<Object> queue) {
super(value, queue); super(value, queue);
this.key = key; this.key = key;
} }
private static ValueCell create(Object key, Object value, private static ValueCell create(Object key, Object value,
ReferenceQueue queue) ReferenceQueue<Object> queue)
{ {
if (value == null) return null; if (value == null) return null;
return new ValueCell(key, value, queue); return new ValueCell(key, value, queue);
@ -154,10 +156,10 @@ public class SoftCache extends AbstractMap implements Map {
/* Hash table mapping keys to ValueCells */ /* Hash table mapping keys to ValueCells */
private Map hash; private Map<Object, Object> hash;
/* Reference queue for cleared ValueCells */ /* Reference queue for cleared ValueCells */
private ReferenceQueue queue = new ReferenceQueue(); private ReferenceQueue<Object> queue = new ReferenceQueue<>();
/* Process any ValueCells that have been cleared and enqueued by the /* Process any ValueCells that have been cleared and enqueued by the
@ -189,7 +191,7 @@ public class SoftCache extends AbstractMap implements Map {
* factor is less than zero * factor is less than zero
*/ */
public SoftCache(int initialCapacity, float loadFactor) { public SoftCache(int initialCapacity, float loadFactor) {
hash = new HashMap(initialCapacity, loadFactor); hash = new HashMap<>(initialCapacity, loadFactor);
} }
/** /**
@ -202,7 +204,7 @@ public class SoftCache extends AbstractMap implements Map {
* or equal to zero * or equal to zero
*/ */
public SoftCache(int initialCapacity) { public SoftCache(int initialCapacity) {
hash = new HashMap(initialCapacity); hash = new HashMap<>(initialCapacity);
} }
/** /**
@ -210,7 +212,7 @@ public class SoftCache extends AbstractMap implements Map {
* capacity and the default load factor. * capacity and the default load factor.
*/ */
public SoftCache() { public SoftCache() {
hash = new HashMap(); hash = new HashMap<>();
} }
@ -348,13 +350,13 @@ public class SoftCache extends AbstractMap implements Map {
/* Internal class for entries. /* Internal class for entries.
Because it uses SoftCache.this.queue, this class cannot be static. Because it uses SoftCache.this.queue, this class cannot be static.
*/ */
private class Entry implements Map.Entry { private class Entry implements Map.Entry<Object, Object> {
private Map.Entry ent; private Map.Entry<Object, Object> ent;
private Object value; /* Strong reference to value, to prevent the GC private Object value; /* Strong reference to value, to prevent the GC
from flushing the value while this Entry from flushing the value while this Entry
exists */ exists */
Entry(Map.Entry ent, Object value) { Entry(Map.Entry<Object, Object> ent, Object value) {
this.ent = ent; this.ent = ent;
this.value = value; this.value = value;
} }
@ -371,9 +373,10 @@ public class SoftCache extends AbstractMap implements Map {
return ent.setValue(ValueCell.create(ent.getKey(), value, queue)); return ent.setValue(ValueCell.create(ent.getKey(), value, queue));
} }
@SuppressWarnings("unchecked")
public boolean equals(Object o) { public boolean equals(Object o) {
if (! (o instanceof Map.Entry)) return false; if (! (o instanceof Map.Entry)) return false;
Map.Entry e = (Map.Entry)o; Map.Entry<Object, Object> e = (Map.Entry<Object, Object>)o;
return (valEquals(ent.getKey(), e.getKey()) return (valEquals(ent.getKey(), e.getKey())
&& valEquals(value, e.getValue())); && valEquals(value, e.getValue()));
} }
@ -388,18 +391,18 @@ public class SoftCache extends AbstractMap implements Map {
/* Internal class for entry sets */ /* Internal class for entry sets */
private class EntrySet extends AbstractSet { private class EntrySet extends AbstractSet<Map.Entry<Object, Object>> {
Set hashEntries = hash.entrySet(); Set<Map.Entry<Object, Object>> hashEntries = hash.entrySet();
public Iterator iterator() { public Iterator<Map.Entry<Object, Object>> iterator() {
return new Iterator() { return new Iterator<Map.Entry<Object, Object>>() {
Iterator hashIterator = hashEntries.iterator(); Iterator<Map.Entry<Object, Object>> hashIterator = hashEntries.iterator();
Entry next = null; Entry next = null;
public boolean hasNext() { public boolean hasNext() {
while (hashIterator.hasNext()) { while (hashIterator.hasNext()) {
Map.Entry ent = (Map.Entry)hashIterator.next(); Map.Entry<Object, Object> ent = hashIterator.next();
ValueCell vc = (ValueCell)ent.getValue(); ValueCell vc = (ValueCell)ent.getValue();
Object v = null; Object v = null;
if ((vc != null) && ((v = vc.get()) == null)) { if ((vc != null) && ((v = vc.get()) == null)) {
@ -412,7 +415,7 @@ public class SoftCache extends AbstractMap implements Map {
return false; return false;
} }
public Object next() { public Map.Entry<Object, Object> next() {
if ((next == null) && !hasNext()) if ((next == null) && !hasNext())
throw new NoSuchElementException(); throw new NoSuchElementException();
Entry e = next; Entry e = next;
@ -433,7 +436,7 @@ public class SoftCache extends AbstractMap implements Map {
public int size() { public int size() {
int j = 0; int j = 0;
for (Iterator i = iterator(); i.hasNext(); i.next()) j++; for (Iterator<Map.Entry<Object, Object>> i = iterator(); i.hasNext(); i.next()) j++;
return j; return j;
} }
@ -446,12 +449,12 @@ public class SoftCache extends AbstractMap implements Map {
} }
private Set entrySet = null; private Set<Map.Entry<Object, Object>> entrySet = null;
/** /**
* Return a <code>Set</code> view of the mappings in this cache. * Return a <code>Set</code> view of the mappings in this cache.
*/ */
public Set entrySet() { public Set<Map.Entry<Object, Object>> entrySet() {
if (entrySet == null) entrySet = new EntrySet(); if (entrySet == null) entrySet = new EntrySet();
return entrySet; return entrySet;
} }