On 8/13/11 4:34 AM, James Kosin wrote:
Everyone,
The Dictionary tests are pointing to some possible issues:
(a) The Set<StringList> class being returned from asStringSet() has
defined an iterator(), contains(). and size() methods. The tests seem
to suggest that the hashCode() values for the two sets need to be
identical. Unfortunately, this is not the case because of the
implementation. The hashCode() and equals() methods would need to be
written for this to be fixed. Currently, the hashCode() for the
iterated members should be correct... however, the Set's hashCode()
function isn't getting the same results due to the method of
calculating the hashCode().
It is returning a Set<String>, but well there you got a point. Maybe
that is not a good idea at all when it will be used for look ups
later on. Then the look up code, would need to program directly against
the dictionary, or handle the lower casing itself.
We need to look into it. The reason we created StringList is that the
dictionary should be able to contain tokenized strings.
(b) I've added locally some more tests to the dictionary; but, I'd
like to run it past everyone before attempting to make changes. I'll
post as separate messages with explanations, if that is okay.
Fell free to check it in, then it can be discussed as part of a code review.
(c) Okay, maybe this one is a bit bothersome to some. The IDE I'm
using is showing items that should have an @Override tag to indicate
the functions are overriding super class items of the same name. I'm
not sure if this is something we need to migrate to the correct style
or we should leave them as advertized (as is)?
OpenNLP must stay compatible with Java 5 for the 1.5 series of releases.
Maybe you got the setting wrong in your IDE and use
Java 6? Otherwise it is safe to add these.
(d) I'm also not sure on the inheritance part for Java. I'm thinking
also that the StringListWrapper may be better suited to be a class
that 'extends StringList' instead of just wrapping? Any ideas or
thought on this?
That would not work out. A user creates a StringList object. Now he
wants to figure out if it is part of a Dictionary,
therefore he calls its contains method, where he needs to pass in a
StringList object.
The StringListWrapper is now used to wrap the StringList object, in
order to modify the behavior of the equals and hashCode
methods. If StringListWrapper would extend StringList, then we would
need to copy the contents of StringList into it. We cannot
take an advantage of sub-classing and therefore it is not done.
Jörn