Commit 7db011fc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

StringListComparator removed

parent a3c43f90
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Comparator used for list of strings.
*
* @author Piotr Gawron
*
*/
public class StringListComparator implements Comparator<List<String>> {
/**
* Default class logger.
*/
private static Logger logger = LogManager.getLogger();
/**
* String comparator used for comparing strings.
*/
private StringComparator stringComparator = new StringComparator();
/**
* Integer comparator used for comparing integers.
*/
private IntegerComparator integerComparator = new IntegerComparator();
@Override
public int compare(final List<String> arg0, final List<String> arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
if (arg0.size() != arg1.size()) {
logger.debug("String lists have different size: " + arg0.size() + ", " + arg1.size());
return integerComparator.compare(arg0.size(), arg1.size());
}
for (int i = 0; i < arg0.size(); i++) {
if (stringComparator.compare(arg0.get(i), arg1.get(i)) != 0) {
logger.debug("Strings in list different: \"" + arg0.get(i) + "\", \"" + arg1.get(i) + "\"");
return stringComparator.compare(arg0.get(i), arg1.get(i));
}
}
return 0;
}
}
package lcsb.mapviewer.common.comparator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class StringListComparatorTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testNotNullComparisonEqualLength() {
List<String> list1 = new ArrayList<>();
List<String> list2 = new ArrayList<>();
List<String> list3 = new ArrayList<>();
list1.add("str1");
list2.add("str2");
list3.add("str1");
StringListComparator comp = new StringListComparator();
assertTrue(comp.compare(list1, list3) == 0);
assertFalse(comp.compare(list1, list2) == 0);
assertFalse(comp.compare(list2, list3) == 0);
}
@Test
public void testNotNullComparisonDiffLength() {
List<String> list1 = new ArrayList<>();
List<String> list2 = new ArrayList<>();
list1.add("str1");
list2.add("str2");
list2.add("str1");
StringListComparator comp = new StringListComparator();
assertFalse(comp.compare(list1, list2) == 0);
}
@Test
public void testNullComparison() {
StringListComparator comp = new StringListComparator();
assertTrue(comp.compare(null, null) == 0);
assertFalse(comp.compare(new ArrayList<>(), null) == 0);
assertFalse(comp.compare(null, new ArrayList<>()) == 0);
}
}
......@@ -20,6 +20,7 @@ import org.xml.sax.SAXParseException;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.geometry.DoubleDimension;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.SingleLine;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.View;
import lcsb.mapviewer.model.map.MiriamRelationType;
......@@ -32,29 +33,6 @@ import lcsb.mapviewer.model.map.MiriamRelationType;
*/
public class CommonXmlParser {
private static class DimensionDouble extends Dimension2D {
private double width;
private double height;
@Override
public double getWidth() {
return width;
}
@Override
public double getHeight() {
return height;
}
@Override
public void setSize(final double width, final double height) {
this.width = width;
this.height = height;
}
}
public static final Set<MiriamRelationType> RELATION_TYPES_SUPPORTED_BY_CELL_DESIGNER = new HashSet<>();
{
......@@ -120,8 +98,7 @@ public class CommonXmlParser {
public Dimension2D getDimension(final Node node) {
double width = Double.parseDouble(XmlParser.getNodeAttr("width", node));
double height = Double.parseDouble(XmlParser.getNodeAttr("height", node));
DimensionDouble result = new DimensionDouble();
result.setSize(width, height);
DoubleDimension result = new DoubleDimension(width, height);
return result;
}
......@@ -147,7 +124,8 @@ public class CommonXmlParser {
*/
public Color getColor(final Node node) {
String color = XmlParser.getNodeAttr("color", node);
// cellDesigner has a bug that removes info about alpha when alpha is 0 (#1103)
// cellDesigner has a bug that removes info about alpha when alpha is 0
// (#1103)
color = StringUtils.leftPad(color, 8, "0");
return XmlParser.stringToColor(color);
......
......@@ -19,8 +19,8 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.comparator.IntegerComparator;
import lcsb.mapviewer.common.comparator.ListComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringListComparator;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
......@@ -506,7 +506,7 @@ public class RestAnnotationParser {
if (element.getFormerSymbols() == null || element.getFormerSymbols().size() == 0) {
element.setFormerSymbols(formerSymbols);
} else {
StringListComparator stringListComparator = new StringListComparator();
ListComparator<String> stringListComparator = new ListComparator<>(new StringComparator());
if (stringListComparator.compare(element.getFormerSymbols(), formerSymbols) != 0) {
logger.warn(elementUtils.getElementTag(element) + " Former symbols list different than default ["
+ formerSymbols + "][" + element.getFormerSymbols() + "]. Ignoring.");
......
......@@ -4,8 +4,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.comparator.ListComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringListComparator;
public class SbmlFunctionComparator extends Comparator<SbmlFunction> {
private static Logger logger = LogManager.getLogger();
......@@ -17,7 +17,7 @@ public class SbmlFunctionComparator extends Comparator<SbmlFunction> {
@Override
protected int internalCompare(final SbmlFunction arg0, final SbmlFunction arg1) {
StringComparator stringComparator = new StringComparator();
StringListComparator stringListComparator = new StringListComparator();
ListComparator<String> stringListComparator = new ListComparator<>(stringComparator);
if (stringComparator.compare(arg0.getFunctionId(), arg1.getFunctionId()) != 0) {
logger.debug("functionId different");
return stringComparator.compare(arg0.getFunctionId(), arg1.getFunctionId());
......
......@@ -8,10 +8,10 @@ import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.BooleanComparator;
import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.comparator.IntegerComparator;
import lcsb.mapviewer.common.comparator.ListComparator;
import lcsb.mapviewer.common.comparator.PointComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringListComparator;
import lcsb.mapviewer.model.graphics.PolylineDataComparator;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamDataComparator;
......@@ -130,7 +130,7 @@ public class ReactionComparator extends Comparator<Reaction> {
return doubleComparator.compare(arg0.getUpperBound(), arg1.getUpperBound());
}
StringListComparator stringListComparator = new StringListComparator();
ListComparator<String> stringListComparator = new ListComparator<>(stringComparator);
if (stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()) != 0) {
logger.debug("Synonyms dataset different");
......
......@@ -9,9 +9,9 @@ import lcsb.mapviewer.common.comparator.ColorComparator;
import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.comparator.EnumComparator;
import lcsb.mapviewer.common.comparator.IntegerComparator;
import lcsb.mapviewer.common.comparator.ListComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringListComparator;
import lcsb.mapviewer.model.graphics.HorizontalAlign;
import lcsb.mapviewer.model.graphics.VerticalAlign;
import lcsb.mapviewer.model.map.MiriamData;
......@@ -168,7 +168,7 @@ public class ElementComparator extends Comparator<Element> {
return stringComparator.compare(arg0.getFormula(), arg1.getFormula());
}
StringListComparator stringListComparator = new StringListComparator();
ListComparator<String> stringListComparator = new ListComparator<>(stringComparator);
if (stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()) != 0) {
logger.debug("List of synonyms different");
......
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