V
VisionSet
I have a several classes that implement an interface that declares a
getInteger() method.
I would like to store objects of this type in some sort of collection
I require to iterate them in the order inserted and to get them based on
their Integer key.
LinkedHashMap I believe is the daddy.
however I'm thinking this is quite expensive and most of the time my
Integers will be consecutive, so why not reimplement a custom ArrayList to
do the job, that has offset ability.
MyArrayList could even determine as the objects are added if they have
consecutive integers, thus making it very efficient to find them via get(int
index). Otherwise it could revert to searching for them by iteration. (or
even using the LinkedHashMap).
So I guess my question is, how does this 2nd fall back approach compare to
LinkedHashMap?
Also how does a Map work? how does it do get(Object key)? does it iterate
its contents?
Another question which relates to testing stuff like this. I've seen in a
recentish post that it is possible to do unit tests that time very
accurately, ie better than a simple System.getCurrentTimeMillis() type
approach. Is the answer - get JUnit? Or can I do this simply without it?
getInteger() method.
I would like to store objects of this type in some sort of collection
I require to iterate them in the order inserted and to get them based on
their Integer key.
LinkedHashMap I believe is the daddy.
however I'm thinking this is quite expensive and most of the time my
Integers will be consecutive, so why not reimplement a custom ArrayList to
do the job, that has offset ability.
MyArrayList could even determine as the objects are added if they have
consecutive integers, thus making it very efficient to find them via get(int
index). Otherwise it could revert to searching for them by iteration. (or
even using the LinkedHashMap).
So I guess my question is, how does this 2nd fall back approach compare to
LinkedHashMap?
Also how does a Map work? how does it do get(Object key)? does it iterate
its contents?
Another question which relates to testing stuff like this. I've seen in a
recentish post that it is possible to do unit tests that time very
accurately, ie better than a simple System.getCurrentTimeMillis() type
approach. Is the answer - get JUnit? Or can I do this simply without it?