ArrayMap and ArrayListScope of ChangeCreate a new class called ArrayMap in the lang.types package which will represent a map. Rationale
Lists and maps need to be distinguishable. PHP arrays are one or the
other, or even both. For a more detailled explanation, see the blog entry
http://news.xp-framework.net/article/293/2009/04/05/. Functionality
Usage examplesThe array operations are overloaded to give this class the typical "array" usability: $m= new ArrayMap(array('one' => 1, 'two' => 2));
Refactoring
Although this class behaves like a typical PHP array, it isn't one. Keep
this in mind when code uses sizeof or any of the array functions
such as array_keys, asort or array_map. The
places where a real array is required need to be passed the ArrayMap's
array member. // Old code Code that uses foreach() or array access syntax as shown above
does not need to be changed. StringOf
The xp::stringOf() function will be extended to produce the
following output: xp::stringOf(new ArrayList(1, 2, 3));
XP language integration
The XP language will use these two types as backing for the array and map
literals. // Equivalent of: $a= new ArrayList(1, 2, 3);
Consistency
The ArrayList class will be changed to adapt the array
member (instead of values). Also, to follow the general strategy
of replacing native arrays by the wrapper types provided in the XP framework,
the restriction of not being able to add elements to an ArrayList will be
removed: $a= new ArrayList(1, 2, 3);
This used to throw an IllegalArgumentException and will now be allowed,
resulting in a list with four elements. Security considerations
None. Speed impact
Slower than native array implementation. Dependencies
BC break for public member "value" in ArrayList class, renamed to "array". Related documents
Comments
friebe, Mon Apr 6 08:19:04 2009
What additional methods should this class provide? What comes to my mind
would be keys() and values() methods returning ArrayLists.
I don't think this class should be a full-featured "swiss-army knife"-style
hashtable implementation, there's util.collections.HashTable for
this and we could also think about extension methods. friebe, Mon Apr 6 08:23:16 2009
In the same course I think the util.Hashmap class could be
deprecated. | Table of contents |