You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by "william.colen@gmail.com" <wi...@gmail.com> on 2011/08/17 12:23:39 UTC

Re: svn commit: r1158465 - in /incubator/opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/chunker/ main/java/opennlp/tools/doccat/ main/java/opennlp/tools/postag/ main/java/opennlp/tools/sentdetect/ main/java/opennlp/tools/tokenize/ test/java

Wow, thanks. The error is from NameSample.equals. I copied the it without
checking if it was ok.

Should the equals take care with null members or all class members are
expected to be set?

On Wed, Aug 17, 2011 at 5:30 AM, Jörn Kottmann <ko...@gmail.com> wrote:

> Hello William,
>
> all the new equals methods look like the one below.
> At the end in the else clause you return true, but that should really be
> false,
> otherwise two objects which are not of the same type are equals.
>
> Jörn
>
>
> On 8/17/11 12:30 AM, colen@apache.org wrote:
>
>> Modified: incubator/opennlp/trunk/**opennlp-tools/src/main/java/**
>> opennlp/tools/chunker/**ChunkSample.java
>> URL: http://svn.apache.org/viewvc/**incubator/opennlp/trunk/**
>> opennlp-tools/src/main/java/**opennlp/tools/chunker/**
>> ChunkSample.java?rev=1158465&**r1=1158464&r2=1158465&view=**diff<http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java?rev=1158465&r1=1158464&r2=1158465&view=diff>
>> ==============================**==============================**
>> ==================
>> --- incubator/opennlp/trunk/**opennlp-tools/src/main/java/**
>> opennlp/tools/chunker/**ChunkSample.java (original)
>> +++ incubator/opennlp/trunk/**opennlp-tools/src/main/java/**
>> opennlp/tools/chunker/**ChunkSample.java Tue Aug 16 22:30:53 2011
>> @@ -195,4 +195,20 @@ public class ChunkSample {
>>            }
>>            return chunkString.toString();
>>          }
>> +
>> +  @Override
>> +  public boolean equals(Object obj) {
>> +    if (this == obj) {
>> +      return true;
>> +    } else if (obj instanceof ChunkSample) {
>> +      ChunkSample a = (ChunkSample) obj;
>> +
>> +      return Arrays.equals(getSentence(), a.getSentence())
>> +&&  Arrays.equals(getTags(), a.getTags())
>> +&&  Arrays.equals(getPreds(), a.getPreds());
>> +    } else {
>> +      return true;
>> +    }
>> +  }
>> +
>>  }
>>
>>

Re: svn commit: r1158465 - in /incubator/opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/chunker/ main/java/opennlp/tools/doccat/ main/java/opennlp/tools/postag/ main/java/opennlp/tools/sentdetect/ main/java/opennlp/tools/tokenize/ test/java

Posted by Jörn Kottmann <ko...@gmail.com>.
On 8/17/11 12:23 PM, william.colen@gmail.com wrote:
> Wow, thanks. The error is from NameSample.equals. I copied the it without
> checking if it was ok.
>
> Should the equals take care with null members or all class members are
> expected to be set?

Then it is my mistake quite sometime ago. Its already handling the null 
case,
and should return false, because in this case it goes into the last 
else, which
is fine.

Jörn