Type safety patrol.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4243 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-07-05 00:50:28 +00:00
parent 40d0df6dfa
commit a89473d1b5
7 changed files with 31 additions and 25 deletions
@@ -126,7 +126,7 @@ public class MessageManager
public MessageBundle getBundle (String path)
{
// first look in the cache
MessageBundle bundle = (MessageBundle)_cache.get(path);
MessageBundle bundle = _cache.get(path);
if (bundle != null) {
return bundle;
}
@@ -190,7 +190,8 @@ public class MessageManager
protected ClassLoader _loader;
/** A cache of instantiated message bundles. */
protected HashMap _cache = new HashMap();
protected HashMap<String,MessageBundle> _cache =
new HashMap<String,MessageBundle>();
/** Our top-level message bundle, from which others obtain messages if
* they can't find them within themselves. */
@@ -59,7 +59,8 @@ public class StreamableArrayList<E> extends ArrayList<E>
int ecount = in.readInt();
ensureCapacity(ecount);
for (int ii = 0; ii < ecount; ii++) {
add((E)in.readObject());
@SuppressWarnings("unchecked") E elem = (E)in.readObject();
add(elem);
}
}
}
@@ -36,7 +36,7 @@ import com.threerings.io.Streamable;
*
* @see Streamable
*/
public class StreamableHashIntMap extends HashIntMap
public class StreamableHashIntMap<V> extends HashIntMap<V>
implements Streamable
{
/**
@@ -82,7 +82,8 @@ public class StreamableHashIntMap extends HashIntMap
ensureCapacity(ecount);
for (int ii = 0; ii < ecount; ii++) {
int key = in.readInt();
put(key, in.readObject());
@SuppressWarnings("unchecked") V value = (V)in.readObject();
put(key, value);
}
}
}
@@ -80,7 +80,9 @@ public class StreamableHashMap<K,V> extends HashMap<K,V>
{
int ecount = in.readInt();
for (int ii = 0; ii < ecount; ii++) {
put((K)in.readObject(), (V)in.readObject());
@SuppressWarnings("unchecked") K key = (K)in.readObject();
@SuppressWarnings("unchecked") V value = (V)in.readObject();
put(key, value);
}
}
}
+2 -2
View File
@@ -94,7 +94,7 @@ public class TimeUtil
minUnit = (byte) Math.min(minUnit, MAX_UNIT);
duration = Math.abs(duration);
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<String>();
int parts = 0; // how many parts are in the translation string?
for (byte uu = MILLISECOND; uu <= MAX_UNIT; uu++) {
int quantity = getQuantityPerUnit(uu);
@@ -110,7 +110,7 @@ public class TimeUtil
}
if (parts == 1) {
return (String) list.get(0);
return list.get(0);
} else {
return MessageBundle.compose("m.times_" + parts, list.toArray());
}
@@ -90,23 +90,23 @@ public class TrackedObject
* instances and an <code>int[]</code> array that represent the number
* of outstanding instance of all {@link TrackedObject}s in the VM.
*/
public static Tuple getSnapshot ()
public static Tuple<Class[],int[]> getSnapshot ()
{
Class[] classes = null;
int[] counts = null;
synchronized (_map) {
classes = new Class[_map.size()];
counts = new int[_map.size()];
Iterator iter = _map.entrySet().iterator();
for (int ii = 0; iter.hasNext(); ii++) {
Map.Entry entry = (Map.Entry)iter.next();
classes[ii] = (Class)entry.getKey();
counts[ii] = ((int[])entry.getValue())[0];
int idx = 0;
for (Map.Entry<Class,int[]> entry : _map.entrySet()) {
classes[idx] = entry.getKey();
counts[idx] = entry.getValue()[0];
idx++;
}
}
return new Tuple(classes, counts);
return new Tuple<Class[],int[]>(classes, counts);
}
/** Tracks a mapping from {@link Class} object to active count. */
protected static HashMap _map = new HashMap();
protected static HashMap<Class,int[]> _map = new HashMap<Class,int[]>();
}
@@ -160,9 +160,9 @@ public class SignalManager
public synchronized static void registerSignalHandler (
int signal, SignalHandler handler)
{
ObserverList list = (ObserverList)_handlers.get(signal);
ObserverList<SignalHandler> list = _handlers.get(signal);
if (list == null) {
_handlers.put(signal, list = new ObserverList(
_handlers.put(signal, list = new ObserverList<SignalHandler>(
ObserverList.SAFE_IN_ORDER_NOTIFY));
if (_haveLibrary) {
activateHandler(signal);
@@ -189,7 +189,7 @@ public class SignalManager
public synchronized static void removeSignalHandler (
int signal, SignalHandler handler)
{
ObserverList list = (ObserverList)_handlers.get(signal);
ObserverList<SignalHandler> list = _handlers.get(signal);
if (list == null || !list.contains(handler)) {
log.warning("Requested to remove non-registered handler " +
"[signal=" + signal + ", handler=" + handler + "].");
@@ -215,11 +215,11 @@ public class SignalManager
_lastINTed = now;
}
}
ObserverList list = (ObserverList)_handlers.get(signal);
ObserverList<SignalHandler> list = _handlers.get(signal);
if (list != null) {
list.apply(new ObserverList.ObserverOp() {
public boolean apply (Object obs) {
return ((SignalHandler)obs).signalReceived(signal);
list.apply(new ObserverList.ObserverOp<SignalHandler>() {
public boolean apply (SignalHandler handler) {
return handler.signalReceived(signal);
}
});
}
@@ -231,7 +231,7 @@ public class SignalManager
*/
protected static void checkEmpty (int signal)
{
ObserverList list = (ObserverList)_handlers.get(signal);
ObserverList<SignalHandler> list = _handlers.get(signal);
if (list != null && list.size() == 0) {
_handlers.remove(signal);
if (_haveLibrary) {
@@ -257,7 +257,8 @@ public class SignalManager
protected static native void dispatchSignals ();
/** A mapping from signal number to a list of handlers. */
protected static HashIntMap _handlers = new HashIntMap();
protected static HashIntMap<ObserverList<SignalHandler>> _handlers =
new HashIntMap<ObserverList<SignalHandler>>();
/** Our signal dispatcher thread. */
protected static Thread _sigdis;