Commit 787485ad authored by Martin Wunderlich's avatar Martin Wunderlich

Issue 22 incorrect equals() method in Tag and derived classes

parent f47dd423
......@@ -102,12 +102,12 @@ public class CTag extends Tag {
}
@Override
public boolean equals (Tag tag) {
if ( tag == null ) return false;
if ( this == tag ) return true;
if ( !(tag instanceof CTag) ) return false;
public boolean equals (Object other) {
if ( other == null ) return false;
if ( this == other ) return true;
if ( !(other instanceof CTag) ) return false;
CTag ctag = (CTag)tag;
CTag ctag = (CTag)other;
if ( tagType.compareTo(ctag.getTagType()) != 0 ) return false;
if ( Util.compareAllowingNull(getId(), ctag.getId()) != 0 ) return false;
......
......@@ -155,11 +155,11 @@ public class MTag extends Tag implements IWithITSAttributes {
}
@Override
public boolean equals (Tag tag) {
if ( tag == null ) return false;
if ( this == tag ) return true;
if ( !(tag instanceof MTag) ) return false;
MTag mtag = (MTag)tag;
public boolean equals (Object other) {
if ( other == null ) return false;
if ( this == other ) return true;
if ( !(other instanceof MTag) ) return false;
MTag mtag = (MTag)other;
if ( tagType.compareTo(mtag.getTagType()) != 0 ) return false;
return mc.equals(mtag.mc);
}
......
......@@ -24,7 +24,7 @@ import net.sf.okapi.lib.xliff2.its.IWithITSAttributes;
/**
* Represents common data for the opening and closing {@link MTag}.
*/
class MTagCommon implements IWithITSAttributes {
public class MTagCommon implements IWithITSAttributes {
private String id;
private String type;
......
......@@ -86,12 +86,13 @@ abstract public class Tag extends DataWithExtAttributes {
abstract public void setType (String type);
/**
* Indicates if this tag is equal to another.
* Indicates if this other is equal to another.
* <p>Use the <code>==</code> operator to test if two tags are the same.
* @param tag the other tag to compare to this one.
* @param other the other tag to compare to this one.
* @return true if both tags are equals.
*/
abstract boolean equals (Tag tag);
@Override
public abstract boolean equals(Object other);
/**
* Indicates if this tag is for a marker ({@link MTag}).
......
......@@ -233,4 +233,13 @@ public class TermTag extends MTag {
setValue(null);
}
@Override
public boolean equals (Object other) {
if ( other == null ) return false;
if ( this == other) return true;
if ( !(other instanceof TermTag) ) return false;
TermTag termtag = (TermTag) other;
if ( tagType.compareTo(termtag.getTagType()) != 0 ) return false;
return mc.equals(termtag.mc);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment