collection framework: using the good interface



Hi,

I have a collection of objects containing information about words: each object hold a word, its part of speech (verb, noun, etc.), its frequency, and other properties.

I need to be able to retreive very quickly an objet according to some signifiant properties: its orthographic form and its part of speech for instance. A hash seems suited, but I cannot use a hash where the key is the orthographic form, for instance:
{
"plane" -> ref_to_object_holding_this_word
}


because several properties are signifiant for word identity: there is a plane "noun" and a plane "verbe".

Implementing hashkey() and equals() in my Word object seems to be the natural way, with "orthographic form" and "part of speech" fields both contributing to the definition of hashkey and equality, but in that case I would have a Map where both the key and the corresponding value are references to the same object. I'm wondering if this situation should be avoided, and if there is another solution. Since key and value are not different object, I was considering using an ArrayList object. But its indexOf(Object elem) method use equals() and not hashkey, and is probably not as much efficient as the HashMap hashing method.

Thanks,
SL
.



Relevant Pages

  • Re: collection framework: using the good interface
    ... > object hold a word, its part of speech, its frequency, ... > contributing to the definition of hashkey and equality, ... > indexOfmethod use equals() and not hashkey, ... HashSet will probably be the fastest Collection ...
    (comp.lang.java.help)
  • Re: collection framework: using the good interface
    ... SL wrote: some signifiant properties: its orthographic form and its part of speech for instance. ... word object's class would implement Comparable, and should have equals ... If I compute hashcode and equality using the form and POS properties. ...
    (comp.lang.java.help)