Commit 40db452e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

comparator checks z-index

parent 4a1afe90
......@@ -8,7 +8,10 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
public abstract class Comparator<T extends Object> implements java.util.Comparator<T> {
Logger logger = Logger.getLogger(Comparator.class);
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(Comparator.class);
private Class<T> comparatorClazz;
private boolean exactClassMatch;
private List<Comparator<? extends T>> subClassComparatorList = new ArrayList<>();
......
......@@ -10,18 +10,18 @@ import java.util.Comparator;
*/
public class IntegerComparator implements Comparator<Integer> {
@Override
public int compare(Integer arg0, Integer arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
return arg0.compareTo(arg1);
}
@Override
public int compare(Integer arg0, Integer arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
return arg0.compareTo(arg1);
}
}
......@@ -6,6 +6,7 @@ import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.ColorComparator;
import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.comparator.IntegerComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringListComparator;
......@@ -83,6 +84,13 @@ public class ElementComparator extends Comparator<Element> {
return doubleComparator.compare(arg0.getY(), arg1.getY());
}
IntegerComparator integerComparator = new IntegerComparator();
if (integerComparator.compare(arg0.getZ(), arg1.getZ()) != 0) {
logger.debug("Z-index different: " + arg0.getZ() + ", " + arg1.getZ());
return integerComparator.compare(arg0.getZ(), arg1.getZ());
}
if (doubleComparator.compare(arg0.getWidth(), arg1.getWidth()) != 0) {
logger.debug("Width different: " + arg0.getWidth() + ", " + arg1.getWidth());
return doubleComparator.compare(arg0.getWidth(), arg1.getWidth());
......
......@@ -318,4 +318,38 @@ public class ElementComparatorTest {
}
}
@Test
public void testCompareZIndex() throws Exception {
try {
SimpleMolecule species1 = createSimpleMolecule();
SimpleMolecule species2 = createSimpleMolecule();
species1.setZ(12);
assertTrue(comparator.compare(species1, species2) != 0);
assertTrue(comparator.compare(species2, species1) != 0);
species1 = createSimpleMolecule();
species2 = createSimpleMolecule();
species1.setZ(12);
species2.setZ(13);
assertTrue(comparator.compare(species1, species2) != 0);
assertTrue(comparator.compare(species2, species1) != 0);
species1 = createSimpleMolecule();
species2 = createSimpleMolecule();
species1.setZ(12);
species2.setZ(12);
assertEquals(0, comparator.compare(species1, species2));
assertEquals(0, comparator.compare(species2, species1));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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