Commit 1c9d80be authored by Piotr Gawron's avatar Piotr Gawron
Browse files

StringSetComparator removed

parent 7db011fc
......@@ -11,7 +11,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.annotation.cache.CachableInterface;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerChemical;
......@@ -437,7 +438,7 @@ public abstract class ElementAnnotator extends CachableInterface {
} else if (newCollection == null || newCollection.size() == 0) {
return false;
} else {
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
......
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Comparator used for comparing sets of strings.
*
* @author Piotr Gawron
*
*/
public class StringSetComparator implements Comparator<Set<String>> {
/**
* Default class logger.
*/
private Logger logger = LogManager.getLogger();
@Override
public int compare(final Set<String> arg0, final Set<String> arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
for (final String string : arg1) {
if (!arg0.contains(string)) {
logger.debug(string + " couldn't be found in " + arg0);
return 1;
}
}
for (final String string : arg0) {
if (!arg1.contains(string)) {
logger.debug(string + " couldn't be found in " + arg1);
return -1;
}
}
return 0;
}
}
......@@ -14,8 +14,6 @@ import org.junit.runners.Suite.SuiteClasses;
ListComparatorTest.class,
PointComparatorTest.class,
StringComparatorTest.class,
StringListComparatorTest.class,
StringSetComparatorTest.class,
SetComparatorTest.class,
})
public class AllComparatorTests {
......
package lcsb.mapviewer.common.comparator;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class StringSetComparatorTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testNotNullComparisonEqualLength() {
Set<String> list1 = new HashSet<>();
Set<String> list2 = new HashSet<>();
Set<String> list3 = new HashSet<>();
list1.add("str1");
list1.add("x");
list2.add("str2");
list2.add("x");
list3.add("x");
list3.add("str1");
StringSetComparator comp = new StringSetComparator();
assertTrue(comp.compare(list1, list3) == 0);
assertFalse(comp.compare(list1, list2) == 0);
assertFalse(comp.compare(list2, list3) == 0);
}
@Test
public void testNotNullComparisonDiffLength() {
Set<String> list1 = new HashSet<>();
Set<String> list2 = new HashSet<>();
list1.add("str1");
list2.add("str2");
list2.add("str1");
StringSetComparator comp = new StringSetComparator();
assertFalse(comp.compare(list1, list2) == 0);
assertFalse(comp.compare(list2, list1) == 0);
}
@Test
public void testNullComparison() {
StringSetComparator comp = new StringSetComparator();
assertTrue(comp.compare(null, null) == 0);
assertFalse(comp.compare(new HashSet<>(), null) == 0);
assertFalse(comp.compare(null, new HashSet<>()) == 0);
}
}
......@@ -20,8 +20,8 @@ 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.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.common.exception.NotImplementedException;
......@@ -478,7 +478,7 @@ public class RestAnnotationParser {
if (element.getSynonyms() == null || element.getSynonyms().size() == 0) {
element.setSynonyms(synonyms);
} else {
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
Set<String> set1 = new HashSet<String>();
Set<String> set2 = new HashSet<String>();
set1.addAll(element.getSynonyms());
......
......@@ -8,7 +8,8 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
......@@ -54,7 +55,7 @@ public class AntisenseRnaComparator extends Comparator<AntisenseRna> {
@Override
protected int internalCompare(final AntisenseRna arg0, final AntisenseRna arg1) {
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
......
......@@ -8,7 +8,8 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -55,7 +56,7 @@ public class GeneComparator extends Comparator<Gene> {
@Override
protected int internalCompare(final Gene arg0, final Gene arg1) {
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
......
......@@ -8,7 +8,8 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.StructuralStateComparator;
......@@ -60,7 +61,7 @@ public class ProteinComparator extends Comparator<Protein> {
@Override
protected int internalCompare(final Protein arg0, final Protein arg1) {
StructuralStateComparator structuralStateComparator = new StructuralStateComparator(epsilon);
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
if (structuralStateComparator.compare(arg0.getStructuralState(), arg1.getStructuralState()) != 0) {
logger.debug("structural state different: " + arg0.getStructuralState() + ", " + arg1.getStructuralState());
......
......@@ -8,7 +8,8 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Comparator;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.comparator.StringSetComparator;
import lcsb.mapviewer.common.comparator.SetComparator;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
......@@ -54,7 +55,7 @@ public class RnaComparator extends Comparator<Rna> {
@Override
protected int internalCompare(final Rna arg0, final Rna arg1) {
StringSetComparator stringSetComparator = new StringSetComparator();
SetComparator<String> stringSetComparator = new SetComparator<>(new StringComparator());
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
......
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