----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: 2001. szeptember 11. 19:31
Subject: cvs commit:
jakarta-velocity/src/java/org/apache/velocity/util/introspection
Introspector.java


<snip/>
>
>   Also, it doesn't seem that using a Set would offer any advantage, as
AFAIK,
>   the standard impls are backed by HashMap or TreeMap anyway...
>

<snip/>

True, and it's one of most lame things I hate about Sun's JDK collections
implementation. However, our source code is cleaner AND we can hope some
future implementation will fix this (I have written my own LightHashSet that
is a non-map based clean implementation of hash set that I use when I mind
memory consumption).

The other infinitely lame thing in Sun's JDK collections implementation is
an explicit call to method named RangeCheck() in all ArrayList accessors.
Basically, it looks like this

public Object get(int index) {
   RangeCheck(index);
   return elementData[index];
}

and RangeCheck looks like

private void RangeCheck(int index) {
    if (index >= size || index < 0)
        throw new IndexOutOfBoundsException(
        "Index: "+index+", Size: "+size);
}

So, we have an EXPLICIT range check and exception throw EVEN if we access
the list through an iterator (since it also calls get()).

If only they had implemented it as

public Object get(int index) {
   try {
       return elementData[index];
   }
   catch(ArrayIndexOutOfBoundsException e) {
        throw new IndexOutOfBoundsException(
        "Index: "+index+", Size: "+size);
   }
}

it would be much saner...

Just ranting...
   Attila.



Reply via email to