15 Apr 2004 12:57
New map helper method
I've added a new helper method to Map called get(key, default) which
takes a default value which is added to the map if the key does not
already exist.
So you can swap code like this
classmethods = classmap.classmethods;
if (classmethods == null) {
classmethods = [];
classmap.classmethods = classmethods;
}
classmethods.add(method);
with
classmap.get("classmethods", []).add(method)
the nice thing about this approach is it works for any type of entry,
be it a list, map, bean, whatever. The downside is it creates the
default value each time the method is called.
James
-------
http://radio.weblogs.com/0112098/
RSS Feed