I've just fetched newest java.util from CVS and I have just three notes:


1)Using exceptions versus explicit checks.
I think that for methods that if used normally do not throw exceptions,
checks should be done by exception if possible. For example in
ArrayEnumeration, possibility that nextElement() overflows is very small
(every sane person use hasNextElement() first). So, code could look like
this:

try {
        return elements[index++];
} catch ( ArrayOutOfBoundsException e ) {
                throw new NoSuchElementException();
        }

instead of

if ( index >= elements.length ) throw ...
return elements[index++];


2) Vector:addAll(Collection)
is:             ensureCapacity(c.size())
should be:      ensureCapacity(c.size() + elementCount)
and the we could use 
        elements[elementCount++]=i.next();
instead of 
        addElement(i.next())
(of course it is just matter of efficiency - it was working)


3) I think, that if it is possible, class specific utility classes
should be implemented as inner classes
(for example VectorIterator). They could be static or non-static, but it
just looks better (at least for me).



Note that all this things are just style/efficiency remarks - java.util
is done well, and certainly good design and robustness is more important
that chasing few opcodes of speedup.

Artur

Reply via email to