tryanDLS
20 Nov 2006, 3:42 PM
Jack,
I was looking at the add method, and I can see the possibility for some very hard to find bugs occurring.
Since the method doesn't check for key existence, you can add multiple items with the same key and step on things. Also, if you called each in this situation, weird things could happen. You'd have the action take place 2 times on one element, since it would be in 2 places in the items array.
Maybe there's a use for this implementation, but it would seem to be the exception, rather than the norm, and should be handled as a subclass.
I think I'd rather know that I added a dup key via an exception, unless I specifically wanted a type of collection that allowed a dup key to do a replace. Even in that situation, the implementation isn't right as there are still 2 items in the array being iterated over.
EDIT:
So I was playing with implementing a check in add for a dup key, and found a bug in indexOfKey() - it passes 'key' as the arg, the compare uses 'o'. Also, the for loop is looking at 'this.key.length' instead of 'this.keys.length'
I was looking at the add method, and I can see the possibility for some very hard to find bugs occurring.
Since the method doesn't check for key existence, you can add multiple items with the same key and step on things. Also, if you called each in this situation, weird things could happen. You'd have the action take place 2 times on one element, since it would be in 2 places in the items array.
Maybe there's a use for this implementation, but it would seem to be the exception, rather than the norm, and should be handled as a subclass.
I think I'd rather know that I added a dup key via an exception, unless I specifically wanted a type of collection that allowed a dup key to do a replace. Even in that situation, the implementation isn't right as there are still 2 items in the array being iterated over.
EDIT:
So I was playing with implementing a check in add for a dup key, and found a bug in indexOfKey() - it passes 'key' as the arg, the compare uses 'o'. Also, the for loop is looking at 'this.key.length' instead of 'this.keys.length'