Fixed a bunch of type safety bits pointed out by the latest version of Eclipse.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5274 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-07-30 12:58:51 +00:00
parent ca4c5897fb
commit 725f656197
77 changed files with 248 additions and 250 deletions
@@ -33,7 +33,7 @@ public interface AccessController
* Should return true if the supplied subscriber is allowed to
* subscribe to the specified object.
*/
boolean allowSubscribe (DObject object, Subscriber subscriber);
boolean allowSubscribe (DObject object, Subscriber<?> subscriber);
/**
* Should return true if the supplied event is legal for dispatch on
@@ -131,7 +131,7 @@ public class AttributeChangedEvent extends NamedEvent
_oldValue = target.getAttribute(_name);
Object value = _value;
if (value != null) {
Class vclass = value.getClass();
Class<?> vclass = value.getClass();
if (vclass.isPrimitive()) {
// do nothing; we check this to avoid the more expensive isAssignableFrom check
// on primitives which are far and away the most common case
@@ -141,7 +141,7 @@ public class AttributeChangedEvent extends NamedEvent
System.arraycopy(value, 0, clone, 0, length);
value = clone;
} else if (DSet.class.isAssignableFrom(vclass)) {
value = ((DSet)value).clone();
value = ((DSet<?>)value).clone();
}
}
// pass the new value on to the object
@@ -202,7 +202,7 @@ public abstract class DEvent implements Streamable
/** Used to differentiate between null meaning we haven't initialized our old entry and null
* being the actual old entry. */
protected static final DSet.Entry UNSET_OLD_ENTRY = new DSet.Entry() {
public Comparable getKey () {
public Comparable<?> getKey () {
return null;
}
};
@@ -25,7 +25,9 @@ import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Maps;
import com.samskivert.util.ListUtil;
import com.samskivert.util.StringUtil;
@@ -151,7 +153,7 @@ public class DObject
*
* @see DObjectManager#subscribeToObject
*/
public void addSubscriber (Subscriber sub)
public void addSubscriber (Subscriber<?> sub)
{
// only add the subscriber if they're not already there
Object[] subs = ListUtil.testAndAddRef(_subs, sub);
@@ -175,7 +177,7 @@ public class DObject
*
* @see DObjectManager#unsubscribeFromObject
*/
public void removeSubscriber (Subscriber sub)
public void removeSubscriber (Subscriber<?> sub)
{
if (ListUtil.clearRef(_subs, sub) != null) {
// if we removed something, check to see if we just removed the last subscriber from
@@ -291,7 +293,7 @@ public class DObject
/**
* Request to have the specified key removed from the specified DSet.
*/
public void removeFromSet (String setName, Comparable key)
public void removeFromSet (String setName, Comparable<?> key)
{
requestEntryRemove(setName, getSet(setName), key);
}
@@ -377,7 +379,7 @@ public class DObject
*
* @return true if the subscriber has access to the object, false if they do not.
*/
public boolean checkPermissions (Subscriber sub)
public boolean checkPermissions (Subscriber<?> sub)
{
if (_controller != null) {
return _controller.allowSubscribe(this, sub);
@@ -814,7 +816,7 @@ public class DObject
* Calls by derived instances when a set remover method was called.
*/
protected <T extends DSet.Entry> void requestEntryRemove (
String name, DSet<T> set, Comparable key)
String name, DSet<T> set, Comparable<?> key)
{
// if we're on the authoritative server, we update the set immediately
T oldEntry = null;
@@ -913,7 +915,7 @@ public class DObject
protected transient boolean _deathWish = false;
/** Maintains a mapping of sorted field arrays for each distributed object class. */
protected static HashMap<Class, Field[]> _ftable = new HashMap<Class, Field[]>();
protected static Map<Class<?>, Field[]> _ftable = Maps.newHashMap();
/** Used to sort and search {@link #_fields}. */
protected static final Comparator<Field> FIELD_COMP = new Comparator<Field>() {
@@ -63,7 +63,7 @@ public class DSet<E extends DSet.Entry>
* Each entry provide an associated key which is used to determine its uniqueness in the
* set. See the {@link DSet} class documentation for further information.
*/
Comparable getKey ();
Comparable<?> getKey ();
}
/**
@@ -82,6 +82,17 @@ public class DSet<E extends DSet.Entry>
return new DSet<E>(source);
}
/**
* Compares the first comparable to the second. This is useful to avoid type safety warnings
* when dealing with the keys of {@link DSet.Entry} values.
*/
public static int compare (Comparable<?> c1, Comparable<?> c2)
{
@SuppressWarnings("unchecked") Comparable<Object> cc1 = (Comparable<Object>)c1;
@SuppressWarnings("unchecked") Comparable<Object> cc2 = (Comparable<Object>)c2;
return cc1.compareTo(cc2);
}
/**
* Creates a distributed set and populates it with values from the supplied iterator. This
* should be done before the set is unleashed into the wild distributed object world because no
@@ -161,7 +172,7 @@ public class DSet<E extends DSet.Entry>
* Returns true if an entry in the set has a key that <code>equals()</code> the supplied
* key. Returns false otherwise.
*/
public boolean containsKey (Comparable key)
public boolean containsKey (Comparable<?> key)
{
return get(key) != null;
}
@@ -170,7 +181,7 @@ public class DSet<E extends DSet.Entry>
* Returns the entry that matches (<code>getKey().equals(key)</code>) the specified key or null
* if no entry could be found that matches the key.
*/
public E get (Comparable key)
public E get (Comparable<?> key)
{
// determine where we'll be adding the new element
int eidx = ArrayUtil.binarySearch(_entries, 0, _size, new KeyWrapper(key), ENTRY_COMP);
@@ -325,7 +336,7 @@ public class DSet<E extends DSet.Entry>
*
* @return the old matching entry if found and removed, null if not found.
*/
protected E removeKey (Comparable key)
protected E removeKey (Comparable<?> key)
{
// don't fail, but generate a warning if we're passed a null key
if (key == null) {
@@ -461,13 +472,13 @@ public class DSet<E extends DSet.Entry>
/** Used to search for keys. */
protected static class KeyWrapper implements DSet.Entry
{
public KeyWrapper (Comparable key) {
public KeyWrapper (Comparable<?> key) {
_key = key;
}
public Comparable getKey () {
public Comparable<?> getKey () {
return _key;
}
protected Comparable _key;
protected Comparable<?> _key;
}
/** The entries of the set (in a sparse array). */
@@ -485,8 +496,7 @@ public class DSet<E extends DSet.Entry>
/** Used for lookups and to keep the set contents sorted on insertions. */
protected static Comparator<Entry> ENTRY_COMP = new Comparator<Entry>() {
public int compare (Entry e1, Entry e2) {
@SuppressWarnings("unchecked") int val = e1.getKey().compareTo(e2.getKey());
return val;
return DSet.compare(e1.getKey(), e2.getKey());
}
};
}
@@ -33,8 +33,8 @@ import static com.threerings.presents.Log.log;
/**
* Maps distributed object events to methods using reflection.
*/
public class DynamicListener
implements AttributeChangeListener, ElementUpdateListener, SetListener
public class DynamicListener<T extends DSet.Entry>
implements AttributeChangeListener, ElementUpdateListener, SetListener<T>
{
/**
* Creates a listener that dynamically dispatches events on the supplied
@@ -70,21 +70,21 @@ public class DynamicListener
}
// from interface SetListener
public void entryAdded (EntryAddedEvent event)
public void entryAdded (EntryAddedEvent<T> event)
{
dispatchMethod(event.getName() + "Added",
new Object[] { event.getEntry() });
}
// from interface SetListener
public void entryUpdated (EntryUpdatedEvent event)
public void entryUpdated (EntryUpdatedEvent<T> event)
{
dispatchMethod(event.getName() + "Updated",
new Object[] { event.getEntry() });
}
// from interface SetListener
public void entryRemoved (EntryRemovedEvent event)
public void entryRemoved (EntryRemovedEvent<T> event)
{
dispatchMethod(event.getName() + "Removed",
new Object[] { event.getKey() });
@@ -120,7 +120,7 @@ public class DynamicListener
*/
protected Method resolveMethod (String name, Object[] arguments)
{
Class[] ptypes = new Class[arguments.length];
Class<?>[] ptypes = new Class<?>[arguments.length];
for (int ii = 0; ii < arguments.length; ii++) {
ptypes[ii] = arguments[ii] == null ?
null : arguments[ii].getClass();
@@ -167,7 +167,7 @@ public class ElementUpdatedEvent extends NamedEvent
try {
// fetch the array field from the object
Field field = target.getClass().getField(_name);
Class ftype = field.getType();
Class<?> ftype = field.getType();
// sanity check
if (!ftype.isArray()) {
@@ -44,7 +44,7 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
* @param key the entry key that identifies the entry to remove.
* @param oldEntry the previous value of the entry.
*/
public EntryRemovedEvent (int targetOid, String name, Comparable key, T oldEntry)
public EntryRemovedEvent (int targetOid, String name, Comparable<?> key, T oldEntry)
{
super(targetOid, name);
_key = key;
@@ -62,7 +62,7 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
/**
* Returns the key that identifies the entry that has been removed.
*/
public Comparable getKey ()
public Comparable<?> getKey ()
{
return _key;
}
@@ -115,7 +115,7 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
buf.append(", key=").append(_key);
}
protected Comparable _key;
protected Comparable<?> _key;
@SuppressWarnings("unchecked")
protected transient T _oldEntry = (T)UNSET_OLD_ENTRY;