Commit 2aaab7ed authored by Yves's avatar Yves

Fixing reset of list of isolated tags for check. Adding hashCode() and...

Fixing reset of list of isolated tags for check. Adding hashCode() and equals() to classes derived from DataWithExtAttributes.
parent 11614bf4
Pipeline #48963041 passed with stage
in 1 minute and 26 seconds
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.changeTracking;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.Const;
import net.sf.okapi.lib.xliff2.Util;
import net.sf.okapi.lib.xliff2.core.DataWithExtAttributes;
......@@ -153,4 +155,38 @@ public class Item extends DataWithExtAttributes implements IWithExtAttributes {
return "</" + Const.PREFIXCOL_TRACKINGSd + TAG_NAME + ">";
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), property, text);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Item other = (Item) obj;
if (property == null) {
if (other.property != null) {
return false;
}
} else if (!property.equals(other.property)) {
return false;
}
if (text == null) {
if (other.text != null) {
return false;
}
} else if (!text.equals(other.text)) {
return false;
}
return true;
}
}
......@@ -18,6 +18,7 @@ package net.sf.okapi.lib.xliff2.core;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.xml.namespace.QName;
......@@ -202,4 +203,38 @@ public class ExtElement extends DataWithExtAttributes implements IExtChild {
return qName.getNamespaceURI().startsWith(Const.NS_XLIFF_MODSTART);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), children, qName);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
ExtElement other = (ExtElement) obj;
if (children == null) {
if (other.children != null) {
return false;
}
} else if (!children.equals(other.children)) {
return false;
}
if (qName == null) {
if (other.qName != null) {
return false;
}
} else if (!qName.equals(other.qName)) {
return false;
}
return true;
}
}
......@@ -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;
......@@ -192,4 +194,51 @@ public class Note extends DataWithExtAttributes {
this.priority = priority;
}
@Override
public int hashCode () {
return Objects.hash(super.hashCode(), appliesTo, category, content, id, priority);
}
@Override
public boolean equals (Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Note other = (Note)obj;
if (appliesTo != other.appliesTo) {
return false;
}
if (category == null) {
if (other.category != null) {
return false;
}
} else if (!category.equals(other.category)) {
return false;
}
if (content == null) {
if (other.content != null) {
return false;
}
} else if (!content.equals(other.content)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (priority != other.priority) {
return false;
}
return true;
}
}
......@@ -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;
......@@ -99,4 +101,45 @@ public class StartXliffData extends DataWithExtAttributes {
getExtAttributes().setNamespace(prefix, namespaceURI);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), sourceLang, targetLang, version);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
StartXliffData other = (StartXliffData) obj;
if (sourceLang == null) {
if (other.sourceLang != null) {
return false;
}
} else if (!sourceLang.equals(other.sourceLang)) {
return false;
}
if (targetLang == null) {
if (other.targetLang != null) {
return false;
}
} else if (!targetLang.equals(other.targetLang)) {
return false;
}
if (version == null) {
if (other.version != null) {
return false;
}
} else if (!version.equals(other.version)) {
return false;
}
return true;
}
}
......@@ -16,6 +16,8 @@
package net.sf.okapi.lib.xliff2.glossary;
import java.util.Objects;
import net.sf.okapi.lib.xliff2.core.DataWithExtAttributes;
/**
......@@ -75,5 +77,39 @@ abstract class BaseGlossaryField extends DataWithExtAttributes {
public void setSource (String source) {
this.source = source;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), source, text);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BaseGlossaryField other = (BaseGlossaryField) obj;
if (source == null) {
if (other.source != null) {
return false;
}
} else if (!source.equals(other.source)) {
return false;
}
if (text == null) {
if (other.text != null) {
return false;
}
} else if (!text.equals(other.text)) {
return false;
}
return true;
}
}
......@@ -3585,6 +3585,10 @@ public class XLIFFReader implements Closeable {
}
unit.setMatches(matches);
popSpecialIds();
// Clear the list of isolated element because the one found in matches may conflict
// with the ones in the segments 9and we check only the ones in segments)
srcIsolated.clear();
trgIsolated.clear();
return;
}
}
......
......@@ -13,6 +13,7 @@ import net.sf.okapi.lib.xliff2.core.Note.AppliesTo;
import net.sf.okapi.lib.xliff2.matches.Match;
import net.sf.okapi.lib.xliff2.reader.Event;
import net.sf.okapi.lib.xliff2.reader.XLIFFReader;
import net.sf.okapi.lib.xliff2.reader.XLIFFReaderException;
import net.sf.okapi.lib.xliff2.test.U;
import org.junit.Test;
......@@ -796,6 +797,24 @@ public class UnitTest {
assertTrue(sameFragments(s1.getSource(), s2.getSource()));
}
@Test
public void testMatchWithIsolatedInMatch () {
String xlfStr = getTestXlfWithIsolatedInMatch();
Unit unit = getUnit(xlfStr, 1);
assertNotNull("There seems to be no unit in this xlf doc. ", unit);
}
@Test
public void testMissingIsolatedAttribute () {
try {
String xlfStr = getTestXlfWithMissingIsolatedAttribute();
getUnit(xlfStr, 1);
}
catch ( XLIFFReaderException e ) {
assertTrue(e.getMessage().contains("Missing isolated='yes' for opening code id='1'"));
}
}
@Test
public void testGetMatches() {
String xlfStr = getTestXlf();
......@@ -859,6 +878,46 @@ public class UnitTest {
assertEquals(0, unit.getMatches().size());
}
private String getTestXlfWithIsolatedInMatch () {
String xlString = "<xliff xmlns='urn:oasis:names:tc:xliff:document:2.0' version='2.0'\r\n" +
" srcLang='en' trgLang='fr'>\r\n" +
" <file id='1'>\r\n" +
" <unit id='1'>\r\n" +
" <mtc:matches xmlns:mtc=\"urn:oasis:names:tc:xliff:matches:2.0\">\r\n" +
" <mtc:match ref=\"#m1\" similarity=\"86.0\" matchSuitability=\"86.0\">\r\n" +
" <source>text <sc id='1' isolated=\"yes\"/></source>\r\n" +
" <target>texte <sc id='1' isolated=\"yes\"/></target>\r\n" +
" </mtc:match>\r\n" +
" </mtc:matches>\r\n" +
" <segment>\r\n" +
" <source><sm id=\"m1\" type=\"mtc:match\"/>Text <sc id='1'/><em startRef=\"m1\"/>stuff<ec startRef=\"1\"/></source>\r\n" +
" </segment>\r\n" +
" </unit>\r\n" +
" </file>\r\n" +
"</xliff>";
return xlString;
}
private String getTestXlfWithMissingIsolatedAttribute () {
String xlString = "<xliff xmlns='urn:oasis:names:tc:xliff:document:2.0' version='2.0'\r\n" +
" srcLang='en' trgLang='fr'>\r\n" +
" <file id='1'>\r\n" +
" <unit id='1'>\r\n" +
" <mtc:matches xmlns:mtc=\"urn:oasis:names:tc:xliff:matches:2.0\">\r\n" +
" <mtc:match ref=\"#m1\" similarity=\"86.0\" matchSuitability=\"86.0\">\r\n" +
" <source>text <sc id='1' isolated=\"yes\"/></source>\r\n" +
" <target>texte <sc id='1' isolated=\"yes\"/></target>\r\n" +
" </mtc:match>\r\n" +
" </mtc:matches>\r\n" +
" <segment>\r\n" + // <sc id='1'/> should have isolated="yes"
" <source><sm id=\"m1\" type=\"mtc:match\"/>Text <sc id='1'/><em startRef=\"m1\"/></source>\r\n" +
" </segment>\r\n" +
" </unit>\r\n" +
" </file>\r\n" +
"</xliff>";
return xlString;
}
private String getTestXlf() {
String xlfStr = "<?xml version=\"1.0\"?>\n" +
"<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\" version=\"2.0\" srcLang=\"en\" trgLang=\"de\"\n" +
......
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