diff --git a/src/java/com/threerings/util/DefaultMap.java b/src/java/com/threerings/util/DefaultMap.java index 3d39e3335..786e97aad 100644 --- a/src/java/com/threerings/util/DefaultMap.java +++ b/src/java/com/threerings/util/DefaultMap.java @@ -26,6 +26,7 @@ import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; +import com.google.common.base.Function; import com.google.common.collect.ForwardingMap; import com.google.common.collect.Maps; @@ -35,13 +36,6 @@ import com.google.common.collect.Maps; */ public class DefaultMap extends ForwardingMap { - /** Used to create default values. */ - public interface Creator - { - /** Creates a new default value for the specified key. */ - V create (K key); - } - /** * Creates a default map backed by a {@link HashMap} that creates instances of the supplied * class (using its no-args constructor) as defaults. @@ -57,7 +51,7 @@ public class DefaultMap extends ForwardingMap */ public static DefaultMap newInstanceMap (Map delegate, Class clazz) { - Creator creator = newInstanceCreator(clazz); + Function creator = newInstanceCreator(clazz); return newMap(delegate, creator); } @@ -66,7 +60,7 @@ public class DefaultMap extends ForwardingMap * Returns a Creator that makes instances of the supplied class (using its no-args * constructor) as default values. */ - public static Creator newInstanceCreator (Class clazz) { + public static Function newInstanceCreator (Class clazz) { final Constructor ctor; try { @@ -74,8 +68,8 @@ public class DefaultMap extends ForwardingMap } catch (NoSuchMethodException nsme) { throw new IllegalArgumentException(clazz + " must have a no-args constructor."); } - return new Creator() { - public V create (K key) { + return new Function() { + public V apply (K key) { try { return ctor.newInstance(); } catch (Exception e) { @@ -88,7 +82,7 @@ public class DefaultMap extends ForwardingMap /** * Creates a default map backed by a {@link HashMap} using the supplied default creator. */ - public static DefaultMap newHashMap (Creator creator) + public static DefaultMap newHashMap (Function creator) { return newMap(Maps.newHashMap(), creator); } @@ -96,7 +90,7 @@ public class DefaultMap extends ForwardingMap /** * Creates a default map backed by the supplied map using the supplied default creator. */ - public static DefaultMap newMap (Map delegate, Creator creator) + public static DefaultMap newMap (Map delegate, Function creator) { return new DefaultMap(delegate, creator); } @@ -104,7 +98,7 @@ public class DefaultMap extends ForwardingMap /** * Creates a default map backed by the supplied map using the supplied default creator. */ - public DefaultMap (Map delegate, Creator creator) + public DefaultMap (Map delegate, Function creator) { _delegate = delegate; _creator = creator; @@ -120,7 +114,7 @@ public class DefaultMap extends ForwardingMap V value = get(key); // null is a valid value, so we check containsKey() before creating a default if (value == null && !containsKey(key)) { - put(key, value = _creator.create(key)); + put(key, value = _creator.apply(key)); } return value; } @@ -132,5 +126,5 @@ public class DefaultMap extends ForwardingMap } protected final Map _delegate; - protected final Creator _creator; + protected final Function _creator; }