Skip to content

Instantly share code, notes, and snippets.

@spaceCamel
Created August 27, 2010 09:25
Show Gist options
  • Save spaceCamel/553095 to your computer and use it in GitHub Desktop.
Save spaceCamel/553095 to your computer and use it in GitHub Desktop.
abstract class TypedMap {
private Map internalMap = new HashMap();
public <T> TypedMap put(Class<T> k, List<T> v) {
internalMap.put(k, v);
return this;
}
public <T> List<T> get(Class<T> k) {
return (List<T>) internalMap.get(k);
}
public <T> T getSingleValue(Class<T> k) {
List<T> l = (List<T>) internalMap.get(k);
if (l == null)
return null;
if (l.size() == 1)
return l.get(0);
else
throw new IllegalStateException("More than one value");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment