Commit 11614bf4 authored by Mihai Nita's avatar Mihai Nita

Fix for issue 22, fails in Unit parsing

parent eff96bcb
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.InvalidParameterException;
import net.sf.okapi.lib.xliff2.Util;
......@@ -102,27 +104,27 @@ 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;
CTag ctag = (CTag)tag;
if ( tagType.compareTo(ctag.getTagType()) != 0 ) return false;
if ( Util.compareAllowingNull(getId(), ctag.getId()) != 0 ) return false;
if ( !cc.equals(ctag.cc) ) return false;
if ( Util.compareAllowingNull(data, ctag.getData()) != 0 ) return false;
if ( Util.compareAllowingNull(dataRef, ctag.getDataRef()) != 0 ) return false;
if ( Util.compareAllowingNull(subFlows, ctag.getSubFlows()) != 0 ) return false;
if ( Util.compareAllowingNull(disp, ctag.getDisp()) != 0 ) return false;
if ( Util.compareAllowingNull(equiv, ctag.getEquiv()) != 0 ) return false;
if ( !getCanReorder().equals(ctag.getCanReorder()) ) return false;
if ( initialWithData != ctag.initialWithData ) return false;
if ( dataDir != ctag.dataDir ) return false;
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof CTag)) return false;
if (!super.equals(other)) return false;
CTag cTag = (CTag) other;
return initialWithData == cTag.initialWithData &&
Objects.equals(cc, cTag.cc) &&
Objects.equals(data, cTag.data) &&
Objects.equals(dataRef, cTag.dataRef) &&
dataDir == cTag.dataDir &&
Objects.equals(disp, cTag.disp) &&
Objects.equals(equiv, cTag.equiv) &&
Objects.equals(subFlows, cTag.subFlows) &&
canReorder == cTag.canReorder;
}
return true;
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), cc, data, initialWithData, dataRef, dataDir, disp, equiv, subFlows, canReorder);
}
@Override
......
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.Const;
import net.sf.okapi.lib.xliff2.InvalidParameterException;
import net.sf.okapi.lib.xliff2.Util;
......@@ -134,18 +136,29 @@ class CTagCommon {
this.dir = dir;
}
public boolean equals (CTagCommon other) {
if ( other == null ) return false;
if ( this == other) return true;
if ( Util.compareAllowingNull(getId(), other.getId()) != 0 ) return false;
if ( Util.compareAllowingNull(getType(), other.getType()) != 0 ) return false;
if ( Util.compareAllowingNull(getSubType(), other.getSubType()) != 0 ) return false;
if ( Util.compareAllowingNull(getCopyOf(), other.getCopyOf()) != 0 ) return false;
if ( getDir() != other.getDir() ) return false;
if ( getCanCopy() != other.getCanCopy() ) return false;
if ( getCanDelete() != other.getCanDelete() ) return false;
if ( getCanOverlap() != other.getCanOverlap() ) return false;
return true;
/**
* Indicates if this object is equals to a given one.
* @param other the other object to compare.
* @return true if the two objects are identical.
*/
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof CTagCommon)) return false;
CTagCommon that = (CTagCommon) other;
return hints == that.hints &&
canOverlap == that.canOverlap &&
Objects.equals(id, that.id) &&
Objects.equals(type, that.type) &&
Objects.equals(subType, that.subType) &&
Objects.equals(copyOf, that.copyOf) &&
dir == that.dir;
}
@Override
public int hashCode() {
return Objects.hash(id, type, hints, canOverlap, subType, copyOf, dir);
}
}
......@@ -16,6 +16,9 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Iterator;
import java.util.Objects;
/**
* Implements the {@link IWithExtAttributes} interface.
*/
......@@ -66,5 +69,36 @@ public class DataWithExtAttributes implements IWithExtAttributes {
if ( xattrs == null ) return null;
return xattrs.getAttributeValue(namespaceURI, localName);
}
/**
* Indicates if this object is equals to a given one.
* @param other the other object to compare.
* @return true if the two objects are identical.
*/
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof DataWithExtAttributes)) return false;
DataWithExtAttributes that = (DataWithExtAttributes) other;
if (this.xattrs == that.xattrs) return true;
if (this.xattrs == null || that.xattrs == null) return false;
Iterator<ExtAttribute> thisIter = this.xattrs.iterator();
Iterator<ExtAttribute> thatIter = that.xattrs.iterator();
while (thisIter.hasNext() ) {
if (!thatIter.hasNext() ) return false;
ExtAttribute thisObj = thisIter.next();
ExtAttribute thatObj = thatIter.next();
if (!Objects.equals(thisObj, thatObj)) return false;
}
return true;
}
@Override
public int hashCode() {
return Objects.hash(xattrs);
}
}
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
import javax.xml.namespace.QName;
import net.sf.okapi.lib.xliff2.Const;
......@@ -103,5 +105,20 @@ public class ExtAttribute {
public boolean isModule () {
return qName.getNamespaceURI().startsWith(Const.NS_XLIFF_MODSTART);
}
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof ExtAttribute)) return false;
ExtAttribute that = (ExtAttribute) other;
return Objects.equals(qName, that.qName) &&
Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(qName, value);
}
}
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.its.ITSItems;
import net.sf.okapi.lib.xliff2.its.IWithITSAttributes;
......@@ -155,13 +157,19 @@ 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;
if ( tagType.compareTo(mtag.getTagType()) != 0 ) return false;
return mc.equals(mtag.mc);
public boolean equals(Object other) {
if ( other == null ) return false;
if (this == other) return true;
if ( !(other instanceof MTag) ) return false;
if (!super.equals(other)) return false;
MTag mTag = (MTag) other;
return Objects.equals(mc, mTag.mc);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mc);
}
@Override
......
......@@ -16,15 +16,16 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.InvalidParameterException;
import net.sf.okapi.lib.xliff2.Util;
import net.sf.okapi.lib.xliff2.its.ITSItems;
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;
......@@ -114,17 +115,24 @@ class MTagCommon implements IWithITSAttributes {
* @param other the other object to compare.
* @return true if the two objects are identical.
*/
public boolean equals (MTagCommon other) {
if ( other == null ) return false;
if ( this == other ) return true;
if ( Util.compareAllowingNull(type, other.getType()) != 0 ) return false;
if ( Util.compareAllowingNull(id, other.getId()) != 0 ) return false;
if ( Util.compareAllowingNull(ref, other.getRef()) != 0 ) return false;
if ( Util.compareAllowingNull(value, other.getValue()) != 0 ) return false;
// Note that translate can be null, and it's OK
if ( translate != other.getTranslate() ) return false;
//TODO: compare the ITS items
return true;
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof MTagCommon)) return false;
MTagCommon that = (MTagCommon) other;
return Objects.equals(id, that.id) &&
Objects.equals(type, that.type) &&
Objects.equals(value, that.value) &&
Objects.equals(ref, that.ref) &&
Objects.equals(translate, that.translate) &&
Objects.equals(itsItems, that.itsItems);
}
@Override
public int hashCode() {
return Objects.hash(id, type, value, ref, translate, itsItems);
}
@Override
......
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.core;
import java.util.Objects;
/**
* Provides the common methods for code and marker tags.
* <p>Any object deriving from this class must also provide an implementation
......@@ -85,14 +87,6 @@ abstract public class Tag extends DataWithExtAttributes {
*/
abstract public void setType (String type);
/**
* Indicates if this tag 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.
* @return true if both tags are equals.
*/
abstract boolean equals (Tag tag);
/**
* Indicates if this tag is for a marker ({@link MTag}).
* @return true if this tag is one for a marker ({@link MTag}), false if it is for a code ({@link CTag}).
......@@ -105,4 +99,25 @@ abstract public class Tag extends DataWithExtAttributes {
*/
abstract public boolean isCode ();
/**
* Indicates if this tag is equal to another.
* <p>Use the <code>==</code> operator to test if two tags are the same.
* @param other the other tag to compare to this one.
* @return true if both tags are equals.
*/
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (this == other) return true;
if (!(other instanceof Tag)) return false;
if (!super.equals(other)) return false;
Tag tag = (Tag) other;
return tagType == tag.tagType;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), tagType);
}
}
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.its;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.InvalidParameterException;
import net.sf.okapi.lib.xliff2.XLIFFException;
import net.sf.okapi.lib.xliff2.core.MTag;
......@@ -233,4 +235,20 @@ 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;
if (!super.equals(other)) return false;
TermTag termTag = (TermTag) other;
return Objects.equals(annotatorRef, termTag.annotatorRef) &&
Objects.equals(termConfidence, termTag.termConfidence);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), annotatorRef, termConfidence);
}
}
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