From 2e02f011c7c992314d697ca63a88fed3a383ac27 Mon Sep 17 00:00:00 2001 From: "piotr.gawron" <piotr.gawron@uni-new> Date: Mon, 26 Sep 2016 11:13:56 +0200 Subject: [PATCH] whitespace characters --- .../annotators/AnnotatorException.java | 96 +- .../annotators/ChebiSearchException.java | 64 +- .../annotators/GoSearchException.java | 60 +- .../services/annotators/UniprotAnnotator.java | 502 ++++---- .../annotators/UniprotSearchException.java | 60 +- .../genome/FileNotAvailableException.java | 106 +- .../services/genome/package-info.java | 8 +- .../annotators/AllAnnotatorTests.java | 42 +- .../annotators/AnnotatorExceptionTest.java | 60 +- .../services/genome/AllGenomeTests.java | 22 +- .../common/comparator/AllComparatorTests.java | 38 +- .../comparator/BooleanComparatorTest.java | 72 +- .../comparator/ColorComparatorTest.java | 76 +- .../comparator/DoubleComparatorTest.java | 88 +- .../comparator/IntegerComparatorTest.java | 70 +- .../comparator/PointComparatorTest.java | 94 +- .../comparator/StringComparatorTest.java | 88 +- .../comparator/StringListComparatorTest.java | 112 +- .../comparator/StringSetComparatorTest.java | 122 +- .../common/exception/AllExceptionTests.java | 24 +- .../InvalidArgumentExceptionTest.java | 78 +- .../exception/InvalidClassExceptionTest.java | 58 +- .../exception/InvalidStateExceptionTest.java | 78 +- .../InvalidXmlSchemaExceptionTest.java | 78 +- .../NotImplementedExceptionTest.java | 58 +- .../common/geometry/AllGeometryTests.java | 32 +- .../common/geometry/CompositeStrokeTest.java | 52 +- .../geometry/EllipseTransformationTest.java | 164 +-- .../geometry/LineTransformationTest.java | 428 +++---- .../geometry/PointTransformationTest.java | 88 +- .../common/geometry/TextAlignmentTest.java | 58 +- .../CellDesignerParserException.java | 114 +- .../celldesigner/InvalidGroupException.java | 118 +- .../model/celldesigner/LayerXmlParser.java | 1070 ++++++++--------- .../celldesigner/AllCellDesignerTests.java | 72 +- .../CellDesignerParserExceptionTest.java | 104 +- .../InvalidGroupExceptionTest.java | 54 +- .../reaction/AllReactionTests.java | 38 +- .../graphics/reaction/ReactionConverter.java | 878 +++++++------- .../model/map/reaction/AndOperator.java | 134 +-- .../map/reaction/AssociationOperator.java | 128 +- .../map/reaction/DissociationOperator.java | 126 +- .../model/map/reaction/NandOperator.java | 124 +- .../model/map/reaction/NodeOperator.java | 530 ++++---- .../map/reaction/NodeOperatorComparator.java | 270 ++--- .../model/map/reaction/OrOperator.java | 136 +-- .../map/reaction/ReactionComparator.java | 420 +++---- .../map/reaction/ReactionNodeComparator.java | 202 ++-- .../model/map/reaction/SplitOperator.java | 126 +- .../map/reaction/TruncationOperator.java | 126 +- .../model/map/reaction/UnknownOperator.java | 126 +- .../model/map/species/ProteinComparator.java | 240 ++-- .../model/map/species/SpeciesComparator.java | 464 +++---- .../model/map/graph/AllGraphTests.java | 30 +- .../graph/DataMiningSetComparatorTest.java | 230 ++-- .../model/map/graph/DataMiningSetTest.java | 166 +-- .../model/map/graph/DataMiningTypeTest.java | 60 +- .../model/map/layout/AllLayoutTests.java | 52 +- .../model/map/layout/ColorSchemaTest.java | 438 +++---- .../layout/GeneVariationColorSchemaTest.java | 248 ++-- .../model/map/layout/GeneVariationTest.java | 202 ++-- .../map/layout/GenericColorSchemaTest.java | 162 +-- .../InvalidColorSchemaExceptionTest.java | 114 +- .../model/map/layout/LayoutStatusTest.java | 60 +- .../model/map/layout/LayoutTest.java | 334 ++--- .../ReferenceGenomeGeneMappingTest.java | 108 +- .../model/map/layout/ReferenceGenomeTest.java | 178 +-- .../map/layout/ReferenceGenomeTypeTest.java | 70 +- .../model/AliasSubmodelConnectionTest.java | 188 +-- .../model/ModelSubmodelConnectionTest.java | 204 ++-- .../model/map/model/SubmodelTypeTest.java | 60 +- .../reaction/AbstractNodeComparatorTest.java | 152 +-- .../model/map/reaction/AllReactionTests.java | 62 +- .../model/map/reaction/AndOperatorTest.java | 208 ++-- .../map/reaction/AssociationOperatorTest.java | 178 +-- .../reaction/DissociationOperatorTest.java | 178 +-- .../model/map/reaction/ModifierTest.java | 156 +-- .../model/map/reaction/NandOperatorTest.java | 178 +-- .../model/map/reaction/NodeOperatorMock.java | 60 +- .../model/map/reaction/NodeOperatorTest.java | 420 +++---- .../model/map/reaction/OrOperatorTest.java | 178 +-- .../model/map/reaction/ProductTest.java | 154 +-- .../model/map/reaction/ReactantTest.java | 156 +-- .../model/map/reaction/SplitOperatorTest.java | 176 +-- .../map/reaction/TruncationOperatorTest.java | 176 +-- .../map/reaction/UnknownOperatorTest.java | 180 +-- .../model/map/species/SpeciesTest.java | 638 +++++----- .../map/statistics/AllStatisticsTests.java | 26 +- .../map/statistics/SearchHistoryTest.java | 126 +- .../model/map/statistics/SearchTypeTest.java | 56 +- .../persist/dao/cache/BigFileEntryDao.java | 102 +- .../persist/dao/cache/CacheQueryDao.java | 116 +- .../persist/dao/cache/CacheTypeDao.java | 90 +- .../dao/cache/UploadedFileEntryDao.java | 68 +- .../mapviewer/persist/dao/log/LogDao.java | 80 +- .../utils/comparators/ANodeComparator.java | 466 +++---- .../ComplexAndCandidateSetComparator.java | 72 +- .../ComplexAndDefinedSetComparator.java | 72 +- .../ComplexAndOtherEntityComparator.java | 72 +- .../GeneAndDefinedSetComparator.java | 72 +- .../GeneAndOtherEntityComparator.java | 72 +- .../comparators/IonAndComplexComparator.java | 180 +-- .../IonAndSimpleEntityComparator.java | 102 +- .../MoleculeAndComplexComparator.java | 176 +-- .../MoleculeAndSimpleEntityComparator.java | 102 +- .../utils/comparators/NodeComparator.java | 264 ++-- .../ProteinAndOtherEntityComparator.java | 72 +- .../ProteinAndPolymerComparator.java | 212 ++-- .../search/comment/CommentDetails.java | 174 +-- .../comment/FullCommentViewFactory.java | 168 +-- .../search/data/ElementIdentifier.java | 500 ++++---- .../search/data/FullReactionViewFactory.java | 270 ++--- .../services/search/db/DbSearchCriteria.java | 334 ++--- .../services/search/db/TargetDetails.java | 142 +-- .../search/layout/FullLayoutAliasView.java | 230 ++-- .../layout/FullLayoutAliasViewFactory.java | 98 +- .../layout/LightLayoutAliasViewFactory.java | 74 +- .../LightLayoutReactionViewFactory.java | 76 +- .../utils/data/ColorSchemaColumn.java | 294 ++--- .../services/utils/data/ColorSchemaType.java | 42 +- .../search/comment/CommentDetailsTest.java | 74 +- .../services/search/db/AllSearchDbTests.java | 40 +- .../search/layout/AllSearchLayoutTests.java | 28 +- .../utils/gmap/CoordinationConverterTest.java | 252 ++-- 124 files changed, 10062 insertions(+), 10062 deletions(-) diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorException.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorException.java index 34ebfe92ee..510e850d99 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorException.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorException.java @@ -1,48 +1,48 @@ -package lcsb.mapviewer.annotation.services.annotators; - -/** - * Exception thrown when there is a problem with annotator. - * - * @author Piotr Gawron - * - */ -public class AnnotatorException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - * - * @param exception - * original exception - */ - public AnnotatorException(Exception exception) { - super(exception); - } - - /** - * Default constructor. - * - * @param message - * message associated with exception - * @param exception - * original exception - */ - public AnnotatorException(String message, Exception exception) { - super(message, exception); - } - - /** - * Default constructor. - * - * @param message - * message associated with exception - */ - public AnnotatorException(String message) { - super(message); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +/** + * Exception thrown when there is a problem with annotator. + * + * @author Piotr Gawron + * + */ +public class AnnotatorException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + * + * @param exception + * original exception + */ + public AnnotatorException(Exception exception) { + super(exception); + } + + /** + * Default constructor. + * + * @param message + * message associated with exception + * @param exception + * original exception + */ + public AnnotatorException(String message, Exception exception) { + super(message, exception); + } + + /** + * Default constructor. + * + * @param message + * message associated with exception + */ + public AnnotatorException(String message) { + super(message); + } + +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiSearchException.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiSearchException.java index 1ca1eb2705..e872bee192 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiSearchException.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiSearchException.java @@ -1,32 +1,32 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import lcsb.mapviewer.annotation.data.Chebi; - -/** - * Exception that should be thrown when there is a problem with finding - * information about {@link Chebi} elements. - * - * @author Piotr Gawron - * - */ -public class ChebiSearchException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a new exception with the specified detail message and cause. - * - * @param message - * the detail message - * @param cause - * the cause (A <tt>null</tt> value is permitted, and indicates that - * the cause is nonexistent or unknown.) - */ - public ChebiSearchException(String message, Throwable cause) { - super(message, cause); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +import lcsb.mapviewer.annotation.data.Chebi; + +/** + * Exception that should be thrown when there is a problem with finding + * information about {@link Chebi} elements. + * + * @author Piotr Gawron + * + */ +public class ChebiSearchException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message + * the detail message + * @param cause + * the cause (A <tt>null</tt> value is permitted, and indicates that + * the cause is nonexistent or unknown.) + */ + public ChebiSearchException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/GoSearchException.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/GoSearchException.java index be32c487da..2719c69d62 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/GoSearchException.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/GoSearchException.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.annotation.services.annotators; - -/** - * Exception that should be thrown when there is a problem with finding - * information about Go elements. - * - * @author Piotr Gawron - * - */ -public class GoSearchException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a new exception with the specified detail message and cause. - * - * @param message - * the detail message - * @param cause - * the cause (A <tt>null</tt> value is permitted, and indicates that - * the cause is nonexistent or unknown.) - */ - public GoSearchException(String message, Throwable cause) { - super(message, cause); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +/** + * Exception that should be thrown when there is a problem with finding + * information about Go elements. + * + * @author Piotr Gawron + * + */ +public class GoSearchException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message + * the detail message + * @param cause + * the cause (A <tt>null</tt> value is permitted, and indicates that + * the cause is nonexistent or unknown.) + */ + public GoSearchException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotator.java index 2c119cb852..705d8e1586 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotator.java @@ -1,251 +1,251 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; -import lcsb.mapviewer.annotation.cache.SourceNotAvailable; -import lcsb.mapviewer.annotation.cache.WebPageDownloader; -import lcsb.mapviewer.annotation.services.ExternalServiceStatus; -import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; -import lcsb.mapviewer.annotation.services.IExternalService; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.AnnotatedObject; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.model.map.species.Rna; -import lcsb.mapviewer.modelutils.map.ElementUtils; - -/** - * This is a class that implements a backend to uniprot restfull API. - * - * @author Piotr Gawron - * - */ -public class UniprotAnnotator extends ElementAnnotator implements IExternalService { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(UniprotAnnotator.class); - - /** - * Pattern used for finding hgnc symbol from uniprot info page . - */ - private Pattern uniprotToHgnc = Pattern.compile("GN[\\ ]+Name=([^;\\ ]+)"); - - /** - * Pattern used for finding entrez identifier from uniprot info page . - */ - private Pattern uniprotToEntrez = Pattern.compile("DR[\\ ]+GeneID;\\ ([^;\\ ]+)"); - - /** - * Class used for some simple operations on {@link AnnotatedObject} elements. - */ - private ElementUtils elementUtils = new ElementUtils(); - - /** - * Default constructor. - */ - public UniprotAnnotator() { - super(UniprotAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false); - } - - @Override - public ExternalServiceStatus getServiceStatus() { - ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); - - GeneralCacheInterface cacheCopy = getCache(); - this.setCache(null); - - try { - MiriamData md = uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, "P37840")); - - status.setStatus(ExternalServiceStatusType.OK); - if (md == null) { - status.setStatus(ExternalServiceStatusType.DOWN); - } else if (!md.getResource().equalsIgnoreCase("SNCA")) { - status.setStatus(ExternalServiceStatusType.CHANGED); - } - } catch (Exception e) { - logger.error(status.getName() + " is down", e); - status.setStatus(ExternalServiceStatusType.DOWN); - } - this.setCache(cacheCopy); - return status; - } - - @Override - public void annotateElement(AnnotatedObject object) throws AnnotatorException { - if (isAnnotatable(object)) { - String uniprotId = object.getName(); - boolean uniprotFound = false; - for (MiriamData md : object.getMiriamData()) { - if (md.getDataType().equals(MiriamType.UNIPROT)) { - uniprotId = md.getResource(); - uniprotFound = true; - } - } - - if (uniprotId == null || uniprotId.equals("")) { - return; - } - - String accessUrl = getUniprotUrl(uniprotId); - try { - String pageContent = getWebPageContent(accessUrl); - // check if we have data over there - if (!pageContent.contains("<title>Error</title>")) { - Set<MiriamData> annotations = new HashSet<MiriamData>(); - annotations.addAll(parseHgnc(pageContent)); - annotations.addAll(parseEntrez(pageContent)); - if (!uniprotFound) { - annotations.add(new MiriamData(MiriamType.UNIPROT, uniprotId)); - } - object.addMiriamData(annotations); - } else { - // this means that entry with a given uniprot id doesn't exist - if (uniprotFound) { - logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId); - } - } - } catch (FileNotFoundException exception) { - // this means that entry with a given uniprot id doesn't exist - if (uniprotFound) { - logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId); - } - } catch (IOException exception) { - throw new AnnotatorException(exception); - } - } - } - - /** - * Returns url to uniprot restfull API about uniprot entry. - * - * @param uniprotId - * uniprot identifier - * @return url to uniprot restfull API about uniprot entry - */ - private String getUniprotUrl(String uniprotId) { - return "http://www.uniprot.org/uniprot/" + uniprotId + ".txt"; - } - - /** - * Parse uniprot webpage to find information about {@link MiriamType#ENTREZ} - * and returns them. - * - * @param pageContent - * uniprot info page - * @return set of entrez identifiers found on the webpage - */ - private Collection<MiriamData> parseEntrez(String pageContent) { - Collection<MiriamData> result = new HashSet<MiriamData>(); - Matcher m = uniprotToEntrez.matcher(pageContent); - if (m.find()) { - result.add(new MiriamData(MiriamType.ENTREZ, m.group(1))); - } - return result; - } - - /** - * Parse uniprot webpage to find information about - * {@link MiriamType#HGNC_SYMBOL} and returns them. - * - * @param pageContent - * uniprot info page - * @return set of entrez identifiers found on the webpage - */ - private Collection<MiriamData> parseHgnc(String pageContent) { - Collection<MiriamData> result = new HashSet<MiriamData>(); - Matcher m = uniprotToHgnc.matcher(pageContent); - if (m.find()) { - result.add(new MiriamData(MiriamType.HGNC_SYMBOL, m.group(1))); - } - return result; - } - - @Override - public Object refreshCacheQuery(Object query) throws SourceNotAvailable { - String name; - String result = null; - if (query instanceof String) { - name = (String) query; - if (name.startsWith("http")) { - try { - result = getWebPageContent(name); - } catch (IOException e) { - throw new SourceNotAvailable(e); - } - } else { - throw new InvalidArgumentException("Don't know what to do with query: " + query); - } - } else { - throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); - } - return result; - } - - /** - * Transform uniprot identifier into hgnc name. - * - * @param uniprot - * {@link MiriamData} with uniprot identifier - * @return {@link MiriamData} with hgnc name - * @throws UniprotSearchException - * thrown when there is aproblem with accessing external database - */ - public MiriamData uniProtToHgnc(MiriamData uniprot) throws UniprotSearchException { - if (uniprot == null) { - return null; - } - - if (!MiriamType.UNIPROT.equals(uniprot.getDataType())) { - throw new InvalidArgumentException(MiriamType.UNIPROT + " expected."); - } - - String accessUrl = getUniprotUrl(uniprot.getResource()); - try { - String pageContent = getWebPageContent(accessUrl); - Collection<MiriamData> collection = parseHgnc(pageContent); - if (collection.size() > 0) { - return collection.iterator().next(); - } else { - return null; - } - } catch (IOException e) { - throw new UniprotSearchException("Problem with accessing uniprot webpage", e); - } - - } - - @Override - public String getCommonName() { - return MiriamType.UNIPROT.getCommonName(); - } - - @Override - public String getUrl() { - return MiriamType.UNIPROT.getDbHomepage(); - } - - @Override - protected WebPageDownloader getWebPageDownloader() { - return super.getWebPageDownloader(); - } - - @Override - protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { - super.setWebPageDownloader(webPageDownloader); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; +import lcsb.mapviewer.annotation.cache.SourceNotAvailable; +import lcsb.mapviewer.annotation.cache.WebPageDownloader; +import lcsb.mapviewer.annotation.services.ExternalServiceStatus; +import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; +import lcsb.mapviewer.annotation.services.IExternalService; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.AnnotatedObject; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.species.Gene; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.Rna; +import lcsb.mapviewer.modelutils.map.ElementUtils; + +/** + * This is a class that implements a backend to uniprot restfull API. + * + * @author Piotr Gawron + * + */ +public class UniprotAnnotator extends ElementAnnotator implements IExternalService { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(UniprotAnnotator.class); + + /** + * Pattern used for finding hgnc symbol from uniprot info page . + */ + private Pattern uniprotToHgnc = Pattern.compile("GN[\\ ]+Name=([^;\\ ]+)"); + + /** + * Pattern used for finding entrez identifier from uniprot info page . + */ + private Pattern uniprotToEntrez = Pattern.compile("DR[\\ ]+GeneID;\\ ([^;\\ ]+)"); + + /** + * Class used for some simple operations on {@link AnnotatedObject} elements. + */ + private ElementUtils elementUtils = new ElementUtils(); + + /** + * Default constructor. + */ + public UniprotAnnotator() { + super(UniprotAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false); + } + + @Override + public ExternalServiceStatus getServiceStatus() { + ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); + + GeneralCacheInterface cacheCopy = getCache(); + this.setCache(null); + + try { + MiriamData md = uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, "P37840")); + + status.setStatus(ExternalServiceStatusType.OK); + if (md == null) { + status.setStatus(ExternalServiceStatusType.DOWN); + } else if (!md.getResource().equalsIgnoreCase("SNCA")) { + status.setStatus(ExternalServiceStatusType.CHANGED); + } + } catch (Exception e) { + logger.error(status.getName() + " is down", e); + status.setStatus(ExternalServiceStatusType.DOWN); + } + this.setCache(cacheCopy); + return status; + } + + @Override + public void annotateElement(AnnotatedObject object) throws AnnotatorException { + if (isAnnotatable(object)) { + String uniprotId = object.getName(); + boolean uniprotFound = false; + for (MiriamData md : object.getMiriamData()) { + if (md.getDataType().equals(MiriamType.UNIPROT)) { + uniprotId = md.getResource(); + uniprotFound = true; + } + } + + if (uniprotId == null || uniprotId.equals("")) { + return; + } + + String accessUrl = getUniprotUrl(uniprotId); + try { + String pageContent = getWebPageContent(accessUrl); + // check if we have data over there + if (!pageContent.contains("<title>Error</title>")) { + Set<MiriamData> annotations = new HashSet<MiriamData>(); + annotations.addAll(parseHgnc(pageContent)); + annotations.addAll(parseEntrez(pageContent)); + if (!uniprotFound) { + annotations.add(new MiriamData(MiriamType.UNIPROT, uniprotId)); + } + object.addMiriamData(annotations); + } else { + // this means that entry with a given uniprot id doesn't exist + if (uniprotFound) { + logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId); + } + } + } catch (FileNotFoundException exception) { + // this means that entry with a given uniprot id doesn't exist + if (uniprotFound) { + logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId); + } + } catch (IOException exception) { + throw new AnnotatorException(exception); + } + } + } + + /** + * Returns url to uniprot restfull API about uniprot entry. + * + * @param uniprotId + * uniprot identifier + * @return url to uniprot restfull API about uniprot entry + */ + private String getUniprotUrl(String uniprotId) { + return "http://www.uniprot.org/uniprot/" + uniprotId + ".txt"; + } + + /** + * Parse uniprot webpage to find information about {@link MiriamType#ENTREZ} + * and returns them. + * + * @param pageContent + * uniprot info page + * @return set of entrez identifiers found on the webpage + */ + private Collection<MiriamData> parseEntrez(String pageContent) { + Collection<MiriamData> result = new HashSet<MiriamData>(); + Matcher m = uniprotToEntrez.matcher(pageContent); + if (m.find()) { + result.add(new MiriamData(MiriamType.ENTREZ, m.group(1))); + } + return result; + } + + /** + * Parse uniprot webpage to find information about + * {@link MiriamType#HGNC_SYMBOL} and returns them. + * + * @param pageContent + * uniprot info page + * @return set of entrez identifiers found on the webpage + */ + private Collection<MiriamData> parseHgnc(String pageContent) { + Collection<MiriamData> result = new HashSet<MiriamData>(); + Matcher m = uniprotToHgnc.matcher(pageContent); + if (m.find()) { + result.add(new MiriamData(MiriamType.HGNC_SYMBOL, m.group(1))); + } + return result; + } + + @Override + public Object refreshCacheQuery(Object query) throws SourceNotAvailable { + String name; + String result = null; + if (query instanceof String) { + name = (String) query; + if (name.startsWith("http")) { + try { + result = getWebPageContent(name); + } catch (IOException e) { + throw new SourceNotAvailable(e); + } + } else { + throw new InvalidArgumentException("Don't know what to do with query: " + query); + } + } else { + throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); + } + return result; + } + + /** + * Transform uniprot identifier into hgnc name. + * + * @param uniprot + * {@link MiriamData} with uniprot identifier + * @return {@link MiriamData} with hgnc name + * @throws UniprotSearchException + * thrown when there is aproblem with accessing external database + */ + public MiriamData uniProtToHgnc(MiriamData uniprot) throws UniprotSearchException { + if (uniprot == null) { + return null; + } + + if (!MiriamType.UNIPROT.equals(uniprot.getDataType())) { + throw new InvalidArgumentException(MiriamType.UNIPROT + " expected."); + } + + String accessUrl = getUniprotUrl(uniprot.getResource()); + try { + String pageContent = getWebPageContent(accessUrl); + Collection<MiriamData> collection = parseHgnc(pageContent); + if (collection.size() > 0) { + return collection.iterator().next(); + } else { + return null; + } + } catch (IOException e) { + throw new UniprotSearchException("Problem with accessing uniprot webpage", e); + } + + } + + @Override + public String getCommonName() { + return MiriamType.UNIPROT.getCommonName(); + } + + @Override + public String getUrl() { + return MiriamType.UNIPROT.getDbHomepage(); + } + + @Override + protected WebPageDownloader getWebPageDownloader() { + return super.getWebPageDownloader(); + } + + @Override + protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { + super.setWebPageDownloader(webPageDownloader); + } + +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotSearchException.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotSearchException.java index 6b12f60e3c..f3d40ee117 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotSearchException.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/UniprotSearchException.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.annotation.services.annotators; - -/** - * Exception that should be thrown when there is a problem with finding - * information about Uniprot. - * - * @author Piotr Gawron - * - */ -public class UniprotSearchException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a new exception with the specified detail message and cause. - * - * @param message - * the detail message - * @param cause - * the cause (A <tt>null</tt> value is permitted, and indicates that - * the cause is nonexistent or unknown.) - */ - public UniprotSearchException(String message, Throwable cause) { - super(message, cause); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +/** + * Exception that should be thrown when there is a problem with finding + * information about Uniprot. + * + * @author Piotr Gawron + * + */ +public class UniprotSearchException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message + * the detail message + * @param cause + * the cause (A <tt>null</tt> value is permitted, and indicates that + * the cause is nonexistent or unknown.) + */ + public UniprotSearchException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/FileNotAvailableException.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/FileNotAvailableException.java index ec70ea6b19..1a0af3ac0c 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/FileNotAvailableException.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/FileNotAvailableException.java @@ -1,53 +1,53 @@ -package lcsb.mapviewer.annotation.services.genome; - -/** - * Exception taht should be thrown when file for specific genome version id not - * available. - * - * @author Piotr Gawron - * - */ -public class FileNotAvailableException extends Exception { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public FileNotAvailableException() { - } - - /** - * Default constructor. - * - * @param message - * error message - */ - public FileNotAvailableException(String message) { - super(message); - } - - /** - * Default constructor. - * - * @param cause - * error cause - */ - public FileNotAvailableException(Throwable cause) { - super(cause); - } - - /** - * Default constructor. - * - * @param message - * error message - * @param cause - * error cause - */ - public FileNotAvailableException(String message, Throwable cause) { - super(message, cause); - } -} +package lcsb.mapviewer.annotation.services.genome; + +/** + * Exception taht should be thrown when file for specific genome version id not + * available. + * + * @author Piotr Gawron + * + */ +public class FileNotAvailableException extends Exception { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public FileNotAvailableException() { + } + + /** + * Default constructor. + * + * @param message + * error message + */ + public FileNotAvailableException(String message) { + super(message); + } + + /** + * Default constructor. + * + * @param cause + * error cause + */ + public FileNotAvailableException(Throwable cause) { + super(cause); + } + + /** + * Default constructor. + * + * @param message + * error message + * @param cause + * error cause + */ + public FileNotAvailableException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/package-info.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/package-info.java index 8c342028a1..e36710236f 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/package-info.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/genome/package-info.java @@ -1,4 +1,4 @@ -/** - * This package contains classes that access reference genome information. - */ -package lcsb.mapviewer.annotation.services.genome; +/** + * This package contains classes that access reference genome information. + */ +package lcsb.mapviewer.annotation.services.genome; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java index 8f704f7104..71dae4246b 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AllAnnotatorTests.java @@ -1,21 +1,21 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ AnnotatorExceptionTest.class, // - BiocompendiumAnnotatorTest.class, // - ChebiAnnotatorTest.class, // - ElementAnnotatorTest.class, // - EnsemblAnnotatorTest.class, // - EntrezAnnotatorTest.class, // - GoAnnotatorTest.class, // - HgncAnnotatorTest.class, // - ReconAnnotatorTest.class, // - UniprotAnnotatorTest.class, // -}) -public class AllAnnotatorTests { - -} +package lcsb.mapviewer.annotation.services.annotators; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ AnnotatorExceptionTest.class, // + BiocompendiumAnnotatorTest.class, // + ChebiAnnotatorTest.class, // + ElementAnnotatorTest.class, // + EnsemblAnnotatorTest.class, // + EntrezAnnotatorTest.class, // + GoAnnotatorTest.class, // + HgncAnnotatorTest.class, // + ReconAnnotatorTest.class, // + UniprotAnnotatorTest.class, // +}) +public class AllAnnotatorTests { + +} diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorExceptionTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorExceptionTest.java index 68f6a01765..c8ecdc1029 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorExceptionTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/AnnotatorExceptionTest.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.annotation.services.annotators; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -public class AnnotatorExceptionTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor() { - AnnotatorException e = new AnnotatorException("messss"); - assertEquals("messss",e.getMessage()); - } - -} +package lcsb.mapviewer.annotation.services.annotators; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +public class AnnotatorExceptionTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor() { + AnnotatorException e = new AnnotatorException("messss"); + assertEquals("messss",e.getMessage()); + } + +} diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/AllGenomeTests.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/AllGenomeTests.java index 0e7211eec9..3ee8e7e988 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/AllGenomeTests.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/genome/AllGenomeTests.java @@ -1,11 +1,11 @@ -package lcsb.mapviewer.annotation.services.genome; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ UcscReferenceGenomeConnectorTest.class }) -public class AllGenomeTests { - -} +package lcsb.mapviewer.annotation.services.genome; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ UcscReferenceGenomeConnectorTest.class }) +public class AllGenomeTests { + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/AllComparatorTests.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/AllComparatorTests.java index 1b64a6dd63..3e35092b03 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/AllComparatorTests.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/AllComparatorTests.java @@ -1,19 +1,19 @@ -package lcsb.mapviewer.common.comparator; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ BooleanComparatorTest.class, // - ColorComparatorTest.class, // - DoubleComparatorTest.class, // - IntegerComparatorTest.class, // - PointComparatorTest.class, // - StringComparatorTest.class, // - StringListComparatorTest.class, // - StringSetComparatorTest.class, // -}) -public class AllComparatorTests { - -} +package lcsb.mapviewer.common.comparator; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ BooleanComparatorTest.class, // + ColorComparatorTest.class, // + DoubleComparatorTest.class, // + IntegerComparatorTest.class, // + PointComparatorTest.class, // + StringComparatorTest.class, // + StringListComparatorTest.class, // + StringSetComparatorTest.class, // +}) +public class AllComparatorTests { + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/BooleanComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/BooleanComparatorTest.java index d8329fcc9c..87d0984b9d 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/BooleanComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/BooleanComparatorTest.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class BooleanComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - BooleanComparator comp = new BooleanComparator(); - assertTrue(comp.compare(new Boolean(true), new Boolean(true)) == 0); - assertTrue(comp.compare(new Boolean(false), new Boolean(false)) == 0); - assertFalse(comp.compare(new Boolean(false), new Boolean(true)) == 0); - assertFalse(comp.compare(new Boolean(true), new Boolean(false)) == 0); - } - - @Test - public void testNullComparison() { - BooleanComparator comp = new BooleanComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare(new Boolean(false), null) == 0); - assertFalse(comp.compare(null, new Boolean(false)) == 0); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class BooleanComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + BooleanComparator comp = new BooleanComparator(); + assertTrue(comp.compare(new Boolean(true), new Boolean(true)) == 0); + assertTrue(comp.compare(new Boolean(false), new Boolean(false)) == 0); + assertFalse(comp.compare(new Boolean(false), new Boolean(true)) == 0); + assertFalse(comp.compare(new Boolean(true), new Boolean(false)) == 0); + } + + @Test + public void testNullComparison() { + BooleanComparator comp = new BooleanComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare(new Boolean(false), null) == 0); + assertFalse(comp.compare(null, new Boolean(false)) == 0); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/ColorComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/ColorComparatorTest.java index febdaff65a..5d82f57c79 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/ColorComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/ColorComparatorTest.java @@ -1,38 +1,38 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -import java.awt.Color; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ColorComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - ColorComparator comp = new ColorComparator(); - assertTrue(comp.compare(Color.BLACK, Color.BLACK) == 0); - assertTrue(comp.compare(Color.RED, Color.RED) == 0); - assertFalse(comp.compare(Color.RED, Color.BLACK) == 0); - assertFalse(comp.compare(Color.BLACK, Color.RED) == 0); - } - - @Test - public void testNullComparison() { - ColorComparator comp = new ColorComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare(Color.RED, null) == 0); - assertFalse(comp.compare(null, Color.RED) == 0); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +import java.awt.Color; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ColorComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + ColorComparator comp = new ColorComparator(); + assertTrue(comp.compare(Color.BLACK, Color.BLACK) == 0); + assertTrue(comp.compare(Color.RED, Color.RED) == 0); + assertFalse(comp.compare(Color.RED, Color.BLACK) == 0); + assertFalse(comp.compare(Color.BLACK, Color.RED) == 0); + } + + @Test + public void testNullComparison() { + ColorComparator comp = new ColorComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare(Color.RED, null) == 0); + assertFalse(comp.compare(null, Color.RED) == 0); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/DoubleComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/DoubleComparatorTest.java index 91243e054d..a1f9da671b 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/DoubleComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/DoubleComparatorTest.java @@ -1,44 +1,44 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class DoubleComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - DoubleComparator comp = new DoubleComparator(); - assertTrue(comp.compare(new Double(5.01), new Double(5.01)) == 0); - assertTrue(comp.compare(new Double(2.73), new Double(2.73)) == 0); - assertFalse(comp.compare(new Double(2.73), new Double(5.01)) == 0); - assertFalse(comp.compare(new Double(5.01), new Double(2.73)) == 0); - } - - @Test - public void testEpsilonComp() { - DoubleComparator comp = new DoubleComparator(10); - assertTrue(comp.compare(new Double(5.01), new Double(1.01)) == 0); - assertFalse(comp.compare(new Double(2.73), new Double(-105.01)) == 0); - assertTrue(comp.compare(new Double(5.01), new Double(-2.73)) == 0); - } - - @Test - public void testNullComparison() { - DoubleComparator comp = new DoubleComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare(new Double(2.73), null) == 0); - assertFalse(comp.compare(null, new Double(2.73)) == 0); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class DoubleComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + DoubleComparator comp = new DoubleComparator(); + assertTrue(comp.compare(new Double(5.01), new Double(5.01)) == 0); + assertTrue(comp.compare(new Double(2.73), new Double(2.73)) == 0); + assertFalse(comp.compare(new Double(2.73), new Double(5.01)) == 0); + assertFalse(comp.compare(new Double(5.01), new Double(2.73)) == 0); + } + + @Test + public void testEpsilonComp() { + DoubleComparator comp = new DoubleComparator(10); + assertTrue(comp.compare(new Double(5.01), new Double(1.01)) == 0); + assertFalse(comp.compare(new Double(2.73), new Double(-105.01)) == 0); + assertTrue(comp.compare(new Double(5.01), new Double(-2.73)) == 0); + } + + @Test + public void testNullComparison() { + DoubleComparator comp = new DoubleComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare(new Double(2.73), null) == 0); + assertFalse(comp.compare(null, new Double(2.73)) == 0); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/IntegerComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/IntegerComparatorTest.java index 65b7ab4653..e396de6274 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/IntegerComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/IntegerComparatorTest.java @@ -1,35 +1,35 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class IntegerComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - IntegerComparator comp = new IntegerComparator(); - assertTrue(comp.compare(new Integer(13), new Integer(13)) == 0); - assertTrue(comp.compare(new Integer(-59), new Integer(-59)) == 0); - assertFalse(comp.compare(new Integer(-59), new Integer(13)) == 0); - assertFalse(comp.compare(new Integer(13), new Integer(-59)) == 0); - } - - @Test - public void testNullComparison() { - IntegerComparator comp = new IntegerComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare(new Integer(-59), null) == 0); - assertFalse(comp.compare(null, new Integer(-59)) == 0); - } -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class IntegerComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + IntegerComparator comp = new IntegerComparator(); + assertTrue(comp.compare(new Integer(13), new Integer(13)) == 0); + assertTrue(comp.compare(new Integer(-59), new Integer(-59)) == 0); + assertFalse(comp.compare(new Integer(-59), new Integer(13)) == 0); + assertFalse(comp.compare(new Integer(13), new Integer(-59)) == 0); + } + + @Test + public void testNullComparison() { + IntegerComparator comp = new IntegerComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare(new Integer(-59), null) == 0); + assertFalse(comp.compare(null, new Integer(-59)) == 0); + } +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/PointComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/PointComparatorTest.java index 0d2097325e..49ff29d5af 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/PointComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/PointComparatorTest.java @@ -1,47 +1,47 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.awt.geom.Point2D; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class PointComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - PointComparator comp = new PointComparator(); - assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 5.01)) == 0); - assertTrue(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, 2.73)) == 0); - assertFalse(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, 5.01)) == 0); - assertFalse(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 2.73)) == 0); - } - - @Test - public void testEpsilonComp() { - PointComparator comp = new PointComparator(10); - assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 1.01)) == 0); - assertFalse(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, -105.01)) == 0); - assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, -2.73)) == 0); - } - - @Test - public void testNullComparison() { - PointComparator comp = new PointComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare(new Point2D.Double(106, 2.73), null) == 0); - assertFalse(comp.compare(null, new Point2D.Double(106, 2.73)) == 0); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.awt.geom.Point2D; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PointComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + PointComparator comp = new PointComparator(); + assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 5.01)) == 0); + assertTrue(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, 2.73)) == 0); + assertFalse(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, 5.01)) == 0); + assertFalse(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 2.73)) == 0); + } + + @Test + public void testEpsilonComp() { + PointComparator comp = new PointComparator(10); + assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, 1.01)) == 0); + assertFalse(comp.compare(new Point2D.Double(106, 2.73), new Point2D.Double(106, -105.01)) == 0); + assertTrue(comp.compare(new Point2D.Double(106, 5.01), new Point2D.Double(106, -2.73)) == 0); + } + + @Test + public void testNullComparison() { + PointComparator comp = new PointComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare(new Point2D.Double(106, 2.73), null) == 0); + assertFalse(comp.compare(null, new Point2D.Double(106, 2.73)) == 0); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringComparatorTest.java index 88b635ee56..6e09a53cd4 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringComparatorTest.java @@ -1,44 +1,44 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class StringComparatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testNotNullComparison() { - StringComparator comp = new StringComparator(); - assertTrue(comp.compare("test1", "test1") == 0); - assertTrue(comp.compare("xxx3", "xxx3") == 0); - assertFalse(comp.compare("xxx3", "test1") == 0); - assertFalse(comp.compare("test1", "xxx3") == 0); - } - - @Test - public void testComparisonWithoutWhitespace() { - StringComparator comp = new StringComparator(); - assertTrue(comp.compare("test1 32", "test1 32",true) == 0); - assertTrue(comp.compare("test1\t32", "test1 \n32",true) == 0); - assertFalse(comp.compare("test132", "test1 32",true) == 0); - } - - @Test - public void testNullComparison() { - StringComparator comp = new StringComparator(); - assertTrue(comp.compare(null, null) == 0); - assertFalse(comp.compare("xxx3", null) == 0); - assertFalse(comp.compare(null, "xxx3") == 0); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class StringComparatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNotNullComparison() { + StringComparator comp = new StringComparator(); + assertTrue(comp.compare("test1", "test1") == 0); + assertTrue(comp.compare("xxx3", "xxx3") == 0); + assertFalse(comp.compare("xxx3", "test1") == 0); + assertFalse(comp.compare("test1", "xxx3") == 0); + } + + @Test + public void testComparisonWithoutWhitespace() { + StringComparator comp = new StringComparator(); + assertTrue(comp.compare("test1 32", "test1 32",true) == 0); + assertTrue(comp.compare("test1\t32", "test1 \n32",true) == 0); + assertFalse(comp.compare("test132", "test1 32",true) == 0); + } + + @Test + public void testNullComparison() { + StringComparator comp = new StringComparator(); + assertTrue(comp.compare(null, null) == 0); + assertFalse(comp.compare("xxx3", null) == 0); + assertFalse(comp.compare(null, "xxx3") == 0); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringListComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringListComparatorTest.java index e22dbc1cb5..65771f6028 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringListComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringListComparatorTest.java @@ -1,56 +1,56 @@ -package lcsb.mapviewer.common.comparator; - -import static org.junit.Assert.*; - -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); - } - -} +package lcsb.mapviewer.common.comparator; + +import static org.junit.Assert.*; + +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); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringSetComparatorTest.java b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringSetComparatorTest.java index d74ca665e1..ceab74d187 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/comparator/StringSetComparatorTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/comparator/StringSetComparatorTest.java @@ -1,61 +1,61 @@ -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); - } - - -} +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); + } + + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/AllExceptionTests.java b/commons/src/test/java/lcsb/mapviewer/common/exception/AllExceptionTests.java index c97eba1515..78b1c8ebaf 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/AllExceptionTests.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/AllExceptionTests.java @@ -1,12 +1,12 @@ -package lcsb.mapviewer.common.exception; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ InvalidArgumentExceptionTest.class, InvalidClassExceptionTest.class, InvalidStateExceptionTest.class, InvalidXmlSchemaExceptionTest.class, - NotImplementedExceptionTest.class }) -public class AllExceptionTests { - -} +package lcsb.mapviewer.common.exception; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ InvalidArgumentExceptionTest.class, InvalidClassExceptionTest.class, InvalidStateExceptionTest.class, InvalidXmlSchemaExceptionTest.class, + NotImplementedExceptionTest.class }) +public class AllExceptionTests { + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidArgumentExceptionTest.java b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidArgumentExceptionTest.java index 4f29bfe219..70043e17e1 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidArgumentExceptionTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidArgumentExceptionTest.java @@ -1,39 +1,39 @@ -package lcsb.mapviewer.common.exception; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class InvalidArgumentExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor1() { - assertNotNull(new InvalidArgumentException()); - } - - @Test - public void testConstructor2() { - assertNotNull(new InvalidArgumentException("str")); - } - - @Test - public void testConstructor3() { - assertNotNull(new InvalidArgumentException(new Exception())); - } - - @Test - public void testConstructor4() { - assertNotNull(new InvalidArgumentException("dsr", new Exception())); - } - -} +package lcsb.mapviewer.common.exception; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InvalidArgumentExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor1() { + assertNotNull(new InvalidArgumentException()); + } + + @Test + public void testConstructor2() { + assertNotNull(new InvalidArgumentException("str")); + } + + @Test + public void testConstructor3() { + assertNotNull(new InvalidArgumentException(new Exception())); + } + + @Test + public void testConstructor4() { + assertNotNull(new InvalidArgumentException("dsr", new Exception())); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidClassExceptionTest.java b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidClassExceptionTest.java index 4dcb0c5896..2b6bee2582 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidClassExceptionTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidClassExceptionTest.java @@ -1,29 +1,29 @@ -package lcsb.mapviewer.common.exception; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class InvalidClassExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor1() { - assertNotNull(new InvalidClassException("str")); - } - - @Test - public void testConstructor2() { - assertNotNull(new InvalidClassException("dsr", new Exception())); - } - -} +package lcsb.mapviewer.common.exception; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InvalidClassExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor1() { + assertNotNull(new InvalidClassException("str")); + } + + @Test + public void testConstructor2() { + assertNotNull(new InvalidClassException("dsr", new Exception())); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidStateExceptionTest.java b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidStateExceptionTest.java index 4ff04ade68..4b5eaf6d5b 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidStateExceptionTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidStateExceptionTest.java @@ -1,39 +1,39 @@ -package lcsb.mapviewer.common.exception; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class InvalidStateExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor1() { - assertNotNull(new InvalidStateException()); - } - - @Test - public void testConstructor2() { - assertNotNull(new InvalidStateException("str")); - } - - @Test - public void testConstructor3() { - assertNotNull(new InvalidStateException(new Exception())); - } - - @Test - public void testConstructor4() { - assertNotNull(new InvalidStateException("dsr", new Exception())); - } - -} +package lcsb.mapviewer.common.exception; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InvalidStateExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor1() { + assertNotNull(new InvalidStateException()); + } + + @Test + public void testConstructor2() { + assertNotNull(new InvalidStateException("str")); + } + + @Test + public void testConstructor3() { + assertNotNull(new InvalidStateException(new Exception())); + } + + @Test + public void testConstructor4() { + assertNotNull(new InvalidStateException("dsr", new Exception())); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidXmlSchemaExceptionTest.java b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidXmlSchemaExceptionTest.java index 95ae7bbc05..4548e61f40 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidXmlSchemaExceptionTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/InvalidXmlSchemaExceptionTest.java @@ -1,39 +1,39 @@ -package lcsb.mapviewer.common.exception; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class InvalidXmlSchemaExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor1() { - assertNotNull(new InvalidXmlSchemaException()); - } - - @Test - public void testConstructor2() { - assertNotNull(new InvalidXmlSchemaException("str")); - } - - @Test - public void testConstructor3() { - assertNotNull(new InvalidXmlSchemaException(new Exception())); - } - - @Test - public void testConstructor4() { - assertNotNull(new InvalidXmlSchemaException("dsr", new Exception())); - } - -} +package lcsb.mapviewer.common.exception; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InvalidXmlSchemaExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor1() { + assertNotNull(new InvalidXmlSchemaException()); + } + + @Test + public void testConstructor2() { + assertNotNull(new InvalidXmlSchemaException("str")); + } + + @Test + public void testConstructor3() { + assertNotNull(new InvalidXmlSchemaException(new Exception())); + } + + @Test + public void testConstructor4() { + assertNotNull(new InvalidXmlSchemaException("dsr", new Exception())); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/exception/NotImplementedExceptionTest.java b/commons/src/test/java/lcsb/mapviewer/common/exception/NotImplementedExceptionTest.java index 17d933b020..2aeabe5eee 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/exception/NotImplementedExceptionTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/exception/NotImplementedExceptionTest.java @@ -1,29 +1,29 @@ -package lcsb.mapviewer.common.exception; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class NotImplementedExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor1() { - assertNotNull(new NotImplementedException()); - } - - @Test - public void testConstructor2() { - assertNotNull(new NotImplementedException("str")); - } - -} +package lcsb.mapviewer.common.exception; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class NotImplementedExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor1() { + assertNotNull(new NotImplementedException()); + } + + @Test + public void testConstructor2() { + assertNotNull(new NotImplementedException("str")); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/AllGeometryTests.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/AllGeometryTests.java index f1f37a3896..2748b50363 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/AllGeometryTests.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/AllGeometryTests.java @@ -1,16 +1,16 @@ -package lcsb.mapviewer.common.geometry; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ CompositeStrokeTest.class, // - EllipseTransformationTest.class, // - LineTransformationTest.class, // - PointTransformationTest.class, // - TextAlignmentTest.class,// -}) -public class AllGeometryTests { - -} +package lcsb.mapviewer.common.geometry; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ CompositeStrokeTest.class, // + EllipseTransformationTest.class, // + LineTransformationTest.class, // + PointTransformationTest.class, // + TextAlignmentTest.class,// +}) +public class AllGeometryTests { + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/CompositeStrokeTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/CompositeStrokeTest.java index a4251214cd..95be640aff 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/CompositeStrokeTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/CompositeStrokeTest.java @@ -1,26 +1,26 @@ -package lcsb.mapviewer.common.geometry; - -import java.awt.BasicStroke; -import java.awt.geom.Line2D; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CompositeStrokeTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - CompositeStroke cs = new CompositeStroke(new BasicStroke(10f), new BasicStroke(0.5f)); - cs.createStrokedShape(new Line2D.Double(0.1, 0.1, 0.1, 0.1)); - } - -} +package lcsb.mapviewer.common.geometry; + +import java.awt.BasicStroke; +import java.awt.geom.Line2D; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CompositeStrokeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void test() { + CompositeStroke cs = new CompositeStroke(new BasicStroke(10f), new BasicStroke(0.5f)); + cs.createStrokedShape(new Line2D.Double(0.1, 0.1, 0.1, 0.1)); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/EllipseTransformationTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/EllipseTransformationTest.java index eeeca94a54..a87a4ae920 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/EllipseTransformationTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/EllipseTransformationTest.java @@ -1,82 +1,82 @@ -package lcsb.mapviewer.common.geometry; - -import static org.junit.Assert.*; - -import java.awt.geom.Ellipse2D; -import java.awt.geom.Point2D; - -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Configuration; - -public class EllipseTransformationTest { - Logger logger = Logger.getLogger(EllipseTransformationTest.class); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testPointOnEllipse() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 0); - assertTrue(point.distance(0, 100) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse2() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 90); - assertTrue(point.distance(100, 0) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse3() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 180); - assertTrue(point.distance(200, 100) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse4() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 270); - assertTrue(point.distance(100, 200) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse5() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 360); - assertTrue(point.distance(0, 100) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse6() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 300); - assertNotNull(point); - } - - @Test - public void testPointOnEllipse7() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, -360); - assertTrue(point.distance(0, 100) <= Configuration.EPSILON); - } - - @Test - public void testPointOnEllipse8() { - EllipseTransformation et = new EllipseTransformation(); - Point2D point = et.getPointOnEllipseByDegree(new Ellipse2D.Double(0, 0, 200, 200), -360); - assertTrue(point.distance(0, 100) <= Configuration.EPSILON); - } - -} +package lcsb.mapviewer.common.geometry; + +import static org.junit.Assert.*; + +import java.awt.geom.Ellipse2D; +import java.awt.geom.Point2D; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Configuration; + +public class EllipseTransformationTest { + Logger logger = Logger.getLogger(EllipseTransformationTest.class); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testPointOnEllipse() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 0); + assertTrue(point.distance(0, 100) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse2() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 90); + assertTrue(point.distance(100, 0) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse3() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 180); + assertTrue(point.distance(200, 100) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse4() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 270); + assertTrue(point.distance(100, 200) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse5() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 360); + assertTrue(point.distance(0, 100) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse6() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, 300); + assertNotNull(point); + } + + @Test + public void testPointOnEllipse7() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(0, 0, 200, 200, -360); + assertTrue(point.distance(0, 100) <= Configuration.EPSILON); + } + + @Test + public void testPointOnEllipse8() { + EllipseTransformation et = new EllipseTransformation(); + Point2D point = et.getPointOnEllipseByDegree(new Ellipse2D.Double(0, 0, 200, 200), -360); + assertTrue(point.distance(0, 100) <= Configuration.EPSILON); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/LineTransformationTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/LineTransformationTest.java index 078abe6591..433c975b4f 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/LineTransformationTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/LineTransformationTest.java @@ -1,214 +1,214 @@ -package lcsb.mapviewer.common.geometry; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; -import java.awt.geom.Line2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.geom.RoundRectangle2D; - -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Configuration; - -public class LineTransformationTest { - static Logger logger = Logger.getLogger(LineTransformationTest.class); - static double EPSILON = Configuration.EPSILON; - LineTransformation lineTransformation = new LineTransformation(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testIntersection() { - Shape s = new RoundRectangle2D.Double(0.0, 0.0, 100.0, 100.0, 10.0, 10.0); - Line2D line = new Line2D.Double(50, 50, 50, 200); - Point2D p = lineTransformation.getIntersectionWithPathIterator(line, s.getPathIterator(new AffineTransform())); - Point2D intPoint = new Point2D.Double(50, 100); - double dist = p.distance(intPoint); - assertEquals("Invalid intersection point: " + p, 0, dist, EPSILON); - } - - @Test - public void testIntersectionWithBezierCurve() { - double x = 0; - double y = 0; - double w = 100; - double h = 200; - GeneralPath path = new GeneralPath(); - - path.moveTo((float) (x + 0.25 * w), (float) (y + 0.25 * h)); - path.quadTo((float) (x + 0.05 * w), (float) (y + 0.25 * h), x, (float) (y + 0.5 * h)); - path.curveTo(x, (float) (y + 0.66 * h), (float) (x + 0.18 * w), (float) (y + 0.9 * h), (float) (x + 0.31 * w), (float) (y + 0.8 * h)); - path.curveTo((float) (x + 0.4 * w), (y + h), (float) (x + 0.7 * w), (y + h), (float) (x + 0.8 * w), (float) (y + 0.8 * h)); - path.curveTo((x + w), (float) (y + 0.8 * h), (x + w), (float) (y + 0.6 * h), (float) (x + 0.875 * w), (float) (y + 0.5 * h)); - path.curveTo((x + w), (float) (y + 0.3 * h), (float) (x + 0.8 * w), (float) (y + 0.1 * h), (float) (x + 0.625 * w), (float) (y + 0.2 * h)); - path.curveTo((float) (x + 0.5 * w), (float) (y + 0.05 * h), (float) (x + 0.3 * w), (float) (y + 0.05 * h), (float) (x + 0.25 * w), (float) (y + 0.25 * h)); - path.closePath(); - - Line2D line = new Line2D.Double(50, 50, 50, 300); - Point2D p = lineTransformation.getIntersectionWithPathIterator(line, path.getPathIterator(new AffineTransform())); - assertNotNull(p); - } - - @Test - public void testIntersectionToInvalidPath() { - Line2D line = new Line2D.Double(50, 50, 50, 200); - Point2D p = lineTransformation.getIntersectionWithPathIterator(line, null); - assertNull(p); - - Shape s = new Rectangle2D.Double(0.0, 0.0, 10.0, 0.0); - p = lineTransformation.getIntersectionWithPathIterator(line, s.getPathIterator(new AffineTransform())); - assertNull(p); - - p = lineTransformation.getIntersectionWithPathIterator(line, new PathIterator() { - - @Override - public void next() { - // TODO Auto-generated method stub - - } - - @Override - public boolean isDone() { - return true; - } - - @Override - public int getWindingRule() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int currentSegment(double[] coords) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int currentSegment(float[] coords) { - // TODO Auto-generated method stub - return 0; - } - }); - assertNull(p); - } - - @Test - public void testDistance() { - assertNotNull(lineTransformation); - Point2D p1 = new Point2D.Double(2, 2); - Point2D p2 = new Point2D.Double(3, 3); - Point2D p3 = new Point2D.Double(4, 4); - - double dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - double d = Math.sqrt(2); - assertEquals(dist, d, EPSILON); - - p3 = new Point2D.Double(3, 4); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - assertEquals(dist, 1, EPSILON); - - p3 = new Point2D.Double(3, 3); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - assertEquals(dist, 0, EPSILON); - - p3 = new Point2D.Double(2.5, 2.5); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - assertEquals(dist, 0, EPSILON); - - p3 = new Point2D.Double(2, 2); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - assertEquals(dist, 0, EPSILON); - - p3 = new Point2D.Double(2, 0); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - assertEquals(dist, 2, EPSILON); - - p3 = new Point2D.Double(3, 2); - dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); - d = Math.sqrt(0.5); - assertEquals(dist, d, EPSILON); - - } - - @Test - public void testDistanceToEmptyLine() { - Point2D p1 = new Point2D.Double(2, 2); - Point2D p2 = new Point2D.Double(3, 3); - double dist = lineTransformation.distBetweenPointAndLineSegment(p1, p1, p2); - assertEquals(p1.distance(p2), dist, EPSILON); - - // the same with line - Line2D line = new Line2D.Double(p1, p1); - dist = lineTransformation.distBetweenPointAndLineSegment(line, p2); - assertEquals(p1.distance(p2), dist, EPSILON); - } - - @Test - public void testClosestPointOnSegmentLineToPointOnEmptyLine() { - Point2D p1 = new Point2D.Double(2, 2); - Point2D p2 = new Point2D.Double(3, 3); - Point2D p3 = lineTransformation.closestPointOnSegmentLineToPoint(p1, p1, p2); - assertEquals(p3, p1); - - // the same with line - Line2D line = new Line2D.Double(p1, p1); - p3 = lineTransformation.closestPointOnSegmentLineToPoint(line, p2); - assertEquals(p3, p1); - - } - - @Test - public void testClosestPoint() { - assertNotNull(lineTransformation); - Point2D p1 = new Point2D.Double(2, 2); - Point2D p2 = new Point2D.Double(3, 3); - Point2D p3 = new Point2D.Double(4, 4); - - Point2D res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - double d = Math.sqrt(2); - assertEquals(res.distance(p3), d, EPSILON); - - p3 = new Point2D.Double(3, 4); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - assertEquals(res.distance(p3), 1, EPSILON); - - p3 = new Point2D.Double(3, 3); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - assertEquals(res.distance(p3), 0, EPSILON); - - p3 = new Point2D.Double(2.5, 2.5); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - assertEquals(res.distance(p3), 0, EPSILON); - - p3 = new Point2D.Double(2, 2); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - assertEquals(res.distance(p3), 0, EPSILON); - - p3 = new Point2D.Double(2, 0); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - assertEquals(res.distance(p3), 2, EPSILON); - - p3 = new Point2D.Double(3, 2); - res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); - d = Math.sqrt(0.5); - assertEquals(res.distance(p3), d, EPSILON); - - } -} +package lcsb.mapviewer.common.geometry; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; +import java.awt.geom.Line2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.awt.geom.RoundRectangle2D; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Configuration; + +public class LineTransformationTest { + static Logger logger = Logger.getLogger(LineTransformationTest.class); + static double EPSILON = Configuration.EPSILON; + LineTransformation lineTransformation = new LineTransformation(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testIntersection() { + Shape s = new RoundRectangle2D.Double(0.0, 0.0, 100.0, 100.0, 10.0, 10.0); + Line2D line = new Line2D.Double(50, 50, 50, 200); + Point2D p = lineTransformation.getIntersectionWithPathIterator(line, s.getPathIterator(new AffineTransform())); + Point2D intPoint = new Point2D.Double(50, 100); + double dist = p.distance(intPoint); + assertEquals("Invalid intersection point: " + p, 0, dist, EPSILON); + } + + @Test + public void testIntersectionWithBezierCurve() { + double x = 0; + double y = 0; + double w = 100; + double h = 200; + GeneralPath path = new GeneralPath(); + + path.moveTo((float) (x + 0.25 * w), (float) (y + 0.25 * h)); + path.quadTo((float) (x + 0.05 * w), (float) (y + 0.25 * h), x, (float) (y + 0.5 * h)); + path.curveTo(x, (float) (y + 0.66 * h), (float) (x + 0.18 * w), (float) (y + 0.9 * h), (float) (x + 0.31 * w), (float) (y + 0.8 * h)); + path.curveTo((float) (x + 0.4 * w), (y + h), (float) (x + 0.7 * w), (y + h), (float) (x + 0.8 * w), (float) (y + 0.8 * h)); + path.curveTo((x + w), (float) (y + 0.8 * h), (x + w), (float) (y + 0.6 * h), (float) (x + 0.875 * w), (float) (y + 0.5 * h)); + path.curveTo((x + w), (float) (y + 0.3 * h), (float) (x + 0.8 * w), (float) (y + 0.1 * h), (float) (x + 0.625 * w), (float) (y + 0.2 * h)); + path.curveTo((float) (x + 0.5 * w), (float) (y + 0.05 * h), (float) (x + 0.3 * w), (float) (y + 0.05 * h), (float) (x + 0.25 * w), (float) (y + 0.25 * h)); + path.closePath(); + + Line2D line = new Line2D.Double(50, 50, 50, 300); + Point2D p = lineTransformation.getIntersectionWithPathIterator(line, path.getPathIterator(new AffineTransform())); + assertNotNull(p); + } + + @Test + public void testIntersectionToInvalidPath() { + Line2D line = new Line2D.Double(50, 50, 50, 200); + Point2D p = lineTransformation.getIntersectionWithPathIterator(line, null); + assertNull(p); + + Shape s = new Rectangle2D.Double(0.0, 0.0, 10.0, 0.0); + p = lineTransformation.getIntersectionWithPathIterator(line, s.getPathIterator(new AffineTransform())); + assertNull(p); + + p = lineTransformation.getIntersectionWithPathIterator(line, new PathIterator() { + + @Override + public void next() { + // TODO Auto-generated method stub + + } + + @Override + public boolean isDone() { + return true; + } + + @Override + public int getWindingRule() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int currentSegment(double[] coords) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int currentSegment(float[] coords) { + // TODO Auto-generated method stub + return 0; + } + }); + assertNull(p); + } + + @Test + public void testDistance() { + assertNotNull(lineTransformation); + Point2D p1 = new Point2D.Double(2, 2); + Point2D p2 = new Point2D.Double(3, 3); + Point2D p3 = new Point2D.Double(4, 4); + + double dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + double d = Math.sqrt(2); + assertEquals(dist, d, EPSILON); + + p3 = new Point2D.Double(3, 4); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + assertEquals(dist, 1, EPSILON); + + p3 = new Point2D.Double(3, 3); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + assertEquals(dist, 0, EPSILON); + + p3 = new Point2D.Double(2.5, 2.5); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + assertEquals(dist, 0, EPSILON); + + p3 = new Point2D.Double(2, 2); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + assertEquals(dist, 0, EPSILON); + + p3 = new Point2D.Double(2, 0); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + assertEquals(dist, 2, EPSILON); + + p3 = new Point2D.Double(3, 2); + dist = lineTransformation.distBetweenPointAndLineSegment(p1, p2, p3); + d = Math.sqrt(0.5); + assertEquals(dist, d, EPSILON); + + } + + @Test + public void testDistanceToEmptyLine() { + Point2D p1 = new Point2D.Double(2, 2); + Point2D p2 = new Point2D.Double(3, 3); + double dist = lineTransformation.distBetweenPointAndLineSegment(p1, p1, p2); + assertEquals(p1.distance(p2), dist, EPSILON); + + // the same with line + Line2D line = new Line2D.Double(p1, p1); + dist = lineTransformation.distBetweenPointAndLineSegment(line, p2); + assertEquals(p1.distance(p2), dist, EPSILON); + } + + @Test + public void testClosestPointOnSegmentLineToPointOnEmptyLine() { + Point2D p1 = new Point2D.Double(2, 2); + Point2D p2 = new Point2D.Double(3, 3); + Point2D p3 = lineTransformation.closestPointOnSegmentLineToPoint(p1, p1, p2); + assertEquals(p3, p1); + + // the same with line + Line2D line = new Line2D.Double(p1, p1); + p3 = lineTransformation.closestPointOnSegmentLineToPoint(line, p2); + assertEquals(p3, p1); + + } + + @Test + public void testClosestPoint() { + assertNotNull(lineTransformation); + Point2D p1 = new Point2D.Double(2, 2); + Point2D p2 = new Point2D.Double(3, 3); + Point2D p3 = new Point2D.Double(4, 4); + + Point2D res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + double d = Math.sqrt(2); + assertEquals(res.distance(p3), d, EPSILON); + + p3 = new Point2D.Double(3, 4); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + assertEquals(res.distance(p3), 1, EPSILON); + + p3 = new Point2D.Double(3, 3); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + assertEquals(res.distance(p3), 0, EPSILON); + + p3 = new Point2D.Double(2.5, 2.5); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + assertEquals(res.distance(p3), 0, EPSILON); + + p3 = new Point2D.Double(2, 2); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + assertEquals(res.distance(p3), 0, EPSILON); + + p3 = new Point2D.Double(2, 0); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + assertEquals(res.distance(p3), 2, EPSILON); + + p3 = new Point2D.Double(3, 2); + res = lineTransformation.closestPointOnSegmentLineToPoint(p1, p2, p3); + d = Math.sqrt(0.5); + assertEquals(res.distance(p3), d, EPSILON); + + } +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java index 1868f38ed3..2bd903a735 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java @@ -1,44 +1,44 @@ -package lcsb.mapviewer.common.geometry; - -import static org.junit.Assert.*; - -import java.awt.geom.Point2D; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Configuration; - -public class PointTransformationTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testRotate() { - PointTransformation pt = new PointTransformation(); - Point2D p1 = new Point2D.Double(1, 0); - Point2D p2 = new Point2D.Double(2, 0); - Point2D p3 = new Point2D.Double(3, 0); - Point2D res = pt.rotatePoint(p1, Math.PI, p2); - assertEquals(0.0, p3.distance(res), Configuration.EPSILON); - } - - @Test - public void testIsValid() { - PointTransformation pt = new PointTransformation(); - Point2D p1 = new Point2D.Double(1, 0); - Point2D p2 = new Point2D.Double(1, Double.NEGATIVE_INFINITY); - Point2D p3 = new Point2D.Double(Double.NEGATIVE_INFINITY, 2); - assertTrue(pt.isValidPoint(p1)); - assertFalse(pt.isValidPoint(p2)); - assertFalse(pt.isValidPoint(p3)); - } - -} +package lcsb.mapviewer.common.geometry; + +import static org.junit.Assert.*; + +import java.awt.geom.Point2D; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Configuration; + +public class PointTransformationTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testRotate() { + PointTransformation pt = new PointTransformation(); + Point2D p1 = new Point2D.Double(1, 0); + Point2D p2 = new Point2D.Double(2, 0); + Point2D p3 = new Point2D.Double(3, 0); + Point2D res = pt.rotatePoint(p1, Math.PI, p2); + assertEquals(0.0, p3.distance(res), Configuration.EPSILON); + } + + @Test + public void testIsValid() { + PointTransformation pt = new PointTransformation(); + Point2D p1 = new Point2D.Double(1, 0); + Point2D p2 = new Point2D.Double(1, Double.NEGATIVE_INFINITY); + Point2D p3 = new Point2D.Double(Double.NEGATIVE_INFINITY, 2); + assertTrue(pt.isValidPoint(p1)); + assertFalse(pt.isValidPoint(p2)); + assertFalse(pt.isValidPoint(p3)); + } + +} diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/TextAlignmentTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/TextAlignmentTest.java index b14349b8ef..8c62a6db83 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/TextAlignmentTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/TextAlignmentTest.java @@ -1,29 +1,29 @@ -package lcsb.mapviewer.common.geometry; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class TextAlignmentTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (TextAlignment type : TextAlignment.values()) { - assertNotNull(type); - - // for coverage tests - TextAlignment.valueOf(type.toString()); - } - } - -} +package lcsb.mapviewer.common.geometry; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TextAlignmentTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (TextAlignment type : TextAlignment.values()) { + assertNotNull(type); + + // for coverage tests + TextAlignment.valueOf(type.toString()); + } + } + +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserException.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserException.java index 3009ac1a3a..beaf497336 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserException.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserException.java @@ -1,57 +1,57 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -/** - * Exception that shold be thrown when the parser encouter problem with - * cellDesigner file. - * - * @author Piotr Gawron - * - */ -public abstract class CellDesignerParserException extends Exception { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor - initializes instance variable to unknown. - */ - - public CellDesignerParserException() { - super(); // call superclass constructor - } - - /** - * Constructor receives some kind of message. - * - * @param err - * message associated with exception - */ - - public CellDesignerParserException(final String err) { - super(err); - } - - /** - * Constructor receives some kind of message and parent exception. - * - * @param err - * message associated with exception - * @param throwable - * parent exception - */ - public CellDesignerParserException(final String err, final Throwable throwable) { - super(err, throwable); - } - - /** - * Public constructor with parent exception that was catched. - * - * @param e - * parent exception - */ - - public CellDesignerParserException(final Throwable e) { - super(e); - } -} +package lcsb.mapviewer.converter.model.celldesigner; + +/** + * Exception that shold be thrown when the parser encouter problem with + * cellDesigner file. + * + * @author Piotr Gawron + * + */ +public abstract class CellDesignerParserException extends Exception { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor - initializes instance variable to unknown. + */ + + public CellDesignerParserException() { + super(); // call superclass constructor + } + + /** + * Constructor receives some kind of message. + * + * @param err + * message associated with exception + */ + + public CellDesignerParserException(final String err) { + super(err); + } + + /** + * Constructor receives some kind of message and parent exception. + * + * @param err + * message associated with exception + * @param throwable + * parent exception + */ + public CellDesignerParserException(final String err, final Throwable throwable) { + super(err, throwable); + } + + /** + * Public constructor with parent exception that was catched. + * + * @param e + * parent exception + */ + + public CellDesignerParserException(final Throwable e) { + super(e); + } +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupException.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupException.java index 5ddddf5576..ab3f278c60 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupException.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupException.java @@ -1,59 +1,59 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; - -/** - * Exception that shold be thrown when the group in xml schema is invalid. - * - * @author Piotr Gawron - * - */ -public class InvalidGroupException extends InvalidXmlSchemaException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor - initializes instance variable to unknown. - */ - - public InvalidGroupException() { - super(); // call superclass constructor - } - - /** - * Constructor receives some kind of message. - * - * @param err - * message associated with exception - */ - - public InvalidGroupException(final String err) { - super(err); - } - - /** - * Constructor receives some kind of message and parent exception. - * - * @param err - * message associated with exception - * @param throwable - * parent exception - */ - public InvalidGroupException(final String err, final Throwable throwable) { - super(err, throwable); - } - - /** - * Public constructor with parent exception that was catched. - * - * @param e - * parent exception - */ - - public InvalidGroupException(final Exception e) { - super(e); - } -} +package lcsb.mapviewer.converter.model.celldesigner; + +import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; + +/** + * Exception that shold be thrown when the group in xml schema is invalid. + * + * @author Piotr Gawron + * + */ +public class InvalidGroupException extends InvalidXmlSchemaException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor - initializes instance variable to unknown. + */ + + public InvalidGroupException() { + super(); // call superclass constructor + } + + /** + * Constructor receives some kind of message. + * + * @param err + * message associated with exception + */ + + public InvalidGroupException(final String err) { + super(err); + } + + /** + * Constructor receives some kind of message and parent exception. + * + * @param err + * message associated with exception + * @param throwable + * parent exception + */ + public InvalidGroupException(final String err, final Throwable throwable) { + super(err, throwable); + } + + /** + * Public constructor with parent exception that was catched. + * + * @param e + * parent exception + */ + + public InvalidGroupException(final Exception e) { + super(e); + } +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java index d419623f0e..f232c0aad7 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java @@ -1,535 +1,535 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.log4j.Logger; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import lcsb.mapviewer.common.XmlParser; -import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; -import lcsb.mapviewer.model.graphics.ArrowType; -import lcsb.mapviewer.model.graphics.LineType; -import lcsb.mapviewer.model.graphics.PolylineData; -import lcsb.mapviewer.model.map.layout.alias.Alias; -import lcsb.mapviewer.model.map.layout.alias.AliasGroup; -import lcsb.mapviewer.model.map.layout.alias.BlockDiagram; -import lcsb.mapviewer.model.map.layout.graphics.Layer; -import lcsb.mapviewer.model.map.layout.graphics.LayerOval; -import lcsb.mapviewer.model.map.layout.graphics.LayerRect; -import lcsb.mapviewer.model.map.layout.graphics.LayerText; -import lcsb.mapviewer.model.map.model.Model; - -/** - * Parser used for parsing CellDesigner xml to get {@link Layer} object. - * - * @author Piotr Gawron - * - */ -public class LayerXmlParser extends XmlParser { - - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(LayerXmlParser.class.getName()); - - /** - * Parser for common CellDesigner structures. - */ - private CommonXmlParser commonParser = new CommonXmlParser(); - - /** - * PArses CellDesigner xml node with collection of layers into collection of - * Layers. - * - * @param layersNode - * xml node - * @return collection of layers - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - public Collection<Layer> parseLayers(Node layersNode) throws InvalidXmlSchemaException { - List<Layer> result = new ArrayList<Layer>(); - NodeList nodes = layersNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:layer")) { - Layer layer = getLayer(node); - result.add(layer); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfLayers: " + node.getNodeName()); - } - } - } - return result; - } - - /** - * Transforms collection of layers into CellDesigner xml node. - * - * @param layers - * collection of layers - * @return xml node representing layers collection - */ - public String layerCollectionToXml(Collection<Layer> layers) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:listOfLayers>"); - for (Layer layer : layers) { - result.append(layerToXml(layer)); - } - result.append("</celldesigner:listOfLayers>\n"); - return result.toString(); - } - - /** - * Parses collection of block diagrams and adds them into the model. - * - * @param model - * model where the data is stored. - * @param xmlNode - * xml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - public void parseBlocks(Model model, Node xmlNode) throws InvalidXmlSchemaException { - NodeList nodes = xmlNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:blockDiagram")) { - model.addBlockDiagream(getBlockDiagram(node, model)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfBlockDiagrams: " + node.getNodeName()); - } - } - } - } - - /** - * Parses block diagrams from CellDesigner xml. Important! It's not yet - * implemented. - * - * @param node - * xml node to parse - * @param model - * model where data is stored - * @return parsed block diagram - */ - private BlockDiagram getBlockDiagram(Node node, Model model) { - logger.warn("BlockDiagrams are not implemented"); - return null; - } - - /** - * Parses CellDesigner node with collection of Alias Group and adds the groups - * into this model. - * - * @param model - * model where the data is stored - * @param xmlNode - * xml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - public void parseGroups(Model model, Node xmlNode) throws InvalidXmlSchemaException { - NodeList nodes = xmlNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:group")) { - model.addAliasGroup(getAliasGroup(node, model)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfGroups: " + node.getNodeName()); - } - } - } - } - - /** - * Parses xml node for alias group. - * - * @param groupNode - * xml node - * @param model - * model where the data is stored - * @return parsed alias group - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - AliasGroup getAliasGroup(Node groupNode, Model model) throws InvalidXmlSchemaException { - AliasGroup result = new AliasGroup(); - String id = getNodeAttr("id", groupNode); - result.setIdGroup(id); - String members = getNodeAttr("members", groupNode); - - String[] list = members.split(","); - for (String string : list) { - Alias alias = model.getAliasByAliasId(string); - if (alias == null) { - throw new InvalidGroupException("Group \"" + id + "\" contains alias with id: \"" + string + "\", but such alias doesn't exist in the model."); - } - result.addAlias(alias); - } - - NodeList nodes = groupNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:group: " + node.getNodeName()); - } - } - - return result; - } - - /** - * Parses CellDesigner xml node for single layer. - * - * @param layerNode - * xml node - * @return Layer that corresponds to CellDesigner xml node. - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - Layer getLayer(Node layerNode) throws InvalidXmlSchemaException { - Layer layer = new Layer(); - layer.setLayerId(getNodeAttr("id", layerNode)); - layer.setName(getNodeAttr("name", layerNode)); - layer.setLocked(getNodeAttr("locked", layerNode)); - layer.setVisible(getNodeAttr("visible", layerNode)); - NodeList list = layerNode.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node node = list.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equals("celldesigner:listOfTexts")) { - NodeList residueList = node.getChildNodes(); - for (int j = 0; j < residueList.getLength(); j++) { - Node textNode = residueList.item(j); - if (textNode.getNodeType() == Node.ELEMENT_NODE) { - if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerSpeciesAlias")) { - layer.addLayerText(getLayerText(textNode)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfTexts " + textNode.getNodeName()); - } - } - } - } else if (node.getNodeName().equals("celldesigner:listOfSquares")) { - NodeList residueList = node.getChildNodes(); - for (int j = 0; j < residueList.getLength(); j++) { - Node textNode = residueList.item(j); - if (textNode.getNodeType() == Node.ELEMENT_NODE) { - if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerCompartmentAlias")) { - if (getNodeAttr("type", textNode).equalsIgnoreCase("SQUARE")) { - layer.addLayerRect(getLayerRect(textNode)); - } else if (getNodeAttr("type", textNode).equalsIgnoreCase("OVAL")) { - layer.addLayerOval(getLayerOval(textNode)); - } else { - throw new InvalidXmlSchemaException("Unknown celldesigner:layerCompartmentAlias type: " + getNodeAttr("type", textNode)); - } - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfSquares " + textNode.getNodeName()); - } - } - } - } else if (node.getNodeName().equals("celldesigner:listOfFreeLines")) { - NodeList residueList = node.getChildNodes(); - for (int j = 0; j < residueList.getLength(); j++) { - Node textNode = residueList.item(j); - if (textNode.getNodeType() == Node.ELEMENT_NODE) { - if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerFreeLine")) { - layer.addLayerLine(getLayerLine(textNode)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfFreeLines " + textNode.getNodeName()); - } - } - } - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:layer " + node.getNodeName()); - } - } - } - - return layer; - } - - /** - * Creates CellDesigner xml for a layer. - * - * @param layer - * object to be transformed into xml - * @return CellDesigner xml representation for the layer - */ - String layerToXml(Layer layer) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:layer id =\"" + layer.getLayerId() + "\" "); - result.append(" name =\"" + layer.getName() + "\" "); - result.append(" locked =\"" + layer.isLocked() + "\" "); - result.append(" visible =\"" + layer.isVisible() + "\">\n"); - - result.append("<celldesigner:listOfTexts>\n"); - for (LayerText layerText : layer.getTexts()) { - result.append(layerTextToXml(layerText)); - } - result.append("</celldesigner:listOfTexts>\n"); - - result.append("<celldesigner:listOfSquares>\n"); - for (LayerRect layerRect : layer.getRectangles()) { - result.append(layerRectToXml(layerRect)); - } - for (LayerOval layerOval : layer.getOvals()) { - result.append(layerOvalToXml(layerOval)); - } - result.append("</celldesigner:listOfSquares>\n"); - - result.append("<celldesigner:listOfFreeLines>\n"); - for (PolylineData layerLine : layer.getLines()) { - result.append(layerLineToXml(layerLine)); - } - result.append("</celldesigner:listOfFreeLines>\n"); - - result.append("</celldesigner:layer>\n"); - return result.toString(); - } - - /** - * Parses CellDesigner xml node into LayerRect object. - * - * @param textNode - * CellDesigner xml node for layer text object. - * @return LayerRect instance representing the cml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - LayerRect getLayerRect(Node textNode) throws InvalidXmlSchemaException { - LayerRect result = new LayerRect(); - NodeList nodes = textNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { - result.setColor(commonParser.getColor(node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { - result.setX(getNodeAttr("x", node)); - result.setY(getNodeAttr("y", node)); - result.setWidth(getNodeAttr("w", node)); - result.setHeight(getNodeAttr("h", node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:ispaint")) { - // ??? - continue; - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerCompartmentAlias: " + node.getNodeName()); - } - } - } - return result; - } - - /** - * Transforms LayerRect object into CellDesigner xml node. - * - * @param layer - * object to be transformed into xml - * @return CellDesigner xml node for LayerRect - */ - String layerRectToXml(LayerRect layer) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:layerCompartmentAlias type=\"Square\">"); - result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); - result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); - result.append(" y=\"" + layer.getY() + "\" "); - result.append(" w=\"" + layer.getWidth() + "\" "); - result.append(" h=\"" + layer.getHeight() + "\"/>"); - result.append("</celldesigner:layerCompartmentAlias>"); - return result.toString(); - } - - /** - * Parses CellDesigner xml node into LayerLine object. - * - * @param lineNode - * CellDesigner xml node for layer text object. - * @return LayerLine instance representing the cml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - PolylineData getLayerLine(Node lineNode) throws InvalidXmlSchemaException { - PolylineData ld = new PolylineData(); - - if (getNodeAttr("isDotted", lineNode).equalsIgnoreCase("true")) { - ld.getEndAtd().setArrowLineType(LineType.DOTTED); - } - if (getNodeAttr("isArrow", lineNode).equalsIgnoreCase("true")) { - ld.getEndAtd().setArrowType(ArrowType.FULL); - } - NodeList nodes = lineNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { - double sx = Double.parseDouble(getNodeAttr("sx", node)); - double sy = Double.parseDouble(getNodeAttr("sy", node)); - double ex = Double.parseDouble(getNodeAttr("ex", node)); - double ey = Double.parseDouble(getNodeAttr("ey", node)); - Point2D startPoint = new Point2D.Double(sx, sy); - Point2D endPoint = new Point2D.Double(ex, ey); - ld.addPoint(startPoint); - ld.addPoint(endPoint); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:line")) { - ld.setColor(stringToColor(getNodeAttr("color", node))); - ld.setWidth(getNodeAttr("width", node)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerFreeLine: " + node.getNodeName()); - } - } - } - return ld; - } - - /** - * Transforms LayerLine object into CellDesigner xml node. - * - * @param layer - * object to be transformed into xml - * @return CellDesigner xml node for LayerLine - */ - String layerLineToXml(PolylineData layer) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:layerFreeLine "); - result.append(" isDotted=\"" + layer.getEndAtd().getArrowLineType().equals(LineType.DOTTED) + "\" "); - result.append(" isArrow=\"" + layer.getEndAtd().getArrowType().equals(ArrowType.FULL) + "\" >"); - - result.append("<celldesigner:bounds sx=\"" + layer.getBeginPoint().getX() + "\" "); - result.append(" sy=\"" + layer.getBeginPoint().getY() + "\" "); - result.append(" ex=\"" + layer.getEndPoint().getX() + "\" "); - result.append(" ey=\"" + layer.getEndPoint().getY() + "\" />"); - result.append("<celldesigner:line "); - result.append(" width=\"" + layer.getWidth() + "\" "); - result.append(" color=\"" + colorToString(layer.getColor()) + "\"/>"); - result.append("</celldesigner:layerFreeLine>\n"); - return result.toString(); - } - - /** - * Parses CellDesigner xml node into LayerOval object. - * - * @param textNode - * CellDesigner xml node for layer text object. - * @return LayerOval instance representing the cml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - LayerOval getLayerOval(Node textNode) throws InvalidXmlSchemaException { - LayerOval result = new LayerOval(); - NodeList nodes = textNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { - result.setColor(commonParser.getColor(node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { - result.setX(getNodeAttr("x", node)); - result.setY(getNodeAttr("y", node)); - result.setWidth(getNodeAttr("w", node)); - result.setHeight(getNodeAttr("h", node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:ispaint")) { - // ??? - continue; - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerCompartmentAlias: " + node.getNodeName()); - } - } - } - return result; - } - - /** - * Transforms LayerOval object into CellDesigner xml node. - * - * @param layer - * object to be transformed into xml - * @return CellDesigner xml node for LayerOval - */ - String layerOvalToXml(LayerOval layer) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:layerCompartmentAlias type=\"Oval\">"); - result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); - result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); - result.append(" y=\"" + layer.getY() + "\" "); - result.append(" w=\"" + layer.getWidth() + "\" "); - result.append(" h=\"" + layer.getHeight() + "\"/>"); - result.append("</celldesigner:layerCompartmentAlias>"); - return result.toString(); - } - - /** - * Parses CellDesigner xml node into LayerText object. - * - * @param textNode - * CellDesigner xml node for layer text object. - * @return LayerText instance representing the cml node - * @throws InvalidXmlSchemaException - * thrown when xml node contains data that is not supported by xml - * schema - */ - LayerText getLayerText(Node textNode) throws InvalidXmlSchemaException { - LayerText result = new LayerText(); - NodeList nodes = textNode.getChildNodes(); - for (int x = 0; x < nodes.getLength(); x++) { - Node node = nodes.item(x); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (node.getNodeName().equalsIgnoreCase("celldesigner:layerNotes")) { - result.setNotes(getNodeValue(node).trim()); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { - result.setColor(commonParser.getColor(node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { - result.setX(getNodeAttr("x", node)); - result.setY(getNodeAttr("y", node)); - result.setWidth(getNodeAttr("w", node)); - result.setHeight(getNodeAttr("h", node)); - } else if (node.getNodeName().equalsIgnoreCase("celldesigner:font")) { - result.setFontSize(getNodeAttr("size", node)); - } else { - throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerSpeciesAlias: " + node.getNodeName()); - } - } - } - return result; - - } - - /** - * Transforms LayerText object into CellDesigner xml node. - * - * @param layer - * object to be transformed into xml - * @return CellDesigner xml node for LayerText - */ - String layerTextToXml(LayerText layer) { - StringBuilder result = new StringBuilder(); - result.append("<celldesigner:layerSpeciesAlias>"); - result.append("<celldesigner:layerNotes>\n"); - result.append(super.escapeXml(layer.getNotes())); - result.append("\n</celldesigner:layerNotes>"); - result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); - result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); - result.append(" y=\"" + layer.getY() + "\" "); - result.append(" w=\"" + layer.getWidth() + "\" "); - result.append(" h=\"" + layer.getHeight() + "\"/>"); - result.append("<celldesigner:font size=\"" + layer.getFontSize() + "\"/>"); - result.append("</celldesigner:layerSpeciesAlias>\n"); - return result.toString(); - } - -} +package lcsb.mapviewer.converter.model.celldesigner; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import lcsb.mapviewer.common.XmlParser; +import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; +import lcsb.mapviewer.model.graphics.ArrowType; +import lcsb.mapviewer.model.graphics.LineType; +import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.layout.alias.Alias; +import lcsb.mapviewer.model.map.layout.alias.AliasGroup; +import lcsb.mapviewer.model.map.layout.alias.BlockDiagram; +import lcsb.mapviewer.model.map.layout.graphics.Layer; +import lcsb.mapviewer.model.map.layout.graphics.LayerOval; +import lcsb.mapviewer.model.map.layout.graphics.LayerRect; +import lcsb.mapviewer.model.map.layout.graphics.LayerText; +import lcsb.mapviewer.model.map.model.Model; + +/** + * Parser used for parsing CellDesigner xml to get {@link Layer} object. + * + * @author Piotr Gawron + * + */ +public class LayerXmlParser extends XmlParser { + + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(LayerXmlParser.class.getName()); + + /** + * Parser for common CellDesigner structures. + */ + private CommonXmlParser commonParser = new CommonXmlParser(); + + /** + * PArses CellDesigner xml node with collection of layers into collection of + * Layers. + * + * @param layersNode + * xml node + * @return collection of layers + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + public Collection<Layer> parseLayers(Node layersNode) throws InvalidXmlSchemaException { + List<Layer> result = new ArrayList<Layer>(); + NodeList nodes = layersNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:layer")) { + Layer layer = getLayer(node); + result.add(layer); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfLayers: " + node.getNodeName()); + } + } + } + return result; + } + + /** + * Transforms collection of layers into CellDesigner xml node. + * + * @param layers + * collection of layers + * @return xml node representing layers collection + */ + public String layerCollectionToXml(Collection<Layer> layers) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:listOfLayers>"); + for (Layer layer : layers) { + result.append(layerToXml(layer)); + } + result.append("</celldesigner:listOfLayers>\n"); + return result.toString(); + } + + /** + * Parses collection of block diagrams and adds them into the model. + * + * @param model + * model where the data is stored. + * @param xmlNode + * xml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + public void parseBlocks(Model model, Node xmlNode) throws InvalidXmlSchemaException { + NodeList nodes = xmlNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:blockDiagram")) { + model.addBlockDiagream(getBlockDiagram(node, model)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfBlockDiagrams: " + node.getNodeName()); + } + } + } + } + + /** + * Parses block diagrams from CellDesigner xml. Important! It's not yet + * implemented. + * + * @param node + * xml node to parse + * @param model + * model where data is stored + * @return parsed block diagram + */ + private BlockDiagram getBlockDiagram(Node node, Model model) { + logger.warn("BlockDiagrams are not implemented"); + return null; + } + + /** + * Parses CellDesigner node with collection of Alias Group and adds the groups + * into this model. + * + * @param model + * model where the data is stored + * @param xmlNode + * xml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + public void parseGroups(Model model, Node xmlNode) throws InvalidXmlSchemaException { + NodeList nodes = xmlNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:group")) { + model.addAliasGroup(getAliasGroup(node, model)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfGroups: " + node.getNodeName()); + } + } + } + } + + /** + * Parses xml node for alias group. + * + * @param groupNode + * xml node + * @param model + * model where the data is stored + * @return parsed alias group + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + AliasGroup getAliasGroup(Node groupNode, Model model) throws InvalidXmlSchemaException { + AliasGroup result = new AliasGroup(); + String id = getNodeAttr("id", groupNode); + result.setIdGroup(id); + String members = getNodeAttr("members", groupNode); + + String[] list = members.split(","); + for (String string : list) { + Alias alias = model.getAliasByAliasId(string); + if (alias == null) { + throw new InvalidGroupException("Group \"" + id + "\" contains alias with id: \"" + string + "\", but such alias doesn't exist in the model."); + } + result.addAlias(alias); + } + + NodeList nodes = groupNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:group: " + node.getNodeName()); + } + } + + return result; + } + + /** + * Parses CellDesigner xml node for single layer. + * + * @param layerNode + * xml node + * @return Layer that corresponds to CellDesigner xml node. + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + Layer getLayer(Node layerNode) throws InvalidXmlSchemaException { + Layer layer = new Layer(); + layer.setLayerId(getNodeAttr("id", layerNode)); + layer.setName(getNodeAttr("name", layerNode)); + layer.setLocked(getNodeAttr("locked", layerNode)); + layer.setVisible(getNodeAttr("visible", layerNode)); + NodeList list = layerNode.getChildNodes(); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals("celldesigner:listOfTexts")) { + NodeList residueList = node.getChildNodes(); + for (int j = 0; j < residueList.getLength(); j++) { + Node textNode = residueList.item(j); + if (textNode.getNodeType() == Node.ELEMENT_NODE) { + if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerSpeciesAlias")) { + layer.addLayerText(getLayerText(textNode)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfTexts " + textNode.getNodeName()); + } + } + } + } else if (node.getNodeName().equals("celldesigner:listOfSquares")) { + NodeList residueList = node.getChildNodes(); + for (int j = 0; j < residueList.getLength(); j++) { + Node textNode = residueList.item(j); + if (textNode.getNodeType() == Node.ELEMENT_NODE) { + if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerCompartmentAlias")) { + if (getNodeAttr("type", textNode).equalsIgnoreCase("SQUARE")) { + layer.addLayerRect(getLayerRect(textNode)); + } else if (getNodeAttr("type", textNode).equalsIgnoreCase("OVAL")) { + layer.addLayerOval(getLayerOval(textNode)); + } else { + throw new InvalidXmlSchemaException("Unknown celldesigner:layerCompartmentAlias type: " + getNodeAttr("type", textNode)); + } + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfSquares " + textNode.getNodeName()); + } + } + } + } else if (node.getNodeName().equals("celldesigner:listOfFreeLines")) { + NodeList residueList = node.getChildNodes(); + for (int j = 0; j < residueList.getLength(); j++) { + Node textNode = residueList.item(j); + if (textNode.getNodeType() == Node.ELEMENT_NODE) { + if (textNode.getNodeName().equalsIgnoreCase("celldesigner:layerFreeLine")) { + layer.addLayerLine(getLayerLine(textNode)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:listOfFreeLines " + textNode.getNodeName()); + } + } + } + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:layer " + node.getNodeName()); + } + } + } + + return layer; + } + + /** + * Creates CellDesigner xml for a layer. + * + * @param layer + * object to be transformed into xml + * @return CellDesigner xml representation for the layer + */ + String layerToXml(Layer layer) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:layer id =\"" + layer.getLayerId() + "\" "); + result.append(" name =\"" + layer.getName() + "\" "); + result.append(" locked =\"" + layer.isLocked() + "\" "); + result.append(" visible =\"" + layer.isVisible() + "\">\n"); + + result.append("<celldesigner:listOfTexts>\n"); + for (LayerText layerText : layer.getTexts()) { + result.append(layerTextToXml(layerText)); + } + result.append("</celldesigner:listOfTexts>\n"); + + result.append("<celldesigner:listOfSquares>\n"); + for (LayerRect layerRect : layer.getRectangles()) { + result.append(layerRectToXml(layerRect)); + } + for (LayerOval layerOval : layer.getOvals()) { + result.append(layerOvalToXml(layerOval)); + } + result.append("</celldesigner:listOfSquares>\n"); + + result.append("<celldesigner:listOfFreeLines>\n"); + for (PolylineData layerLine : layer.getLines()) { + result.append(layerLineToXml(layerLine)); + } + result.append("</celldesigner:listOfFreeLines>\n"); + + result.append("</celldesigner:layer>\n"); + return result.toString(); + } + + /** + * Parses CellDesigner xml node into LayerRect object. + * + * @param textNode + * CellDesigner xml node for layer text object. + * @return LayerRect instance representing the cml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + LayerRect getLayerRect(Node textNode) throws InvalidXmlSchemaException { + LayerRect result = new LayerRect(); + NodeList nodes = textNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { + result.setColor(commonParser.getColor(node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { + result.setX(getNodeAttr("x", node)); + result.setY(getNodeAttr("y", node)); + result.setWidth(getNodeAttr("w", node)); + result.setHeight(getNodeAttr("h", node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:ispaint")) { + // ??? + continue; + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerCompartmentAlias: " + node.getNodeName()); + } + } + } + return result; + } + + /** + * Transforms LayerRect object into CellDesigner xml node. + * + * @param layer + * object to be transformed into xml + * @return CellDesigner xml node for LayerRect + */ + String layerRectToXml(LayerRect layer) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:layerCompartmentAlias type=\"Square\">"); + result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); + result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); + result.append(" y=\"" + layer.getY() + "\" "); + result.append(" w=\"" + layer.getWidth() + "\" "); + result.append(" h=\"" + layer.getHeight() + "\"/>"); + result.append("</celldesigner:layerCompartmentAlias>"); + return result.toString(); + } + + /** + * Parses CellDesigner xml node into LayerLine object. + * + * @param lineNode + * CellDesigner xml node for layer text object. + * @return LayerLine instance representing the cml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + PolylineData getLayerLine(Node lineNode) throws InvalidXmlSchemaException { + PolylineData ld = new PolylineData(); + + if (getNodeAttr("isDotted", lineNode).equalsIgnoreCase("true")) { + ld.getEndAtd().setArrowLineType(LineType.DOTTED); + } + if (getNodeAttr("isArrow", lineNode).equalsIgnoreCase("true")) { + ld.getEndAtd().setArrowType(ArrowType.FULL); + } + NodeList nodes = lineNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { + double sx = Double.parseDouble(getNodeAttr("sx", node)); + double sy = Double.parseDouble(getNodeAttr("sy", node)); + double ex = Double.parseDouble(getNodeAttr("ex", node)); + double ey = Double.parseDouble(getNodeAttr("ey", node)); + Point2D startPoint = new Point2D.Double(sx, sy); + Point2D endPoint = new Point2D.Double(ex, ey); + ld.addPoint(startPoint); + ld.addPoint(endPoint); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:line")) { + ld.setColor(stringToColor(getNodeAttr("color", node))); + ld.setWidth(getNodeAttr("width", node)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerFreeLine: " + node.getNodeName()); + } + } + } + return ld; + } + + /** + * Transforms LayerLine object into CellDesigner xml node. + * + * @param layer + * object to be transformed into xml + * @return CellDesigner xml node for LayerLine + */ + String layerLineToXml(PolylineData layer) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:layerFreeLine "); + result.append(" isDotted=\"" + layer.getEndAtd().getArrowLineType().equals(LineType.DOTTED) + "\" "); + result.append(" isArrow=\"" + layer.getEndAtd().getArrowType().equals(ArrowType.FULL) + "\" >"); + + result.append("<celldesigner:bounds sx=\"" + layer.getBeginPoint().getX() + "\" "); + result.append(" sy=\"" + layer.getBeginPoint().getY() + "\" "); + result.append(" ex=\"" + layer.getEndPoint().getX() + "\" "); + result.append(" ey=\"" + layer.getEndPoint().getY() + "\" />"); + result.append("<celldesigner:line "); + result.append(" width=\"" + layer.getWidth() + "\" "); + result.append(" color=\"" + colorToString(layer.getColor()) + "\"/>"); + result.append("</celldesigner:layerFreeLine>\n"); + return result.toString(); + } + + /** + * Parses CellDesigner xml node into LayerOval object. + * + * @param textNode + * CellDesigner xml node for layer text object. + * @return LayerOval instance representing the cml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + LayerOval getLayerOval(Node textNode) throws InvalidXmlSchemaException { + LayerOval result = new LayerOval(); + NodeList nodes = textNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { + result.setColor(commonParser.getColor(node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { + result.setX(getNodeAttr("x", node)); + result.setY(getNodeAttr("y", node)); + result.setWidth(getNodeAttr("w", node)); + result.setHeight(getNodeAttr("h", node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:ispaint")) { + // ??? + continue; + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerCompartmentAlias: " + node.getNodeName()); + } + } + } + return result; + } + + /** + * Transforms LayerOval object into CellDesigner xml node. + * + * @param layer + * object to be transformed into xml + * @return CellDesigner xml node for LayerOval + */ + String layerOvalToXml(LayerOval layer) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:layerCompartmentAlias type=\"Oval\">"); + result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); + result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); + result.append(" y=\"" + layer.getY() + "\" "); + result.append(" w=\"" + layer.getWidth() + "\" "); + result.append(" h=\"" + layer.getHeight() + "\"/>"); + result.append("</celldesigner:layerCompartmentAlias>"); + return result.toString(); + } + + /** + * Parses CellDesigner xml node into LayerText object. + * + * @param textNode + * CellDesigner xml node for layer text object. + * @return LayerText instance representing the cml node + * @throws InvalidXmlSchemaException + * thrown when xml node contains data that is not supported by xml + * schema + */ + LayerText getLayerText(Node textNode) throws InvalidXmlSchemaException { + LayerText result = new LayerText(); + NodeList nodes = textNode.getChildNodes(); + for (int x = 0; x < nodes.getLength(); x++) { + Node node = nodes.item(x); + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equalsIgnoreCase("celldesigner:layerNotes")) { + result.setNotes(getNodeValue(node).trim()); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) { + result.setColor(commonParser.getColor(node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:bounds")) { + result.setX(getNodeAttr("x", node)); + result.setY(getNodeAttr("y", node)); + result.setWidth(getNodeAttr("w", node)); + result.setHeight(getNodeAttr("h", node)); + } else if (node.getNodeName().equalsIgnoreCase("celldesigner:font")) { + result.setFontSize(getNodeAttr("size", node)); + } else { + throw new InvalidXmlSchemaException("Unknown element of celldesigner:layerSpeciesAlias: " + node.getNodeName()); + } + } + } + return result; + + } + + /** + * Transforms LayerText object into CellDesigner xml node. + * + * @param layer + * object to be transformed into xml + * @return CellDesigner xml node for LayerText + */ + String layerTextToXml(LayerText layer) { + StringBuilder result = new StringBuilder(); + result.append("<celldesigner:layerSpeciesAlias>"); + result.append("<celldesigner:layerNotes>\n"); + result.append(super.escapeXml(layer.getNotes())); + result.append("\n</celldesigner:layerNotes>"); + result.append("<celldesigner:paint color=\"" + colorToString(layer.getColor()) + "\"/>"); + result.append("<celldesigner:bounds x=\"" + layer.getX() + "\" "); + result.append(" y=\"" + layer.getY() + "\" "); + result.append(" w=\"" + layer.getWidth() + "\" "); + result.append(" h=\"" + layer.getHeight() + "\"/>"); + result.append("<celldesigner:font size=\"" + layer.getFontSize() + "\"/>"); + result.append("</celldesigner:layerSpeciesAlias>\n"); + return result.toString(); + } + +} diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/AllCellDesignerTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/AllCellDesignerTests.java index e37cb961ad..0d41f0455f 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/AllCellDesignerTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/AllCellDesignerTests.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -import lcsb.mapviewer.converter.model.celldesigner.alias.AllAliasTests; -import lcsb.mapviewer.converter.model.celldesigner.annotation.AllAnnotationTests; -import lcsb.mapviewer.converter.model.celldesigner.compartment.AllCompartmentTests; -import lcsb.mapviewer.converter.model.celldesigner.geometry.AllGeometryTests; -import lcsb.mapviewer.converter.model.celldesigner.reaction.AllReactionTests; -import lcsb.mapviewer.converter.model.celldesigner.species.AllSpeciesTests; -import lcsb.mapviewer.converter.model.celldesigner.structure.AllStructureTests; -import lcsb.mapviewer.converter.model.celldesigner.types.AllTypesTests; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ // - AllAnnotationTests.class, // - AllAliasTests.class, // - AllCompartmentTests.class, // - AllGeometryTests.class, // - AllReactionTests.class, // - AllSpeciesTests.class, // - AllStructureTests.class, // - AllTypesTests.class, // - CellDesignerParserExceptionTest.class, // - CellDesignerXmlParserTest.class, // - ComplexParserTests.class, // - InvalidGroupExceptionTest.class, // - LayerXmlParserTest.class, // - NestedComplexParsingTests.class, // - ReconDataInCellDesignerXmlParserTest.class,// -}) -public class AllCellDesignerTests { - -} +package lcsb.mapviewer.converter.model.celldesigner; + +import lcsb.mapviewer.converter.model.celldesigner.alias.AllAliasTests; +import lcsb.mapviewer.converter.model.celldesigner.annotation.AllAnnotationTests; +import lcsb.mapviewer.converter.model.celldesigner.compartment.AllCompartmentTests; +import lcsb.mapviewer.converter.model.celldesigner.geometry.AllGeometryTests; +import lcsb.mapviewer.converter.model.celldesigner.reaction.AllReactionTests; +import lcsb.mapviewer.converter.model.celldesigner.species.AllSpeciesTests; +import lcsb.mapviewer.converter.model.celldesigner.structure.AllStructureTests; +import lcsb.mapviewer.converter.model.celldesigner.types.AllTypesTests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ // + AllAnnotationTests.class, // + AllAliasTests.class, // + AllCompartmentTests.class, // + AllGeometryTests.class, // + AllReactionTests.class, // + AllSpeciesTests.class, // + AllStructureTests.class, // + AllTypesTests.class, // + CellDesignerParserExceptionTest.class, // + CellDesignerXmlParserTest.class, // + ComplexParserTests.class, // + InvalidGroupExceptionTest.class, // + LayerXmlParserTest.class, // + NestedComplexParsingTests.class, // + ReconDataInCellDesignerXmlParserTest.class,// +}) +public class AllCellDesignerTests { + +} diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserExceptionTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserExceptionTest.java index b586a2cc66..648b9bb0be 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserExceptionTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/CellDesignerParserExceptionTest.java @@ -1,52 +1,52 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class CellDesignerParserExceptionTest { - - private static class Tmp extends CellDesignerParserException { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public Tmp(String string) { - super(string); - } - - public Tmp() { - super(); - } - - public Tmp(String string, Exception exception) { - super(string, exception); - } - - public Tmp(Exception exception) { - super(exception); - } - - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor() { - assertNotNull(new Tmp()); - assertNotNull(new Tmp("str")); - assertNotNull(new Tmp("str2", new Exception())); - assertNotNull(new Tmp(new Exception())); - } - -} +package lcsb.mapviewer.converter.model.celldesigner; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class CellDesignerParserExceptionTest { + + private static class Tmp extends CellDesignerParserException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public Tmp(String string) { + super(string); + } + + public Tmp() { + super(); + } + + public Tmp(String string, Exception exception) { + super(string, exception); + } + + public Tmp(Exception exception) { + super(exception); + } + + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor() { + assertNotNull(new Tmp()); + assertNotNull(new Tmp("str")); + assertNotNull(new Tmp("str2", new Exception())); + assertNotNull(new Tmp(new Exception())); + } + +} diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupExceptionTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupExceptionTest.java index af15a37f2c..c04439642a 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupExceptionTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/InvalidGroupExceptionTest.java @@ -1,27 +1,27 @@ -package lcsb.mapviewer.converter.model.celldesigner; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class InvalidGroupExceptionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor() { - assertNotNull(new InvalidGroupException()); - assertNotNull(new InvalidGroupException("str")); - assertNotNull(new InvalidGroupException("str2", new Exception())); - assertNotNull(new InvalidGroupException(new Exception())); - } - -} +package lcsb.mapviewer.converter.model.celldesigner; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class InvalidGroupExceptionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor() { + assertNotNull(new InvalidGroupException()); + assertNotNull(new InvalidGroupException("str")); + assertNotNull(new InvalidGroupException("str2", new Exception())); + assertNotNull(new InvalidGroupException(new Exception())); + } + +} diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/AllReactionTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/AllReactionTests.java index 47deed84ab..aa13beebfc 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/AllReactionTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/reaction/AllReactionTests.java @@ -1,19 +1,19 @@ -package lcsb.mapviewer.converter.model.celldesigner.reaction; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ ReactionCollectionXmlParserTest.class, // - ReactionFromXmlTest.class, // - ReactionLineDataTest.class, // - ReactionParserExceptionTest.class, // - ReactionParserTests.class, // - ReactionToXmlTest.class, // - UnknownModifierClassExceptionTest.class, // - UnknownReactionClassExceptionTest.class,// -}) -public class AllReactionTests { - -} +package lcsb.mapviewer.converter.model.celldesigner.reaction; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ ReactionCollectionXmlParserTest.class, // + ReactionFromXmlTest.class, // + ReactionLineDataTest.class, // + ReactionParserExceptionTest.class, // + ReactionParserTests.class, // + ReactionToXmlTest.class, // + UnknownModifierClassExceptionTest.class, // + UnknownReactionClassExceptionTest.class,// +}) +public class AllReactionTests { + +} diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java index 097df4add0..37120db85f 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java @@ -1,440 +1,440 @@ -package lcsb.mapviewer.converter.graphics.reaction; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.geom.Ellipse2D; -import java.awt.geom.GeneralPath; -import java.awt.geom.Line2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.common.geometry.LineTransformation; -import lcsb.mapviewer.common.geometry.PointTransformation; -import lcsb.mapviewer.converter.graphics.geometry.ArrowTransformation; -import lcsb.mapviewer.model.graphics.ArrowType; -import lcsb.mapviewer.model.graphics.ArrowTypeData; -import lcsb.mapviewer.model.graphics.PolylineData; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.layout.GenericColorSchema; -import lcsb.mapviewer.model.map.reaction.AbstractNode; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.NodeOperator; -import lcsb.mapviewer.model.map.reaction.Product; -import lcsb.mapviewer.model.map.reaction.Reactant; -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.reaction.type.ReactionRect; - -/** - * Thics class allows to draw reaction on the graphics2D. - * - * @author Piotr Gawron - * - */ -public class ReactionConverter { - - /** - * When drawing operator this value defines radius of the joining operator - * circle. - */ - private static final int DEFAULT_OPERATOR_RADIUS = 6; - - /** - * Size of the rectangle drawn on the central line of the reaction. - */ - public static final double RECT_SIZE = 10; - - /** - * Default font size of reaction description. - */ - public static final int DESCRIPTION_FONT_SIZE = 10; - - /** - * Radius multiplier for bigger logic operators circles in SBGN view. - */ - public static final double SBGN_RADIUS_MULTIPLIER = 2.5; - - /** - * {@link ColorSchema} used for coloring reactions where we have more than one - * layout. - */ - public static final ColorSchema DEFAULT_COLOR_SCHEMA = new GenericColorSchema(); - - /** - * Line width of #DEFAULT_COLOR_SCHEMA used for coloring reactions where we - * have more than one layout. - */ - private static final double DEFAULT_COLOR_SCHEMA_LINE_WIDTH = 3.0; - - static { - DEFAULT_COLOR_SCHEMA.setColor(Color.BLACK); - DEFAULT_COLOR_SCHEMA.setLineWidth(DEFAULT_COLOR_SCHEMA_LINE_WIDTH); - } - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(ReactionConverter.class.getName()); - - /** - * Font used for drawing reaction description on the map. - */ - private Font descFont = null; - - /** - * Graphical helper object with line transformation functions. - */ - private LineTransformation lineTransformation = new LineTransformation(); - - /** - * This objects helps drawing arrows. - */ - private ArrowTransformation arrowTransformation = new ArrowTransformation(); - - /** - * Object used to perform transformations on point objects. - */ - private PointTransformation pointTransformation = new PointTransformation(); - - /** - * Default constructor. - */ - public ReactionConverter() { - super(); - descFont = new Font(Font.SANS_SERIF, Font.BOLD, DESCRIPTION_FONT_SIZE); - } - - /** - * This method draws a rectangle in the center of reaction (defined by line). - * - * @param line - * line on which the rectangle is drawn - * @param insideType - * type of the rectangle to be drawn - * @param graphics - * where the rectangle should be drawn - */ - protected void drawRectangleData(final Line2D line, final ReactionRect insideType, final Graphics2D graphics) { - if (insideType == null) { - graphics.draw(line); - } else { - Point2D startPoint = line.getP1(); - Point2D endPoint = line.getP2(); - double dx = endPoint.getX() - startPoint.getX(); - double dy = endPoint.getY() - startPoint.getY(); - double angle = Math.atan2(dy, dx); - - // find rectangle - Rectangle2D rect = new Rectangle2D.Double(); - double pointX = (startPoint.getX() + endPoint.getX()) / 2; - double pointY = (startPoint.getY() + endPoint.getY()) / 2; - rect.setRect(pointX - RECT_SIZE / 2, pointY - RECT_SIZE / 2, RECT_SIZE, RECT_SIZE); - - // rotate graphics by the angle defined by line (instead of rotating - // rectangle) - graphics.rotate(angle, pointX, pointY); - // fill rect - Color color = graphics.getColor(); - graphics.setColor(Color.white); - graphics.fill(rect); - graphics.setColor(color); - // draw rect border - graphics.draw(rect); - - // draw text inside rect - Font tmpFont = graphics.getFont(); - graphics.setFont(descFont); - String insideDesc = insideType.getText(); - double textWidth = graphics.getFontMetrics().stringWidth(insideDesc); - double textHeight = graphics.getFontMetrics().getAscent() - 2; - graphics.drawString(insideDesc, (int) (pointX - textWidth / 2), (int) (pointY + textHeight / 2)); - graphics.setFont(tmpFont); - - // if we should put bolt character inside then do it - if (insideType == ReactionRect.RECT_BOLT) { - GeneralPath path = new GeneralPath(); - // CHECKSTYLE:OFF - path.moveTo(pointX + 2, pointY - RECT_SIZE / 2 + 1); - path.lineTo(pointX + 2, pointY + RECT_SIZE / 2 - 3); - path.lineTo(pointX - 2, pointY - RECT_SIZE / 2 + 3); - path.lineTo(pointX - 2, pointY + RECT_SIZE / 2 - 1); - // CHECKSTYLE:ON - graphics.draw(path); - } - - // unrotate the graphics - graphics.rotate(-angle, pointX, pointY); - } - } - - /** - * Draw reaction on the graphics2D. - * - * @param reaction - * object to be drawn - * @param graphics - * where we want to draw the object - * @param sbgnFormat - * true if reaction is to be drawn in SBGN format - */ - public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat) { - Color color = graphics.getColor(); - graphics.setColor(reaction.getReactants().get(0).getLine().getColor()); - // first reactants - for (Reactant reactant : reaction.getReactants()) { - drawReactant(graphics, reactant); - } - // now products - for (Product product : reaction.getProducts()) { - drawProduct(graphics, product); - } - // draw modifiers - for (Modifier modifier : reaction.getModifiers()) { - drawModifier(graphics, modifier); - } - - // and operators - for (NodeOperator operator : reaction.getOperators()) { - drawOperator(graphics, operator, sbgnFormat); - } - - // in the end we draw rectangle in the middle - drawRectangleData(reaction.getCenterLine(), reaction.getReactionRect(), graphics); - graphics.setColor(color); - } - - /** - * Draw reaction on the graphics2D. - * - * @param reaction - * object to be drawn - * @param graphics - * where we want to draw the object - * @param sbgnFormat - * true if reaction is to be drawn in SBGN format - * @param visualizedLayoutsColorSchemas - * list of {@link ColorSchema} that were used for visualizing this - * alias in different layouts that should be overlayed on the alias - */ - public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat, List<ColorSchema> visualizedLayoutsColorSchemas) { - if (visualizedLayoutsColorSchemas.size() == 0) { - drawReaction(reaction, graphics, sbgnFormat); - } else if (visualizedLayoutsColorSchemas.size() == 1) { - if (visualizedLayoutsColorSchemas.get(0) == null) { - drawReaction(reaction, graphics, sbgnFormat); - } else { - List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); - for (AbstractNode node : reaction.getNodes()) { - oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); - } - applyColorSchema(reaction, visualizedLayoutsColorSchemas.get(0)); - drawReaction(reaction, graphics, sbgnFormat); - for (Pair<AbstractNode, PolylineData> pair : oldData) { - pair.getLeft().setLine(pair.getRight()); - } - } - } else { - int count = 0; - for (ColorSchema schema : visualizedLayoutsColorSchemas) { - if (schema != null) { - count++; - } - } - if (count == 0) { - drawReaction(reaction, graphics, sbgnFormat); - } else { - List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); - for (AbstractNode node : reaction.getNodes()) { - oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); - } - applyColorSchema(reaction, DEFAULT_COLOR_SCHEMA); - drawReaction(reaction, graphics, sbgnFormat); - for (Pair<AbstractNode, PolylineData> pair : oldData) { - pair.getLeft().setLine(pair.getRight()); - } - } - } - } - - /** - * Modify reaction with data from {@link ColorSchema}. - * - * @param reaction - * reaction to modify - * @param colorSchema - * {@link ColorSchema} to modify reaction - */ - private void applyColorSchema(Reaction reaction, ColorSchema colorSchema) { - for (AbstractNode node : reaction.getNodes()) { - PolylineData pd = new PolylineData(node.getLine()); - pd.setColor(colorSchema.getNormalizedColor()); - if (colorSchema.getLineWidth() != null) { - pd.setWidth(colorSchema.getLineWidth()); - } - if (colorSchema.getReverseReaction() != null && colorSchema.getReverseReaction()) { - ArrowTypeData atd = pd.getBeginAtd(); - pd.setBeginAtd(pd.getEndAtd()); - pd.setEndAtd(atd); - } - node.setLine(pd); - } - - } - - /** - * Draw modifier on the graphics2d. - * - * @param graphics - * where we want to draw the object - * @param modifier - * object to be drawn - */ - private void drawModifier(final Graphics2D graphics, final Modifier modifier) { - // modifier consists only from the arrow - arrowTransformation.drawLine(modifier.getLine(), graphics); - } - - /** - * Draw operator on the graphics2d. - * - * @param graphics - * where we want to draw the object - * @param operator - * object to be drawn - * @param sbgnFormat - * true if operator is to be drawn in SBGN format - */ - private void drawOperator(final Graphics2D graphics, final NodeOperator operator, boolean sbgnFormat) { - // draw line - arrowTransformation.drawLine(operator.getLine(), graphics); - - // in SBGN view - draw connecting point only if it's not connected to - // reactants or products - if (!sbgnFormat || operator.getLine().getEndAtd().getArrowType() != ArrowType.NONE - || (!operator.getOutputs().isEmpty() && operator.getOutputs().get(0) instanceof NodeOperator)) { - // and now connecting point - Point2D centerPoint = operator.getLine().getPoints().get(0); - int radius = DEFAULT_OPERATOR_RADIUS; - // bigger connecting point circles in SBGN view - if (sbgnFormat) { - radius *= SBGN_RADIUS_MULTIPLIER; - } - // it's a circle - Ellipse2D cir = new Ellipse2D.Double(centerPoint.getX() - radius, centerPoint.getY() - radius, 2 * radius, 2 * radius); - Color color = graphics.getColor(); - graphics.setColor(Color.white); - graphics.fill(cir); - graphics.setColor(operator.getLine().getColor()); - graphics.draw(cir); - // and text defined by operator - String text; - if (!sbgnFormat) { - text = operator.getOperatorText(); - } else { - text = operator.getSBGNOperatorText(); - } - Rectangle2D rect = graphics.getFontMetrics().getStringBounds(text, graphics); - graphics.drawString(text, (int) (centerPoint.getX() - rect.getWidth() / 2 + 1), (int) (centerPoint.getY() + rect.getHeight() / 2) - 2); - graphics.setColor(color); - } - } - - /** - * Draw product on the graphics2D. - * - * @param graphics - * where we want to draw the object - * @param product - * object to be drawn - */ - private void drawProduct(final Graphics2D graphics, final Product product) { - arrowTransformation.drawLine(product.getLine(), graphics); - } - - /** - * Draw reactant on the graphics2D. - * - * @param graphics - * where the reactant should be drawn - * @param reactant - * object to be drawn on the graphics - */ - private void drawReactant(final Graphics2D graphics, final Reactant reactant) { - arrowTransformation.drawLine(reactant.getLine(), graphics); - } - - /** - * - * @return {@link #descFont} - */ - protected Font getDescFont() { - return descFont; - } - - /** - * - * @param descFont - * new {@link #descFont} value - */ - protected void setDescFont(final Font descFont) { - this.descFont = descFont; - } - - /** - * - * @return {@link #lineTransformation} - */ - protected LineTransformation getLineTransformation() { - return lineTransformation; - } - - /** - * - * @param lineTransformation - * new {@link #lineTransformation} - */ - protected void setLineTransformation(final LineTransformation lineTransformation) { - this.lineTransformation = lineTransformation; - } - - /** - * - * @return {@link #arrowTransformation} - */ - protected ArrowTransformation getArrowTransformation() { - return arrowTransformation; - } - - /** - * - * @param arrowTransformation - * new {@link #arrowTransformation} - */ - protected void setArrowTransformation(final ArrowTransformation arrowTransformation) { - this.arrowTransformation = arrowTransformation; - } - - /** - * - * @return {@link #pointTransformation} - */ - protected PointTransformation getPointTransformation() { - return pointTransformation; - } - - /** - * - * @param pointTransformation - * new {@link #pointTransformation} - */ - protected void setPointTransformation(final PointTransformation pointTransformation) { - this.pointTransformation = pointTransformation; - } - +package lcsb.mapviewer.converter.graphics.reaction; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.common.geometry.LineTransformation; +import lcsb.mapviewer.common.geometry.PointTransformation; +import lcsb.mapviewer.converter.graphics.geometry.ArrowTransformation; +import lcsb.mapviewer.model.graphics.ArrowType; +import lcsb.mapviewer.model.graphics.ArrowTypeData; +import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.layout.GenericColorSchema; +import lcsb.mapviewer.model.map.reaction.AbstractNode; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.NodeOperator; +import lcsb.mapviewer.model.map.reaction.Product; +import lcsb.mapviewer.model.map.reaction.Reactant; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.model.map.reaction.type.ReactionRect; + +/** + * Thics class allows to draw reaction on the graphics2D. + * + * @author Piotr Gawron + * + */ +public class ReactionConverter { + + /** + * When drawing operator this value defines radius of the joining operator + * circle. + */ + private static final int DEFAULT_OPERATOR_RADIUS = 6; + + /** + * Size of the rectangle drawn on the central line of the reaction. + */ + public static final double RECT_SIZE = 10; + + /** + * Default font size of reaction description. + */ + public static final int DESCRIPTION_FONT_SIZE = 10; + + /** + * Radius multiplier for bigger logic operators circles in SBGN view. + */ + public static final double SBGN_RADIUS_MULTIPLIER = 2.5; + + /** + * {@link ColorSchema} used for coloring reactions where we have more than one + * layout. + */ + public static final ColorSchema DEFAULT_COLOR_SCHEMA = new GenericColorSchema(); + + /** + * Line width of #DEFAULT_COLOR_SCHEMA used for coloring reactions where we + * have more than one layout. + */ + private static final double DEFAULT_COLOR_SCHEMA_LINE_WIDTH = 3.0; + + static { + DEFAULT_COLOR_SCHEMA.setColor(Color.BLACK); + DEFAULT_COLOR_SCHEMA.setLineWidth(DEFAULT_COLOR_SCHEMA_LINE_WIDTH); + } + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(ReactionConverter.class.getName()); + + /** + * Font used for drawing reaction description on the map. + */ + private Font descFont = null; + + /** + * Graphical helper object with line transformation functions. + */ + private LineTransformation lineTransformation = new LineTransformation(); + + /** + * This objects helps drawing arrows. + */ + private ArrowTransformation arrowTransformation = new ArrowTransformation(); + + /** + * Object used to perform transformations on point objects. + */ + private PointTransformation pointTransformation = new PointTransformation(); + + /** + * Default constructor. + */ + public ReactionConverter() { + super(); + descFont = new Font(Font.SANS_SERIF, Font.BOLD, DESCRIPTION_FONT_SIZE); + } + + /** + * This method draws a rectangle in the center of reaction (defined by line). + * + * @param line + * line on which the rectangle is drawn + * @param insideType + * type of the rectangle to be drawn + * @param graphics + * where the rectangle should be drawn + */ + protected void drawRectangleData(final Line2D line, final ReactionRect insideType, final Graphics2D graphics) { + if (insideType == null) { + graphics.draw(line); + } else { + Point2D startPoint = line.getP1(); + Point2D endPoint = line.getP2(); + double dx = endPoint.getX() - startPoint.getX(); + double dy = endPoint.getY() - startPoint.getY(); + double angle = Math.atan2(dy, dx); + + // find rectangle + Rectangle2D rect = new Rectangle2D.Double(); + double pointX = (startPoint.getX() + endPoint.getX()) / 2; + double pointY = (startPoint.getY() + endPoint.getY()) / 2; + rect.setRect(pointX - RECT_SIZE / 2, pointY - RECT_SIZE / 2, RECT_SIZE, RECT_SIZE); + + // rotate graphics by the angle defined by line (instead of rotating + // rectangle) + graphics.rotate(angle, pointX, pointY); + // fill rect + Color color = graphics.getColor(); + graphics.setColor(Color.white); + graphics.fill(rect); + graphics.setColor(color); + // draw rect border + graphics.draw(rect); + + // draw text inside rect + Font tmpFont = graphics.getFont(); + graphics.setFont(descFont); + String insideDesc = insideType.getText(); + double textWidth = graphics.getFontMetrics().stringWidth(insideDesc); + double textHeight = graphics.getFontMetrics().getAscent() - 2; + graphics.drawString(insideDesc, (int) (pointX - textWidth / 2), (int) (pointY + textHeight / 2)); + graphics.setFont(tmpFont); + + // if we should put bolt character inside then do it + if (insideType == ReactionRect.RECT_BOLT) { + GeneralPath path = new GeneralPath(); + // CHECKSTYLE:OFF + path.moveTo(pointX + 2, pointY - RECT_SIZE / 2 + 1); + path.lineTo(pointX + 2, pointY + RECT_SIZE / 2 - 3); + path.lineTo(pointX - 2, pointY - RECT_SIZE / 2 + 3); + path.lineTo(pointX - 2, pointY + RECT_SIZE / 2 - 1); + // CHECKSTYLE:ON + graphics.draw(path); + } + + // unrotate the graphics + graphics.rotate(-angle, pointX, pointY); + } + } + + /** + * Draw reaction on the graphics2D. + * + * @param reaction + * object to be drawn + * @param graphics + * where we want to draw the object + * @param sbgnFormat + * true if reaction is to be drawn in SBGN format + */ + public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat) { + Color color = graphics.getColor(); + graphics.setColor(reaction.getReactants().get(0).getLine().getColor()); + // first reactants + for (Reactant reactant : reaction.getReactants()) { + drawReactant(graphics, reactant); + } + // now products + for (Product product : reaction.getProducts()) { + drawProduct(graphics, product); + } + // draw modifiers + for (Modifier modifier : reaction.getModifiers()) { + drawModifier(graphics, modifier); + } + + // and operators + for (NodeOperator operator : reaction.getOperators()) { + drawOperator(graphics, operator, sbgnFormat); + } + + // in the end we draw rectangle in the middle + drawRectangleData(reaction.getCenterLine(), reaction.getReactionRect(), graphics); + graphics.setColor(color); + } + + /** + * Draw reaction on the graphics2D. + * + * @param reaction + * object to be drawn + * @param graphics + * where we want to draw the object + * @param sbgnFormat + * true if reaction is to be drawn in SBGN format + * @param visualizedLayoutsColorSchemas + * list of {@link ColorSchema} that were used for visualizing this + * alias in different layouts that should be overlayed on the alias + */ + public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat, List<ColorSchema> visualizedLayoutsColorSchemas) { + if (visualizedLayoutsColorSchemas.size() == 0) { + drawReaction(reaction, graphics, sbgnFormat); + } else if (visualizedLayoutsColorSchemas.size() == 1) { + if (visualizedLayoutsColorSchemas.get(0) == null) { + drawReaction(reaction, graphics, sbgnFormat); + } else { + List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); + for (AbstractNode node : reaction.getNodes()) { + oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); + } + applyColorSchema(reaction, visualizedLayoutsColorSchemas.get(0)); + drawReaction(reaction, graphics, sbgnFormat); + for (Pair<AbstractNode, PolylineData> pair : oldData) { + pair.getLeft().setLine(pair.getRight()); + } + } + } else { + int count = 0; + for (ColorSchema schema : visualizedLayoutsColorSchemas) { + if (schema != null) { + count++; + } + } + if (count == 0) { + drawReaction(reaction, graphics, sbgnFormat); + } else { + List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); + for (AbstractNode node : reaction.getNodes()) { + oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); + } + applyColorSchema(reaction, DEFAULT_COLOR_SCHEMA); + drawReaction(reaction, graphics, sbgnFormat); + for (Pair<AbstractNode, PolylineData> pair : oldData) { + pair.getLeft().setLine(pair.getRight()); + } + } + } + } + + /** + * Modify reaction with data from {@link ColorSchema}. + * + * @param reaction + * reaction to modify + * @param colorSchema + * {@link ColorSchema} to modify reaction + */ + private void applyColorSchema(Reaction reaction, ColorSchema colorSchema) { + for (AbstractNode node : reaction.getNodes()) { + PolylineData pd = new PolylineData(node.getLine()); + pd.setColor(colorSchema.getNormalizedColor()); + if (colorSchema.getLineWidth() != null) { + pd.setWidth(colorSchema.getLineWidth()); + } + if (colorSchema.getReverseReaction() != null && colorSchema.getReverseReaction()) { + ArrowTypeData atd = pd.getBeginAtd(); + pd.setBeginAtd(pd.getEndAtd()); + pd.setEndAtd(atd); + } + node.setLine(pd); + } + + } + + /** + * Draw modifier on the graphics2d. + * + * @param graphics + * where we want to draw the object + * @param modifier + * object to be drawn + */ + private void drawModifier(final Graphics2D graphics, final Modifier modifier) { + // modifier consists only from the arrow + arrowTransformation.drawLine(modifier.getLine(), graphics); + } + + /** + * Draw operator on the graphics2d. + * + * @param graphics + * where we want to draw the object + * @param operator + * object to be drawn + * @param sbgnFormat + * true if operator is to be drawn in SBGN format + */ + private void drawOperator(final Graphics2D graphics, final NodeOperator operator, boolean sbgnFormat) { + // draw line + arrowTransformation.drawLine(operator.getLine(), graphics); + + // in SBGN view - draw connecting point only if it's not connected to + // reactants or products + if (!sbgnFormat || operator.getLine().getEndAtd().getArrowType() != ArrowType.NONE + || (!operator.getOutputs().isEmpty() && operator.getOutputs().get(0) instanceof NodeOperator)) { + // and now connecting point + Point2D centerPoint = operator.getLine().getPoints().get(0); + int radius = DEFAULT_OPERATOR_RADIUS; + // bigger connecting point circles in SBGN view + if (sbgnFormat) { + radius *= SBGN_RADIUS_MULTIPLIER; + } + // it's a circle + Ellipse2D cir = new Ellipse2D.Double(centerPoint.getX() - radius, centerPoint.getY() - radius, 2 * radius, 2 * radius); + Color color = graphics.getColor(); + graphics.setColor(Color.white); + graphics.fill(cir); + graphics.setColor(operator.getLine().getColor()); + graphics.draw(cir); + // and text defined by operator + String text; + if (!sbgnFormat) { + text = operator.getOperatorText(); + } else { + text = operator.getSBGNOperatorText(); + } + Rectangle2D rect = graphics.getFontMetrics().getStringBounds(text, graphics); + graphics.drawString(text, (int) (centerPoint.getX() - rect.getWidth() / 2 + 1), (int) (centerPoint.getY() + rect.getHeight() / 2) - 2); + graphics.setColor(color); + } + } + + /** + * Draw product on the graphics2D. + * + * @param graphics + * where we want to draw the object + * @param product + * object to be drawn + */ + private void drawProduct(final Graphics2D graphics, final Product product) { + arrowTransformation.drawLine(product.getLine(), graphics); + } + + /** + * Draw reactant on the graphics2D. + * + * @param graphics + * where the reactant should be drawn + * @param reactant + * object to be drawn on the graphics + */ + private void drawReactant(final Graphics2D graphics, final Reactant reactant) { + arrowTransformation.drawLine(reactant.getLine(), graphics); + } + + /** + * + * @return {@link #descFont} + */ + protected Font getDescFont() { + return descFont; + } + + /** + * + * @param descFont + * new {@link #descFont} value + */ + protected void setDescFont(final Font descFont) { + this.descFont = descFont; + } + + /** + * + * @return {@link #lineTransformation} + */ + protected LineTransformation getLineTransformation() { + return lineTransformation; + } + + /** + * + * @param lineTransformation + * new {@link #lineTransformation} + */ + protected void setLineTransformation(final LineTransformation lineTransformation) { + this.lineTransformation = lineTransformation; + } + + /** + * + * @return {@link #arrowTransformation} + */ + protected ArrowTransformation getArrowTransformation() { + return arrowTransformation; + } + + /** + * + * @param arrowTransformation + * new {@link #arrowTransformation} + */ + protected void setArrowTransformation(final ArrowTransformation arrowTransformation) { + this.arrowTransformation = arrowTransformation; + } + + /** + * + * @return {@link #pointTransformation} + */ + protected PointTransformation getPointTransformation() { + return pointTransformation; + } + + /** + * + * @param pointTransformation + * new {@link #pointTransformation} + */ + protected void setPointTransformation(final PointTransformation pointTransformation) { + this.pointTransformation = pointTransformation; + } + } \ No newline at end of file diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AndOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AndOperator.java index 8fde0ea87e..77daea75ea 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AndOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AndOperator.java @@ -1,67 +1,67 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing "and operator" between two or more nodes in the reaction. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("AND_OPERATOR_NODE") -public class AndOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(AndOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public AndOperator(AndOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public AndOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "&"; - } - - @Override - public String getSBGNOperatorText() { - return "AND"; - } - - @Override - public AndOperator copy() { - if (this.getClass() == AndOperator.class) { - return new AndOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing "and operator" between two or more nodes in the reaction. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("AND_OPERATOR_NODE") +public class AndOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(AndOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public AndOperator(AndOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public AndOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "&"; + } + + @Override + public String getSBGNOperatorText() { + return "AND"; + } + + @Override + public AndOperator copy() { + if (this.getClass() == AndOperator.class) { + return new AndOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AssociationOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AssociationOperator.java index fcdea08a0e..e8bc4d7f7e 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AssociationOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AssociationOperator.java @@ -1,64 +1,64 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing operator between two input nodes in - * {@link lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction - * HeterodimerAssociationReaction}. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("ASSOCIATION_OPERATOR_NODE") -public class AssociationOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(AssociationOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public AssociationOperator(AssociationOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public AssociationOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "&"; - } - - @Override - public AssociationOperator copy() { - if (this.getClass() == AssociationOperator.class) { - return new AssociationOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing operator between two input nodes in + * {@link lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction + * HeterodimerAssociationReaction}. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("ASSOCIATION_OPERATOR_NODE") +public class AssociationOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(AssociationOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public AssociationOperator(AssociationOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public AssociationOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "&"; + } + + @Override + public AssociationOperator copy() { + if (this.getClass() == AssociationOperator.class) { + return new AssociationOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/DissociationOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/DissociationOperator.java index 6453ede8c1..5bd1b190c6 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/DissociationOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/DissociationOperator.java @@ -1,63 +1,63 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing "dissociation operator" of one node into two or more nodes - * in the reaction (in the product part of the reaction). - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("DISSOCIATION_OPERATOR_NODE") -public class DissociationOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(DissociationOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public DissociationOperator(DissociationOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public DissociationOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "â—‹"; - } - - @Override - public DissociationOperator copy() { - if (this.getClass() == DissociationOperator.class) { - return new DissociationOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing "dissociation operator" of one node into two or more nodes + * in the reaction (in the product part of the reaction). + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("DISSOCIATION_OPERATOR_NODE") +public class DissociationOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(DissociationOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public DissociationOperator(DissociationOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public DissociationOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "â—‹"; + } + + @Override + public DissociationOperator copy() { + if (this.getClass() == DissociationOperator.class) { + return new DissociationOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NandOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NandOperator.java index bc88d04dbd..f0d4490514 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NandOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NandOperator.java @@ -1,62 +1,62 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing "not and operator" between two or more nodes in the - * reaction. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("NAND_OPERATOR_NODE") -public class NandOperator extends NodeOperator { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(NandOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public NandOperator(NandOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public NandOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "~"; - } - - @Override - public NandOperator copy() { - if (this.getClass() == NandOperator.class) { - return new NandOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing "not and operator" between two or more nodes in the + * reaction. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("NAND_OPERATOR_NODE") +public class NandOperator extends NodeOperator { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(NandOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public NandOperator(NandOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public NandOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "~"; + } + + @Override + public NandOperator copy() { + if (this.getClass() == NandOperator.class) { + return new NandOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperator.java index be989824ad..ebe7255b97 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperator.java @@ -1,265 +1,265 @@ -package lcsb.mapviewer.model.map.reaction; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; - -import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; - -/** - * One of two known types of nodes in the {@link Reaction}. It describes - * relation between two (or more) nodes in the reaction. There are few types of - * relations that are implemented: - * <ul> - * <li>{@link AndOperator} - when the output node is a result of logic - * "and operator" between two or more input nodes</li> - * <li>{@link AssociationOperator} - when the output node is a result of logic - * "and operator" between two or more input nodes</li> - * <li>{@link DissociationOperator} - when two (or more) output nodes is a - * result of dissociation of the input</li> - * <li>{@link NandOperator} - when the output node is a result of logic - * "nand operator" between two or more input nodes</li> - * <li>{@link OrOperator} - when the output node is a result of logic - * "or operator" between two or more input nodes</li> - * <li>{@link SplitOperator} - when two (or more) output nodes is a result of - * spliting (dissociation???) of the input</li> - * <li>{@link TruncationOperator} - when the output nodes are a result of - * truncation of the input. As a result we will get truncated node and the - * reminder part.</li> - * <li>{@link UnknownOperator} - when the output node is a result of logic - * operator between two or more input nodes, but the logic is unknown</li> - * </ul> - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("GENERIC_OPERATOR_NODE") -public abstract class NodeOperator extends AbstractNode { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(NodeOperator.class); - - /** - * List of input nodes. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(fetch = FetchType.EAGER, mappedBy = "nodeOperatorForInput") - @OrderBy("id") - private List<AbstractNode> inputs = new ArrayList<AbstractNode>(); - - /** - * List of output nodes. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(fetch = FetchType.EAGER, mappedBy = "nodeOperatorForOutput") - @OrderBy("id") - private List<AbstractNode> outputs = new ArrayList<AbstractNode>(); - - /** - * Default constructor. - */ - public NodeOperator() { - } - - /** - * Creates operator using the data from the original operator in the - * parameter. - * - * @param operator - * original operator from which data is initialized - */ - public NodeOperator(NodeOperator operator) { - super(operator); - - for (AbstractNode node : operator.getInputs()) { - addInput(node); - } - for (AbstractNode node : operator.getOutputs()) { - addOutput(node); - } - } - - /** - * Adds input node. - * - * @param node - * node to add - */ - public void addInput(AbstractNode node) { - node.setNodeOperatorForInput(this); - if (inputs.contains(node)) { - throw new InvalidArgumentException("Node already on the list: " + node); - } - inputs.add(node); - } - - /** - * Adds set of inputs. - * - * @param newInputs - * set of input nodes to add - */ - public void addInputs(Collection<? extends AbstractNode> newInputs) { - for (AbstractNode input : newInputs) { - addInput(input); - } - } - - /** - * Checks if the operator connects several inputs to one output. - * - * @return <code>true</code> if the operator connects several inputs to one - * output, <code>false</code> otherwise - */ - public boolean isReactantOperator() { - for (AbstractNode node : inputs) { - if (node instanceof Reactant) { - return true; - } - if (node instanceof NodeOperator) { - if (((NodeOperator) node).isReactantOperator()) { - return true; - } - } - - } - return false; - } - - /** - * Adds output to the operator. - * - * @param node - * output node to add - */ - public void addOutput(AbstractNode node) { - node.setNodeOperatorForOutput(this); - if (outputs.contains(node)) { - throw new InvalidArgumentException("Node already on the list: " + node); - } - outputs.add(node); - } - - /** - * Checks if the operator connects one input to several outputs. - * - * @return <code>true</code> if the operator connects one input to several - * outputs, <code>false</code> otherwise - */ - public boolean isProductOperator() { - for (AbstractNode node : outputs) { - if (node instanceof Product) { - return true; - } - if (node instanceof NodeOperator) { - if (((NodeOperator) node).isProductOperator()) { - return true; - } - } - } - return false; - } - - /** - * Returns one character length description of the operator. - * - * @return one character length description of the operator - */ - public abstract String getOperatorText(); - - /** - * Returns SBGN description of the operator. - * - * @return SBGN description of the operator - */ - public String getSBGNOperatorText() { - return getOperatorText(); - } - - /** - * Checks if the operator connects several inputs (that are modifiers) to one - * output. - * - * @return <code>true</code> if the operator connects several inputs (that are - * modifiers) to one output, <code>false</code> otherwise - */ - public boolean isModifierOperator() { - for (AbstractNode node : inputs) { - if (node instanceof Modifier) { - return true; - } - if (node instanceof NodeOperator) { - if (((NodeOperator) node).isModifierOperator()) { - return true; - } - } - } - return false; - } - - /** - * Adds outputs to the operator. - * - * @param newOutputs - * output nodes to add - */ - public void addOutputs(Collection<? extends AbstractNode> newOutputs) { - for (AbstractNode output : newOutputs) { - addOutput(output); - } - } - - /** - * @return the inputs - * @see #inputs - */ - public List<AbstractNode> getInputs() { - return inputs; - } - - /** - * @param inputs - * the inputs to set - * @see #inputs - */ - public void setInputs(List<AbstractNode> inputs) { - this.inputs = inputs; - } - - /** - * @return the outputs - * @see #outputs - */ - public List<AbstractNode> getOutputs() { - return outputs; - } - - /** - * @param outputs - * the outputs to set - * @see #outputs - */ - public void setOutputs(List<AbstractNode> outputs) { - this.outputs = outputs; - } - -} +package lcsb.mapviewer.model.map.reaction; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; + +import org.apache.log4j.Logger; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; + +/** + * One of two known types of nodes in the {@link Reaction}. It describes + * relation between two (or more) nodes in the reaction. There are few types of + * relations that are implemented: + * <ul> + * <li>{@link AndOperator} - when the output node is a result of logic + * "and operator" between two or more input nodes</li> + * <li>{@link AssociationOperator} - when the output node is a result of logic + * "and operator" between two or more input nodes</li> + * <li>{@link DissociationOperator} - when two (or more) output nodes is a + * result of dissociation of the input</li> + * <li>{@link NandOperator} - when the output node is a result of logic + * "nand operator" between two or more input nodes</li> + * <li>{@link OrOperator} - when the output node is a result of logic + * "or operator" between two or more input nodes</li> + * <li>{@link SplitOperator} - when two (or more) output nodes is a result of + * spliting (dissociation???) of the input</li> + * <li>{@link TruncationOperator} - when the output nodes are a result of + * truncation of the input. As a result we will get truncated node and the + * reminder part.</li> + * <li>{@link UnknownOperator} - when the output node is a result of logic + * operator between two or more input nodes, but the logic is unknown</li> + * </ul> + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("GENERIC_OPERATOR_NODE") +public abstract class NodeOperator extends AbstractNode { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(NodeOperator.class); + + /** + * List of input nodes. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(fetch = FetchType.EAGER, mappedBy = "nodeOperatorForInput") + @OrderBy("id") + private List<AbstractNode> inputs = new ArrayList<AbstractNode>(); + + /** + * List of output nodes. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(fetch = FetchType.EAGER, mappedBy = "nodeOperatorForOutput") + @OrderBy("id") + private List<AbstractNode> outputs = new ArrayList<AbstractNode>(); + + /** + * Default constructor. + */ + public NodeOperator() { + } + + /** + * Creates operator using the data from the original operator in the + * parameter. + * + * @param operator + * original operator from which data is initialized + */ + public NodeOperator(NodeOperator operator) { + super(operator); + + for (AbstractNode node : operator.getInputs()) { + addInput(node); + } + for (AbstractNode node : operator.getOutputs()) { + addOutput(node); + } + } + + /** + * Adds input node. + * + * @param node + * node to add + */ + public void addInput(AbstractNode node) { + node.setNodeOperatorForInput(this); + if (inputs.contains(node)) { + throw new InvalidArgumentException("Node already on the list: " + node); + } + inputs.add(node); + } + + /** + * Adds set of inputs. + * + * @param newInputs + * set of input nodes to add + */ + public void addInputs(Collection<? extends AbstractNode> newInputs) { + for (AbstractNode input : newInputs) { + addInput(input); + } + } + + /** + * Checks if the operator connects several inputs to one output. + * + * @return <code>true</code> if the operator connects several inputs to one + * output, <code>false</code> otherwise + */ + public boolean isReactantOperator() { + for (AbstractNode node : inputs) { + if (node instanceof Reactant) { + return true; + } + if (node instanceof NodeOperator) { + if (((NodeOperator) node).isReactantOperator()) { + return true; + } + } + + } + return false; + } + + /** + * Adds output to the operator. + * + * @param node + * output node to add + */ + public void addOutput(AbstractNode node) { + node.setNodeOperatorForOutput(this); + if (outputs.contains(node)) { + throw new InvalidArgumentException("Node already on the list: " + node); + } + outputs.add(node); + } + + /** + * Checks if the operator connects one input to several outputs. + * + * @return <code>true</code> if the operator connects one input to several + * outputs, <code>false</code> otherwise + */ + public boolean isProductOperator() { + for (AbstractNode node : outputs) { + if (node instanceof Product) { + return true; + } + if (node instanceof NodeOperator) { + if (((NodeOperator) node).isProductOperator()) { + return true; + } + } + } + return false; + } + + /** + * Returns one character length description of the operator. + * + * @return one character length description of the operator + */ + public abstract String getOperatorText(); + + /** + * Returns SBGN description of the operator. + * + * @return SBGN description of the operator + */ + public String getSBGNOperatorText() { + return getOperatorText(); + } + + /** + * Checks if the operator connects several inputs (that are modifiers) to one + * output. + * + * @return <code>true</code> if the operator connects several inputs (that are + * modifiers) to one output, <code>false</code> otherwise + */ + public boolean isModifierOperator() { + for (AbstractNode node : inputs) { + if (node instanceof Modifier) { + return true; + } + if (node instanceof NodeOperator) { + if (((NodeOperator) node).isModifierOperator()) { + return true; + } + } + } + return false; + } + + /** + * Adds outputs to the operator. + * + * @param newOutputs + * output nodes to add + */ + public void addOutputs(Collection<? extends AbstractNode> newOutputs) { + for (AbstractNode output : newOutputs) { + addOutput(output); + } + } + + /** + * @return the inputs + * @see #inputs + */ + public List<AbstractNode> getInputs() { + return inputs; + } + + /** + * @param inputs + * the inputs to set + * @see #inputs + */ + public void setInputs(List<AbstractNode> inputs) { + this.inputs = inputs; + } + + /** + * @return the outputs + * @see #outputs + */ + public List<AbstractNode> getOutputs() { + return outputs; + } + + /** + * @param outputs + * the outputs to set + * @see #outputs + */ + public void setOutputs(List<AbstractNode> outputs) { + this.outputs = outputs; + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperatorComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperatorComparator.java index 349253b0f7..97b0927379 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperatorComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/NodeOperatorComparator.java @@ -1,135 +1,135 @@ -package lcsb.mapviewer.model.map.reaction; - -import java.util.Comparator; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.comparator.IntegerComparator; - -/** - * This class implements comparator interface for {@link NodeOperator}. It also - * handles comparison of subclasses of {@link NodeOperator} class. - * - * - * @author Piotr Gawron - * - */ -public class NodeOperatorComparator implements Comparator<NodeOperator> { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(NodeOperatorComparator.class); - - /** - * Epsilon value used for comparison of doubles. - */ - private double epsilon; - - /** - * Constructor that requires {@link #epsilon} parameter. - * - * @param epsilon - * {@link #epsilon} - */ - public NodeOperatorComparator(double epsilon) { - this.epsilon = epsilon; - } - - /** - * Default constructor. - */ - public NodeOperatorComparator() { - this(Configuration.EPSILON); - } - - @Override - public int compare(NodeOperator arg0, NodeOperator arg1) { - if (arg0 == null) { - if (arg1 == null) { - return 0; - } else { - return 1; - } - } else if (arg1 == null) { - return -1; - } - - if (arg0.getClass().equals(arg1.getClass())) { - return internalCompare(arg0, arg1); - } else { - logger.debug("Different classes."); - return -1; - } - } - - /** - * This method compare all fields of two node operators and return 0 if they - * are the same or 1/-1 if the objects are different. Also comparator for - * super class ({@link AbstractNode}) is called. - * - * @param arg0 - * first object to compare - * @param arg1 - * second object to compare - * @return 0 if objects are equal,<br> - * -1/1 otherwise - */ - - private int internalCompare(NodeOperator arg0, NodeOperator arg1) { - AbstractNodeComparator anComparator = new AbstractNodeComparator(epsilon); - - int result = anComparator.internalCompare(arg0, arg1); - if (result != 0) { - logger.debug("Different Abstract Nodes: " + arg0 + ", " + arg1); - return result; - } - - IntegerComparator integerComparator = new IntegerComparator(); - - if (integerComparator.compare(arg0.getInputs().size(), arg1.getInputs().size()) != 0) { - logger.debug("Different input size: " + arg0.getInputs().size() + ", " + arg1.getInputs().size()); - return integerComparator.compare(arg0.getInputs().size(), arg1.getInputs().size()); - } - if (integerComparator.compare(arg0.getOutputs().size(), arg1.getOutputs().size()) != 0) { - logger.debug("Different output size: " + arg0.getOutputs().size() + ", " + arg1.getOutputs().size()); - return integerComparator.compare(arg0.getOutputs().size(), arg1.getOutputs().size()); - } - - for (int i = 0; i < arg0.getInputs().size(); i++) { - AbstractNode node1 = arg0.getInputs().get(i); - int status = -1; - for (int j = 0; j < arg1.getInputs().size(); j++) { - AbstractNode node2 = arg1.getInputs().get(j); - int tmpStatus = anComparator.compare(node1, node2); - if (tmpStatus == 0) { - status = 0; - break; - } - } - if (status != 0) { - logger.debug("Can't find match in inputs."); - return status; - } - } - for (int i = 0; i < arg0.getOutputs().size(); i++) { - AbstractNode node1 = arg0.getOutputs().get(i); - int status = -1; - for (int j = 0; j < arg1.getOutputs().size(); j++) { - AbstractNode node2 = arg1.getOutputs().get(j); - int tmpStatus = anComparator.compare(node1, node2); - if (tmpStatus == 0) { - status = 0; - break; - } - } - if (status != 0) { - logger.debug("Can't find match in outputs."); - return status; - } - } - - return 0; - } - -} +package lcsb.mapviewer.model.map.reaction; + +import java.util.Comparator; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.comparator.IntegerComparator; + +/** + * This class implements comparator interface for {@link NodeOperator}. It also + * handles comparison of subclasses of {@link NodeOperator} class. + * + * + * @author Piotr Gawron + * + */ +public class NodeOperatorComparator implements Comparator<NodeOperator> { + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(NodeOperatorComparator.class); + + /** + * Epsilon value used for comparison of doubles. + */ + private double epsilon; + + /** + * Constructor that requires {@link #epsilon} parameter. + * + * @param epsilon + * {@link #epsilon} + */ + public NodeOperatorComparator(double epsilon) { + this.epsilon = epsilon; + } + + /** + * Default constructor. + */ + public NodeOperatorComparator() { + this(Configuration.EPSILON); + } + + @Override + public int compare(NodeOperator arg0, NodeOperator arg1) { + if (arg0 == null) { + if (arg1 == null) { + return 0; + } else { + return 1; + } + } else if (arg1 == null) { + return -1; + } + + if (arg0.getClass().equals(arg1.getClass())) { + return internalCompare(arg0, arg1); + } else { + logger.debug("Different classes."); + return -1; + } + } + + /** + * This method compare all fields of two node operators and return 0 if they + * are the same or 1/-1 if the objects are different. Also comparator for + * super class ({@link AbstractNode}) is called. + * + * @param arg0 + * first object to compare + * @param arg1 + * second object to compare + * @return 0 if objects are equal,<br> + * -1/1 otherwise + */ + + private int internalCompare(NodeOperator arg0, NodeOperator arg1) { + AbstractNodeComparator anComparator = new AbstractNodeComparator(epsilon); + + int result = anComparator.internalCompare(arg0, arg1); + if (result != 0) { + logger.debug("Different Abstract Nodes: " + arg0 + ", " + arg1); + return result; + } + + IntegerComparator integerComparator = new IntegerComparator(); + + if (integerComparator.compare(arg0.getInputs().size(), arg1.getInputs().size()) != 0) { + logger.debug("Different input size: " + arg0.getInputs().size() + ", " + arg1.getInputs().size()); + return integerComparator.compare(arg0.getInputs().size(), arg1.getInputs().size()); + } + if (integerComparator.compare(arg0.getOutputs().size(), arg1.getOutputs().size()) != 0) { + logger.debug("Different output size: " + arg0.getOutputs().size() + ", " + arg1.getOutputs().size()); + return integerComparator.compare(arg0.getOutputs().size(), arg1.getOutputs().size()); + } + + for (int i = 0; i < arg0.getInputs().size(); i++) { + AbstractNode node1 = arg0.getInputs().get(i); + int status = -1; + for (int j = 0; j < arg1.getInputs().size(); j++) { + AbstractNode node2 = arg1.getInputs().get(j); + int tmpStatus = anComparator.compare(node1, node2); + if (tmpStatus == 0) { + status = 0; + break; + } + } + if (status != 0) { + logger.debug("Can't find match in inputs."); + return status; + } + } + for (int i = 0; i < arg0.getOutputs().size(); i++) { + AbstractNode node1 = arg0.getOutputs().get(i); + int status = -1; + for (int j = 0; j < arg1.getOutputs().size(); j++) { + AbstractNode node2 = arg1.getOutputs().get(j); + int tmpStatus = anComparator.compare(node1, node2); + if (tmpStatus == 0) { + status = 0; + break; + } + } + if (status != 0) { + logger.debug("Can't find match in outputs."); + return status; + } + } + + return 0; + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/OrOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/OrOperator.java index 267fab63a6..7995a1572d 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/OrOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/OrOperator.java @@ -1,68 +1,68 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing boolean "or operator" between two or more nodes in the - * reaction. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("OR_OPERATOR_NODE") -public class OrOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(OrOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public OrOperator(OrOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public OrOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "|"; - } - - @Override - public String getSBGNOperatorText() { - return "OR"; - } - - @Override - public OrOperator copy() { - if (this.getClass() == OrOperator.class) { - return new OrOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing boolean "or operator" between two or more nodes in the + * reaction. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("OR_OPERATOR_NODE") +public class OrOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(OrOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public OrOperator(OrOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public OrOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "|"; + } + + @Override + public String getSBGNOperatorText() { + return "OR"; + } + + @Override + public OrOperator copy() { + if (this.getClass() == OrOperator.class) { + return new OrOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionComparator.java index 5972fde52c..38a1265d1d 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionComparator.java @@ -1,210 +1,210 @@ -package lcsb.mapviewer.model.map.reaction; - -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; - -import org.apache.log4j.Logger; - -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.StringComparator; -import lcsb.mapviewer.common.comparator.StringListComparator; -import lcsb.mapviewer.common.comparator.StringSetComparator; -import lcsb.mapviewer.model.map.MiriamData; - -/** - * This class implements comparator interface for {@link Reaction}. - * - * @author Piotr Gawron - * - */ -public class ReactionComparator implements Comparator<Reaction> { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(ReactionComparator.class); - - /** - * Epsilon value used for comparison of doubles. - */ - private double epsilon; - - /** - * Constructor that requires {@link #epsilon} parameter. - * - * @param epsilon - * {@link #epsilon} - */ - public ReactionComparator(double epsilon) { - this.epsilon = epsilon; - } - - /** - * Default constructor. - */ - public ReactionComparator() { - this(Configuration.EPSILON); - } - - @Override - public int compare(Reaction arg0, Reaction arg1) { - if (arg0 == null) { - if (arg1 == null) { - return 0; - } else { - return 1; - } - } else if (arg1 == null) { - return -1; - } - - if (arg0.getClass().equals(arg1.getClass())) { - return internalCompare(arg0, arg1); - } else { - logger.debug("Different class: " + arg0.getClass() + ", " + arg1.getClass()); - return -1; - } - } - - /** - * This method compares only the fields that are defined in {@link Reaction} - * class in inheritence tree. - * - * @param arg0 - * first object to compare - * @param arg1 - * second object to compare - * @return if all fields are qual then returns 0. If they are different then - * -1/1 is returned. - */ - public int internalCompare(Reaction arg0, Reaction arg1) { - StringComparator stringComparator = new StringComparator(); - BooleanComparator booleanComparator = new BooleanComparator(); - AbstractNodeComparator aNodeComparator = new AbstractNodeComparator(epsilon); - - if (stringComparator.compare(arg0.getName(), arg1.getName()) != 0) { - logger.debug("Name different: " + arg0.getName() + ", " + arg1.getName()); - return stringComparator.compare(arg0.getName(), arg1.getName()); - } - - if (stringComparator.compare(arg0.getNotes().trim(), arg1.getNotes().trim()) != 0) { - logger.debug("Notes different: " + arg0.getNotes() + ", " + arg1.getNotes()); - return stringComparator.compare(arg0.getNotes(), arg1.getNotes()); - } - - - if (stringComparator.compare(arg0.getIdReaction(), arg1.getIdReaction()) != 0) { - logger.debug("IdReaction different: " + arg0.getIdReaction() + ", " + arg1.getIdReaction()); - return stringComparator.compare(arg0.getIdReaction(), arg1.getIdReaction()); - } - - if (booleanComparator.compare(arg0.isReversible(), arg1.isReversible()) != 0) { - logger.debug("Reversible different: " + arg0.isReversible() + ", " + arg1.isReversible()); - return booleanComparator.compare(arg0.isReversible(), arg1.isReversible()); - } - - if (booleanComparator.compare(arg0.isKineticLaw(), arg1.isKineticLaw()) != 0) { - logger.debug("KineticLaw different: " + arg0.isKineticLaw() + ", " + arg1.isKineticLaw()); - return booleanComparator.compare(arg0.isKineticLaw(), arg1.isKineticLaw()); - } - - if (stringComparator.compare(arg0.getSymbol(), arg1.getSymbol()) != 0) { - logger.debug("Symbol different: " + arg0.getSymbol() + ", " + arg1.getSymbol()); - return stringComparator.compare(arg0.getSymbol(), arg1.getSymbol()); - } - if (stringComparator.compare(arg0.getAbbreviation(), arg1.getAbbreviation()) != 0) { - logger.debug("abbreviation different: " + arg0.getAbbreviation() + ", " + arg1.getAbbreviation()); - return stringComparator.compare(arg0.getAbbreviation(), arg1.getAbbreviation()); - } - if (stringComparator.compare(arg0.getFormula(), arg1.getFormula()) != 0) { - logger.debug("Formula different: " + arg0.getFormula() + ", " + arg1.getFormula()); - return stringComparator.compare(arg0.getFormula(), arg1.getFormula()); - } - if (stringComparator.compare(arg0.getSubsystem(), arg1.getSubsystem()) != 0) { - logger.debug("Subsystem different: " + arg0.getSubsystem() + ", " + arg1.getSubsystem()); - return stringComparator.compare(arg0.getSubsystem(), arg1.getSubsystem()); - } - if (stringComparator.compare(arg0.getGeneProteinReaction(), arg1.getGeneProteinReaction()) != 0) { - logger.debug("GeneProteinReaction different: " + arg0.getGeneProteinReaction() + ", " + arg1.getGeneProteinReaction()); - return stringComparator.compare(arg0.getGeneProteinReaction(), arg1.getGeneProteinReaction()); - } - - IntegerComparator integerComparator = new IntegerComparator(); - - if (integerComparator.compare(arg0.getMechanicalConfidenceScore(), arg1.getMechanicalConfidenceScore()) != 0) { - logger.debug("MechanicalConfidenceScore different: " + arg0.getMechanicalConfidenceScore() + ", " + arg1.getMechanicalConfidenceScore()); - return integerComparator.compare(arg0.getMechanicalConfidenceScore(), arg1.getMechanicalConfidenceScore()); - } - - DoubleComparator doubleComparator = new DoubleComparator(epsilon); - if (doubleComparator.compare(arg0.getLowerBound(), arg1.getLowerBound()) != 0) { - logger.debug("LowerBound different: " + arg0.getLowerBound() + ", " + arg1.getLowerBound()); - return doubleComparator.compare(arg0.getLowerBound(), arg1.getLowerBound()); - } - if (doubleComparator.compare(arg0.getUpperBound(), arg1.getUpperBound()) != 0) { - logger.debug("UpperBound different: " + arg0.getUpperBound() + ", " + arg1.getUpperBound()); - return doubleComparator.compare(arg0.getUpperBound(), arg1.getUpperBound()); - } - - StringListComparator stringListComparator = new StringListComparator(); - - if (stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()) != 0) { - logger.debug("Synonyms dataset different"); - return stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()); - } - - Set<String> hashCode1 = new HashSet<String>(); - Set<String> hashCode2 = new HashSet<String>(); - - for (MiriamData md : arg0.getMiriamData()) { - String hash = md.getRelationType() + " " + md.getDataType() + " " + md.getResource(); - hashCode1.add(hash); - } - - for (MiriamData md : arg1.getMiriamData()) { - String hash = md.getRelationType() + " " + md.getDataType() + " " + md.getResource(); - hashCode2.add(hash); - } - - StringSetComparator stringSetComparator = new StringSetComparator(); - if (stringSetComparator.compare(hashCode1, hashCode2) != 0) { - logger.debug("Miriam dataset different"); - return stringSetComparator.compare(hashCode1, hashCode2); - } - - if (arg0.getNodes().size() != arg1.getNodes().size()) { - logger.debug("Different number of nodes: " + arg0.getNodes().size() + ", " + arg1.getNodes().size()); - return ((Integer) arg0.getNodes().size()).compareTo(arg1.getNodes().size()); - } - - /** Changed **/ - for (int i = 0; i < arg0.getNodes().size(); i++) { - int status = -1; - for (int j = 0; j < arg1.getNodes().size(); j++) { - int tmpStatus = aNodeComparator.compare(arg0.getNodes().get(i), arg1.getNodes().get(j)); - if (tmpStatus == 0) { - status = 0; - break; - } - } - // int status = reactionNodeComparator.compare(arg0.getNodes().get(i), - // arg1.getNodes().get(i)); - if (status != 0) { - logger.debug("Can't find matching node for: " + arg0.getNodes().get(i)); - // logger.debug("Different node: " + - // arg0.getNodes().get(i).getElement().getName() + ", " + - // arg1.getNodes().get(i).getElement().getName()); - // logger.debug("Different node: " + arg0.getNodes().get(i) + ", " + - // arg1.getNodes().get(i)); - // logger.debug(arg0.getNodes().size()); - return status; - } - } - - return 0; - } - -} +package lcsb.mapviewer.model.map.reaction; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; + +import org.apache.log4j.Logger; + +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.StringComparator; +import lcsb.mapviewer.common.comparator.StringListComparator; +import lcsb.mapviewer.common.comparator.StringSetComparator; +import lcsb.mapviewer.model.map.MiriamData; + +/** + * This class implements comparator interface for {@link Reaction}. + * + * @author Piotr Gawron + * + */ +public class ReactionComparator implements Comparator<Reaction> { + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(ReactionComparator.class); + + /** + * Epsilon value used for comparison of doubles. + */ + private double epsilon; + + /** + * Constructor that requires {@link #epsilon} parameter. + * + * @param epsilon + * {@link #epsilon} + */ + public ReactionComparator(double epsilon) { + this.epsilon = epsilon; + } + + /** + * Default constructor. + */ + public ReactionComparator() { + this(Configuration.EPSILON); + } + + @Override + public int compare(Reaction arg0, Reaction arg1) { + if (arg0 == null) { + if (arg1 == null) { + return 0; + } else { + return 1; + } + } else if (arg1 == null) { + return -1; + } + + if (arg0.getClass().equals(arg1.getClass())) { + return internalCompare(arg0, arg1); + } else { + logger.debug("Different class: " + arg0.getClass() + ", " + arg1.getClass()); + return -1; + } + } + + /** + * This method compares only the fields that are defined in {@link Reaction} + * class in inheritence tree. + * + * @param arg0 + * first object to compare + * @param arg1 + * second object to compare + * @return if all fields are qual then returns 0. If they are different then + * -1/1 is returned. + */ + public int internalCompare(Reaction arg0, Reaction arg1) { + StringComparator stringComparator = new StringComparator(); + BooleanComparator booleanComparator = new BooleanComparator(); + AbstractNodeComparator aNodeComparator = new AbstractNodeComparator(epsilon); + + if (stringComparator.compare(arg0.getName(), arg1.getName()) != 0) { + logger.debug("Name different: " + arg0.getName() + ", " + arg1.getName()); + return stringComparator.compare(arg0.getName(), arg1.getName()); + } + + if (stringComparator.compare(arg0.getNotes().trim(), arg1.getNotes().trim()) != 0) { + logger.debug("Notes different: " + arg0.getNotes() + ", " + arg1.getNotes()); + return stringComparator.compare(arg0.getNotes(), arg1.getNotes()); + } + + + if (stringComparator.compare(arg0.getIdReaction(), arg1.getIdReaction()) != 0) { + logger.debug("IdReaction different: " + arg0.getIdReaction() + ", " + arg1.getIdReaction()); + return stringComparator.compare(arg0.getIdReaction(), arg1.getIdReaction()); + } + + if (booleanComparator.compare(arg0.isReversible(), arg1.isReversible()) != 0) { + logger.debug("Reversible different: " + arg0.isReversible() + ", " + arg1.isReversible()); + return booleanComparator.compare(arg0.isReversible(), arg1.isReversible()); + } + + if (booleanComparator.compare(arg0.isKineticLaw(), arg1.isKineticLaw()) != 0) { + logger.debug("KineticLaw different: " + arg0.isKineticLaw() + ", " + arg1.isKineticLaw()); + return booleanComparator.compare(arg0.isKineticLaw(), arg1.isKineticLaw()); + } + + if (stringComparator.compare(arg0.getSymbol(), arg1.getSymbol()) != 0) { + logger.debug("Symbol different: " + arg0.getSymbol() + ", " + arg1.getSymbol()); + return stringComparator.compare(arg0.getSymbol(), arg1.getSymbol()); + } + if (stringComparator.compare(arg0.getAbbreviation(), arg1.getAbbreviation()) != 0) { + logger.debug("abbreviation different: " + arg0.getAbbreviation() + ", " + arg1.getAbbreviation()); + return stringComparator.compare(arg0.getAbbreviation(), arg1.getAbbreviation()); + } + if (stringComparator.compare(arg0.getFormula(), arg1.getFormula()) != 0) { + logger.debug("Formula different: " + arg0.getFormula() + ", " + arg1.getFormula()); + return stringComparator.compare(arg0.getFormula(), arg1.getFormula()); + } + if (stringComparator.compare(arg0.getSubsystem(), arg1.getSubsystem()) != 0) { + logger.debug("Subsystem different: " + arg0.getSubsystem() + ", " + arg1.getSubsystem()); + return stringComparator.compare(arg0.getSubsystem(), arg1.getSubsystem()); + } + if (stringComparator.compare(arg0.getGeneProteinReaction(), arg1.getGeneProteinReaction()) != 0) { + logger.debug("GeneProteinReaction different: " + arg0.getGeneProteinReaction() + ", " + arg1.getGeneProteinReaction()); + return stringComparator.compare(arg0.getGeneProteinReaction(), arg1.getGeneProteinReaction()); + } + + IntegerComparator integerComparator = new IntegerComparator(); + + if (integerComparator.compare(arg0.getMechanicalConfidenceScore(), arg1.getMechanicalConfidenceScore()) != 0) { + logger.debug("MechanicalConfidenceScore different: " + arg0.getMechanicalConfidenceScore() + ", " + arg1.getMechanicalConfidenceScore()); + return integerComparator.compare(arg0.getMechanicalConfidenceScore(), arg1.getMechanicalConfidenceScore()); + } + + DoubleComparator doubleComparator = new DoubleComparator(epsilon); + if (doubleComparator.compare(arg0.getLowerBound(), arg1.getLowerBound()) != 0) { + logger.debug("LowerBound different: " + arg0.getLowerBound() + ", " + arg1.getLowerBound()); + return doubleComparator.compare(arg0.getLowerBound(), arg1.getLowerBound()); + } + if (doubleComparator.compare(arg0.getUpperBound(), arg1.getUpperBound()) != 0) { + logger.debug("UpperBound different: " + arg0.getUpperBound() + ", " + arg1.getUpperBound()); + return doubleComparator.compare(arg0.getUpperBound(), arg1.getUpperBound()); + } + + StringListComparator stringListComparator = new StringListComparator(); + + if (stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()) != 0) { + logger.debug("Synonyms dataset different"); + return stringListComparator.compare(arg0.getSynonyms(), arg1.getSynonyms()); + } + + Set<String> hashCode1 = new HashSet<String>(); + Set<String> hashCode2 = new HashSet<String>(); + + for (MiriamData md : arg0.getMiriamData()) { + String hash = md.getRelationType() + " " + md.getDataType() + " " + md.getResource(); + hashCode1.add(hash); + } + + for (MiriamData md : arg1.getMiriamData()) { + String hash = md.getRelationType() + " " + md.getDataType() + " " + md.getResource(); + hashCode2.add(hash); + } + + StringSetComparator stringSetComparator = new StringSetComparator(); + if (stringSetComparator.compare(hashCode1, hashCode2) != 0) { + logger.debug("Miriam dataset different"); + return stringSetComparator.compare(hashCode1, hashCode2); + } + + if (arg0.getNodes().size() != arg1.getNodes().size()) { + logger.debug("Different number of nodes: " + arg0.getNodes().size() + ", " + arg1.getNodes().size()); + return ((Integer) arg0.getNodes().size()).compareTo(arg1.getNodes().size()); + } + + /** Changed **/ + for (int i = 0; i < arg0.getNodes().size(); i++) { + int status = -1; + for (int j = 0; j < arg1.getNodes().size(); j++) { + int tmpStatus = aNodeComparator.compare(arg0.getNodes().get(i), arg1.getNodes().get(j)); + if (tmpStatus == 0) { + status = 0; + break; + } + } + // int status = reactionNodeComparator.compare(arg0.getNodes().get(i), + // arg1.getNodes().get(i)); + if (status != 0) { + logger.debug("Can't find matching node for: " + arg0.getNodes().get(i)); + // logger.debug("Different node: " + + // arg0.getNodes().get(i).getElement().getName() + ", " + + // arg1.getNodes().get(i).getElement().getName()); + // logger.debug("Different node: " + arg0.getNodes().get(i) + ", " + + // arg1.getNodes().get(i)); + // logger.debug(arg0.getNodes().size()); + return status; + } + } + + return 0; + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionNodeComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionNodeComparator.java index 6eb568ed1b..69b596dcfc 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionNodeComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/ReactionNodeComparator.java @@ -1,101 +1,101 @@ -package lcsb.mapviewer.model.map.reaction; - -import java.util.Comparator; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.map.ElementComparator; -import lcsb.mapviewer.model.map.layout.alias.AliasComparator; - -/** - * This class implements comparator interface for {@link ReactionNode}. It also - * handles comparison of subclasses of {@link ReactionNode} class. - * - * - * @author Piotr Gawron - * - */ -public class ReactionNodeComparator implements Comparator<ReactionNode> { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(ReactionNodeComparator.class); - - /** - * Epsilon value used for comparison of doubles. - */ - private double epsilon; - - /** - * Constructor that requires {@link #epsilon} parameter. - * - * @param epsilon - * {@link #epsilon} - */ - public ReactionNodeComparator(double epsilon) { - this.epsilon = epsilon; - } - - /** - * Default constructor. - */ - public ReactionNodeComparator() { - this(Configuration.EPSILON); - } - - @Override - public int compare(ReactionNode arg0, ReactionNode arg1) { - if (arg0 == null) { - if (arg1 == null) { - return 0; - } else { - return 1; - } - } else if (arg1 == null) { - return -1; - } - - if (arg0.getClass().equals(arg1.getClass())) { - return internalCompare(arg0, arg1); - } else { - logger.debug("Different classes."); - return -1; - } - } - - /** - * This method compare all fields of two node operators and return 0 if they - * are the same or 1/-1 if the objects are different. Also comparator for - * super class ({@link AbstractNode}) is called. - * - * @param arg0 - * first object to compare - * @param arg1 - * second object to compare - * @return 0 if objects are equal,<br> - * -1/1 otherwise - */ - private int internalCompare(ReactionNode arg0, ReactionNode arg1) { - AbstractNodeComparator anComparator = new AbstractNodeComparator(epsilon); - ElementComparator elementComparator = new ElementComparator(epsilon); - AliasComparator aliasComparator = new AliasComparator(epsilon); - - int result = anComparator.internalCompare(arg0, arg1); - if (result != 0) { - return result; - } - - if (aliasComparator.compare(arg0.getAlias(), arg1.getAlias()) != 0) { - logger.debug("Alias different"); - return aliasComparator.compare(arg0.getAlias(), arg1.getAlias()); - } - - if (elementComparator.compare(arg0.getElement(), arg1.getElement()) != 0) { - logger.debug("Element different"); - return elementComparator.compare(arg0.getElement(), arg1.getElement()); - } - - return 0; - } -} +package lcsb.mapviewer.model.map.reaction; + +import java.util.Comparator; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.model.map.ElementComparator; +import lcsb.mapviewer.model.map.layout.alias.AliasComparator; + +/** + * This class implements comparator interface for {@link ReactionNode}. It also + * handles comparison of subclasses of {@link ReactionNode} class. + * + * + * @author Piotr Gawron + * + */ +public class ReactionNodeComparator implements Comparator<ReactionNode> { + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(ReactionNodeComparator.class); + + /** + * Epsilon value used for comparison of doubles. + */ + private double epsilon; + + /** + * Constructor that requires {@link #epsilon} parameter. + * + * @param epsilon + * {@link #epsilon} + */ + public ReactionNodeComparator(double epsilon) { + this.epsilon = epsilon; + } + + /** + * Default constructor. + */ + public ReactionNodeComparator() { + this(Configuration.EPSILON); + } + + @Override + public int compare(ReactionNode arg0, ReactionNode arg1) { + if (arg0 == null) { + if (arg1 == null) { + return 0; + } else { + return 1; + } + } else if (arg1 == null) { + return -1; + } + + if (arg0.getClass().equals(arg1.getClass())) { + return internalCompare(arg0, arg1); + } else { + logger.debug("Different classes."); + return -1; + } + } + + /** + * This method compare all fields of two node operators and return 0 if they + * are the same or 1/-1 if the objects are different. Also comparator for + * super class ({@link AbstractNode}) is called. + * + * @param arg0 + * first object to compare + * @param arg1 + * second object to compare + * @return 0 if objects are equal,<br> + * -1/1 otherwise + */ + private int internalCompare(ReactionNode arg0, ReactionNode arg1) { + AbstractNodeComparator anComparator = new AbstractNodeComparator(epsilon); + ElementComparator elementComparator = new ElementComparator(epsilon); + AliasComparator aliasComparator = new AliasComparator(epsilon); + + int result = anComparator.internalCompare(arg0, arg1); + if (result != 0) { + return result; + } + + if (aliasComparator.compare(arg0.getAlias(), arg1.getAlias()) != 0) { + logger.debug("Alias different"); + return aliasComparator.compare(arg0.getAlias(), arg1.getAlias()); + } + + if (elementComparator.compare(arg0.getElement(), arg1.getElement()) != 0) { + logger.debug("Element different"); + return elementComparator.compare(arg0.getElement(), arg1.getElement()); + } + + return 0; + } +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/SplitOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/SplitOperator.java index 4ebb08b866..1599fee579 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/SplitOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/SplitOperator.java @@ -1,63 +1,63 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing "split operator" (dissociation???) of one node into two or - * more nodes in the reaction (in the product part of the reaction). - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("SPLIT_OPERATOR_NODE") -public class SplitOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(SplitOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public SplitOperator(SplitOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public SplitOperator() { - super(); - } - - @Override - public String getOperatorText() { - return ""; - } - - @Override - public SplitOperator copy() { - if (this.getClass() == SplitOperator.class) { - return new SplitOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing "split operator" (dissociation???) of one node into two or + * more nodes in the reaction (in the product part of the reaction). + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("SPLIT_OPERATOR_NODE") +public class SplitOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(SplitOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public SplitOperator(SplitOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public SplitOperator() { + super(); + } + + @Override + public String getOperatorText() { + return ""; + } + + @Override + public SplitOperator copy() { + if (this.getClass() == SplitOperator.class) { + return new SplitOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/TruncationOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/TruncationOperator.java index a9c96692b8..1408e838dc 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/TruncationOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/TruncationOperator.java @@ -1,63 +1,63 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing "truncation operator" of one node into two nodes in the - * reaction. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("TRUNCATION_OPERATOR_NODE") -public class TruncationOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(TruncationOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public TruncationOperator(TruncationOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public TruncationOperator() { - super(); - } - - @Override - public String getOperatorText() { - return ""; - } - - @Override - public TruncationOperator copy() { - if (this.getClass() == TruncationOperator.class) { - return new TruncationOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing "truncation operator" of one node into two nodes in the + * reaction. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("TRUNCATION_OPERATOR_NODE") +public class TruncationOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(TruncationOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public TruncationOperator(TruncationOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public TruncationOperator() { + super(); + } + + @Override + public String getOperatorText() { + return ""; + } + + @Override + public TruncationOperator copy() { + if (this.getClass() == TruncationOperator.class) { + return new TruncationOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/UnknownOperator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/UnknownOperator.java index 01f80e6d22..15d2b75fdf 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/UnknownOperator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/UnknownOperator.java @@ -1,63 +1,63 @@ -package lcsb.mapviewer.model.map.reaction; - -import javax.persistence.DiscriminatorValue; -import javax.persistence.Entity; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -/** - * Class representing boolean, but unknown operator between two or more nodes in - * the reaction. - * - * @author Piotr Gawron - * - */ -@Entity -@DiscriminatorValue("UNKNOWN_OPERATOR_NODE") -public class UnknownOperator extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(UnknownOperator.class); - - /** - * Constructor that copies data from the parameter given in the argument. - * - * @param operator - * parent operator from which we copy data - */ - public UnknownOperator(UnknownOperator operator) { - super(operator); - } - - /** - * Default constructor. - */ - public UnknownOperator() { - super(); - } - - @Override - public String getOperatorText() { - return "?"; - } - - @Override - public UnknownOperator copy() { - if (this.getClass() == UnknownOperator.class) { - return new UnknownOperator(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +/** + * Class representing boolean, but unknown operator between two or more nodes in + * the reaction. + * + * @author Piotr Gawron + * + */ +@Entity +@DiscriminatorValue("UNKNOWN_OPERATOR_NODE") +public class UnknownOperator extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(UnknownOperator.class); + + /** + * Constructor that copies data from the parameter given in the argument. + * + * @param operator + * parent operator from which we copy data + */ + public UnknownOperator(UnknownOperator operator) { + super(operator); + } + + /** + * Default constructor. + */ + public UnknownOperator() { + super(); + } + + @Override + public String getOperatorText() { + return "?"; + } + + @Override + public UnknownOperator copy() { + if (this.getClass() == UnknownOperator.class) { + return new UnknownOperator(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/ProteinComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/species/ProteinComparator.java index f9132ead21..0d1bdf101a 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/ProteinComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/ProteinComparator.java @@ -1,120 +1,120 @@ -package lcsb.mapviewer.model.map.species; - -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.comparator.IntegerComparator; -import lcsb.mapviewer.common.comparator.StringComparator; -import lcsb.mapviewer.common.comparator.StringSetComparator; -import lcsb.mapviewer.model.map.species.fields.ModificationResidue; - -/** - * This class implements comparator interface for Protein. - * - * @author Piotr Gawron - * - * @see Protein - */ -public class ProteinComparator implements Comparator<Protein> { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(ProteinComparator.class); - - /** - * Epsilon value used for comparison of doubles. - */ - private double epsilon; - - /** - * Constructor that requires {@link #epsilon} parameter. - * - * @param epsilon - * {@link #epsilon} - */ - public ProteinComparator(double epsilon) { - this.epsilon = epsilon; - } - - /** - * Default constructor. - */ - public ProteinComparator() { - this(Configuration.EPSILON); - } - - @Override - public int compare(Protein arg0, Protein arg1) { - if (arg0 == null) { - if (arg1 == null) { - return 0; - } else { - return 1; - } - } else if (arg1 == null) { - return -1; - } - - if (arg0.getClass().equals(arg1.getClass())) { - return internalCompare(arg0, arg1); - } else { - return -1; - } - } - - /** - * This method compares only the fields that are defined in {@link Protein} - * class in inheritence tree. It also calls the {@link SpeciesComparator} for - * the super class ( {@link Species}). - * - * @param arg0 - * first object to compare - * @param arg1 - * second object to compare - * @return if all fields are qual then returns 0. If they are different then - * -1/1 is returned. - */ - private int internalCompare(Protein arg0, Protein arg1) { - SpeciesComparator speciesComparator = new SpeciesComparator(epsilon); - int result = speciesComparator.internalCompare(arg0, arg1); - if (result != 0) { - return result; - } - - StringComparator stringComparator = new StringComparator(); - IntegerComparator integerComparator = new IntegerComparator(); - StringSetComparator stringSetComparator = new StringSetComparator(); - - if (integerComparator.compare(arg0.getHomodimer(), arg1.getHomodimer()) != 0) { - logger.debug("homodimer different: " + arg0.getHomodimer() + ", " + arg1.getHomodimer()); - return integerComparator.compare(arg0.getHomodimer(), arg1.getHomodimer()); - } - - if (stringComparator.compare(arg0.getStructuralState(), arg1.getStructuralState()) != 0) { - logger.debug("structural state different: " + arg0.getStructuralState() + ", " + arg1.getStructuralState()); - return stringComparator.compare(arg0.getStructuralState(), arg1.getStructuralState()); - } - - Set<String> set1 = new HashSet<String>(); - Set<String> set2 = new HashSet<String>(); - - for (ModificationResidue region : arg0.getModificationResidues()) { - set1.add(region.toString()); - } - - for (ModificationResidue region : arg1.getModificationResidues()) { - set2.add(region.toString()); - } - - if (stringSetComparator.compare(set1, set2) != 0) { - logger.debug("modification residues different"); - return stringSetComparator.compare(set1, set2); - } - - return 0; - } -} +package lcsb.mapviewer.model.map.species; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.comparator.IntegerComparator; +import lcsb.mapviewer.common.comparator.StringComparator; +import lcsb.mapviewer.common.comparator.StringSetComparator; +import lcsb.mapviewer.model.map.species.fields.ModificationResidue; + +/** + * This class implements comparator interface for Protein. + * + * @author Piotr Gawron + * + * @see Protein + */ +public class ProteinComparator implements Comparator<Protein> { + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(ProteinComparator.class); + + /** + * Epsilon value used for comparison of doubles. + */ + private double epsilon; + + /** + * Constructor that requires {@link #epsilon} parameter. + * + * @param epsilon + * {@link #epsilon} + */ + public ProteinComparator(double epsilon) { + this.epsilon = epsilon; + } + + /** + * Default constructor. + */ + public ProteinComparator() { + this(Configuration.EPSILON); + } + + @Override + public int compare(Protein arg0, Protein arg1) { + if (arg0 == null) { + if (arg1 == null) { + return 0; + } else { + return 1; + } + } else if (arg1 == null) { + return -1; + } + + if (arg0.getClass().equals(arg1.getClass())) { + return internalCompare(arg0, arg1); + } else { + return -1; + } + } + + /** + * This method compares only the fields that are defined in {@link Protein} + * class in inheritence tree. It also calls the {@link SpeciesComparator} for + * the super class ( {@link Species}). + * + * @param arg0 + * first object to compare + * @param arg1 + * second object to compare + * @return if all fields are qual then returns 0. If they are different then + * -1/1 is returned. + */ + private int internalCompare(Protein arg0, Protein arg1) { + SpeciesComparator speciesComparator = new SpeciesComparator(epsilon); + int result = speciesComparator.internalCompare(arg0, arg1); + if (result != 0) { + return result; + } + + StringComparator stringComparator = new StringComparator(); + IntegerComparator integerComparator = new IntegerComparator(); + StringSetComparator stringSetComparator = new StringSetComparator(); + + if (integerComparator.compare(arg0.getHomodimer(), arg1.getHomodimer()) != 0) { + logger.debug("homodimer different: " + arg0.getHomodimer() + ", " + arg1.getHomodimer()); + return integerComparator.compare(arg0.getHomodimer(), arg1.getHomodimer()); + } + + if (stringComparator.compare(arg0.getStructuralState(), arg1.getStructuralState()) != 0) { + logger.debug("structural state different: " + arg0.getStructuralState() + ", " + arg1.getStructuralState()); + return stringComparator.compare(arg0.getStructuralState(), arg1.getStructuralState()); + } + + Set<String> set1 = new HashSet<String>(); + Set<String> set2 = new HashSet<String>(); + + for (ModificationResidue region : arg0.getModificationResidues()) { + set1.add(region.toString()); + } + + for (ModificationResidue region : arg1.getModificationResidues()) { + set2.add(region.toString()); + } + + if (stringSetComparator.compare(set1, set2) != 0) { + logger.debug("modification residues different"); + return stringSetComparator.compare(set1, set2); + } + + return 0; + } +} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java index da4f2a8fb9..b07ba68a12 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/SpeciesComparator.java @@ -1,232 +1,232 @@ -package lcsb.mapviewer.model.map.species; - -import java.util.Comparator; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.comparator.BooleanComparator; -import lcsb.mapviewer.common.comparator.IntegerComparator; -import lcsb.mapviewer.common.comparator.StringComparator; -import lcsb.mapviewer.common.exception.InvalidClassException; -import lcsb.mapviewer.model.map.ElementComparator; - -/** - * This class implements comparator interface for Species. It calls comparator - * implementation for all known subclases of Species class when necessary. - * - * @author Piotr Gawron - * - * @see Species - */ -public class SpeciesComparator implements Comparator<Species> { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(SpeciesComparator.class); - - /** - * Comparator for {@link AntisenseRna}. - */ - private AntisenseRnaComparator antisenseRnaComparator; - - /** - * Comparator for {@link ComplexSpecies}. - */ - private ComplexSpeciesComparator complexSpeciesComparator; - - /** - * Comparator for {@link Degraded}. - */ - private DegradedComparator degradedComparator; - - /** - * Comparator for {@link Drug}. - */ - private DrugComparator drugComparator; - - /** - * Comparator for {@link Gene}. - */ - private GeneComparator geneComparator; - - /** - * Comparator for {@link Ion}. - */ - private IonComparator ionComparator; - - /** - * Comparator for {@link Phenotype}. - */ - private PhenotypeComparator phenotypeComparator; - - /** - * Comparator for {@link Protein}. - */ - private ProteinComparator proteinComparator; - - /** - * Comparator for {@link Rna}. - */ - private RnaComparator rnaComparator; - - /** - * Comparator for {@link SimpleMolecule}. - */ - private SimpleMoleculeComparator simpleMoleculeComparator; - - /** - * Comparator for {@link Unknown}. - */ - private UnknownComparator unknownComparator; - - /** - * Epsilon value used for comparison of doubles. - */ - private double epsilon; - - /** - * Constructor that requires {@link #epsilon} parameter. - * - * @param epsilon - * {@link #epsilon} - */ - public SpeciesComparator(double epsilon) { - this.epsilon = epsilon; - antisenseRnaComparator = new AntisenseRnaComparator(epsilon); - complexSpeciesComparator = new ComplexSpeciesComparator(epsilon); - degradedComparator = new DegradedComparator(epsilon); - drugComparator = new DrugComparator(epsilon); - geneComparator = new GeneComparator(epsilon); - ionComparator = new IonComparator(epsilon); - phenotypeComparator = new PhenotypeComparator(epsilon); - proteinComparator = new ProteinComparator(epsilon); - rnaComparator = new RnaComparator(epsilon); - simpleMoleculeComparator = new SimpleMoleculeComparator(epsilon); - unknownComparator = new UnknownComparator(epsilon); - - } - - /** - * Default constructor. - */ - public SpeciesComparator() { - this(Configuration.EPSILON); - } - - @Override - public int compare(Species arg0, Species arg1) { - if (arg0 == null) { - if (arg1 == null) { - return 0; - } else { - return 1; - } - } else if (arg1 == null) { - return -1; - } - - if (arg0.getClass().equals(arg1.getClass())) { - if (arg0 instanceof AntisenseRna) { - return antisenseRnaComparator.compare((AntisenseRna) arg0, (AntisenseRna) arg1); - } else if (arg0 instanceof ComplexSpecies) { - return complexSpeciesComparator.compare((ComplexSpecies) arg0, (ComplexSpecies) arg1); - } else if (arg0 instanceof Degraded) { - return degradedComparator.compare((Degraded) arg0, (Degraded) arg1); - } else if (arg0 instanceof Drug) { - return drugComparator.compare((Drug) arg0, (Drug) arg1); - } else if (arg0 instanceof Gene) { - return geneComparator.compare((Gene) arg0, (Gene) arg1); - } else if (arg0 instanceof Ion) { - return ionComparator.compare((Ion) arg0, (Ion) arg1); - } else if (arg0 instanceof Phenotype) { - return phenotypeComparator.compare((Phenotype) arg0, (Phenotype) arg1); - } else if (arg0 instanceof Protein) { - return proteinComparator.compare((Protein) arg0, (Protein) arg1); - } else if (arg0 instanceof Rna) { - return rnaComparator.compare((Rna) arg0, (Rna) arg1); - } else if (arg0 instanceof SimpleMolecule) { - return simpleMoleculeComparator.compare((SimpleMolecule) arg0, (SimpleMolecule) arg1); - } else if (arg0 instanceof Unknown) { - return unknownComparator.compare((Unknown) arg0, (Unknown) arg1); - } else { - throw new InvalidClassException("Don't know how to compare classes: " + arg0.getClass()); - } - } else { - logger.debug("class different: " + arg0.getClass() + ", " + arg1.getClass()); - return -1; - } - } - - /** - * This method compares only the fields that are defined in {@link Species} - * class in inheritence tree. It also calls the {@link ElementComparator} for - * the super class ({@link lcsb.mapviewer.db.model.map.Element Element}). - * - * @param arg0 - * first object to compare - * @param arg1 - * second object to compare - * @return if all fields are qual then returns 0. If they are different then - * -1/1 is returned. - */ - public int internalCompare(Species arg0, Species arg1) { - ElementComparator elementComparator = new ElementComparator(epsilon); - StringComparator stringComparator = new StringComparator(); - IntegerComparator integerComparator = new IntegerComparator(); - BooleanComparator booleanComparator = new BooleanComparator(); - - int result = elementComparator.internalCompare(arg0, arg1); - if (result != 0) { - return result; - } - - if (stringComparator.compare(arg0.getElementId(), arg1.getElementId()) != 0) { - logger.debug("Id species different: " + arg0.getElementId() + ", " + arg1.getElementId()); - return stringComparator.compare(arg0.getElementId(), arg1.getElementId()); - } - - if (integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()) != 0) { - logger.debug("Initial amount different: " + arg0.getInitialAmount() + ", " + arg1.getInitialAmount()); - return integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()); - } - - if (integerComparator.compare(arg0.getCharge(), arg1.getCharge()) != 0) { - logger.debug("Charge different: " + arg0.getCharge() + ", " + arg1.getCharge()); - return integerComparator.compare(arg0.getCharge(), arg1.getCharge()); - } - - if (integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()) != 0) { - logger.debug("Initial concentration different: " + arg0.getInitialConcentration() + ", " + arg1.getInitialConcentration()); - return integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()); - } - - if (booleanComparator.compare(arg0.hasOnlySubstanceUnits(), arg1.hasOnlySubstanceUnits()) != 0) { - logger.debug("OnlySubstanceUnits different: " + arg0.hasOnlySubstanceUnits() + ", " + arg1.hasOnlySubstanceUnits()); - return booleanComparator.compare(arg0.hasOnlySubstanceUnits(), arg1.hasOnlySubstanceUnits()); - } - - if (arg0.getPositionToCompartment() != null || arg1.getPositionToCompartment() != null) { - Integer pos0 = null; - Integer pos1 = null; - if (arg0.getPositionToCompartment() != null) { - pos0 = arg0.getPositionToCompartment().ordinal(); - } - if (arg1.getPositionToCompartment() != null) { - pos1 = arg1.getPositionToCompartment().ordinal(); - } - if (integerComparator.compare(pos0, pos1) != 0) { - logger.debug("PositionToCompartment different: \"" + arg0.getPositionToCompartment() + "\", \"" + arg1.getPositionToCompartment() + "\""); - return integerComparator.compare(pos0, pos1); - } - } - - if (booleanComparator.compare(arg0.isHypothetical(), arg1.isHypothetical()) != 0) { - logger.debug("Hypothetical different: \"" + arg0.isHypothetical() + "\", \"" + arg1.isHypothetical() + "\""); - return booleanComparator.compare(arg0.isHypothetical(), arg1.isHypothetical()); - } - - return 0; - } - -} +package lcsb.mapviewer.model.map.species; + +import java.util.Comparator; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.comparator.BooleanComparator; +import lcsb.mapviewer.common.comparator.IntegerComparator; +import lcsb.mapviewer.common.comparator.StringComparator; +import lcsb.mapviewer.common.exception.InvalidClassException; +import lcsb.mapviewer.model.map.ElementComparator; + +/** + * This class implements comparator interface for Species. It calls comparator + * implementation for all known subclases of Species class when necessary. + * + * @author Piotr Gawron + * + * @see Species + */ +public class SpeciesComparator implements Comparator<Species> { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(SpeciesComparator.class); + + /** + * Comparator for {@link AntisenseRna}. + */ + private AntisenseRnaComparator antisenseRnaComparator; + + /** + * Comparator for {@link ComplexSpecies}. + */ + private ComplexSpeciesComparator complexSpeciesComparator; + + /** + * Comparator for {@link Degraded}. + */ + private DegradedComparator degradedComparator; + + /** + * Comparator for {@link Drug}. + */ + private DrugComparator drugComparator; + + /** + * Comparator for {@link Gene}. + */ + private GeneComparator geneComparator; + + /** + * Comparator for {@link Ion}. + */ + private IonComparator ionComparator; + + /** + * Comparator for {@link Phenotype}. + */ + private PhenotypeComparator phenotypeComparator; + + /** + * Comparator for {@link Protein}. + */ + private ProteinComparator proteinComparator; + + /** + * Comparator for {@link Rna}. + */ + private RnaComparator rnaComparator; + + /** + * Comparator for {@link SimpleMolecule}. + */ + private SimpleMoleculeComparator simpleMoleculeComparator; + + /** + * Comparator for {@link Unknown}. + */ + private UnknownComparator unknownComparator; + + /** + * Epsilon value used for comparison of doubles. + */ + private double epsilon; + + /** + * Constructor that requires {@link #epsilon} parameter. + * + * @param epsilon + * {@link #epsilon} + */ + public SpeciesComparator(double epsilon) { + this.epsilon = epsilon; + antisenseRnaComparator = new AntisenseRnaComparator(epsilon); + complexSpeciesComparator = new ComplexSpeciesComparator(epsilon); + degradedComparator = new DegradedComparator(epsilon); + drugComparator = new DrugComparator(epsilon); + geneComparator = new GeneComparator(epsilon); + ionComparator = new IonComparator(epsilon); + phenotypeComparator = new PhenotypeComparator(epsilon); + proteinComparator = new ProteinComparator(epsilon); + rnaComparator = new RnaComparator(epsilon); + simpleMoleculeComparator = new SimpleMoleculeComparator(epsilon); + unknownComparator = new UnknownComparator(epsilon); + + } + + /** + * Default constructor. + */ + public SpeciesComparator() { + this(Configuration.EPSILON); + } + + @Override + public int compare(Species arg0, Species arg1) { + if (arg0 == null) { + if (arg1 == null) { + return 0; + } else { + return 1; + } + } else if (arg1 == null) { + return -1; + } + + if (arg0.getClass().equals(arg1.getClass())) { + if (arg0 instanceof AntisenseRna) { + return antisenseRnaComparator.compare((AntisenseRna) arg0, (AntisenseRna) arg1); + } else if (arg0 instanceof ComplexSpecies) { + return complexSpeciesComparator.compare((ComplexSpecies) arg0, (ComplexSpecies) arg1); + } else if (arg0 instanceof Degraded) { + return degradedComparator.compare((Degraded) arg0, (Degraded) arg1); + } else if (arg0 instanceof Drug) { + return drugComparator.compare((Drug) arg0, (Drug) arg1); + } else if (arg0 instanceof Gene) { + return geneComparator.compare((Gene) arg0, (Gene) arg1); + } else if (arg0 instanceof Ion) { + return ionComparator.compare((Ion) arg0, (Ion) arg1); + } else if (arg0 instanceof Phenotype) { + return phenotypeComparator.compare((Phenotype) arg0, (Phenotype) arg1); + } else if (arg0 instanceof Protein) { + return proteinComparator.compare((Protein) arg0, (Protein) arg1); + } else if (arg0 instanceof Rna) { + return rnaComparator.compare((Rna) arg0, (Rna) arg1); + } else if (arg0 instanceof SimpleMolecule) { + return simpleMoleculeComparator.compare((SimpleMolecule) arg0, (SimpleMolecule) arg1); + } else if (arg0 instanceof Unknown) { + return unknownComparator.compare((Unknown) arg0, (Unknown) arg1); + } else { + throw new InvalidClassException("Don't know how to compare classes: " + arg0.getClass()); + } + } else { + logger.debug("class different: " + arg0.getClass() + ", " + arg1.getClass()); + return -1; + } + } + + /** + * This method compares only the fields that are defined in {@link Species} + * class in inheritence tree. It also calls the {@link ElementComparator} for + * the super class ({@link lcsb.mapviewer.db.model.map.Element Element}). + * + * @param arg0 + * first object to compare + * @param arg1 + * second object to compare + * @return if all fields are qual then returns 0. If they are different then + * -1/1 is returned. + */ + public int internalCompare(Species arg0, Species arg1) { + ElementComparator elementComparator = new ElementComparator(epsilon); + StringComparator stringComparator = new StringComparator(); + IntegerComparator integerComparator = new IntegerComparator(); + BooleanComparator booleanComparator = new BooleanComparator(); + + int result = elementComparator.internalCompare(arg0, arg1); + if (result != 0) { + return result; + } + + if (stringComparator.compare(arg0.getElementId(), arg1.getElementId()) != 0) { + logger.debug("Id species different: " + arg0.getElementId() + ", " + arg1.getElementId()); + return stringComparator.compare(arg0.getElementId(), arg1.getElementId()); + } + + if (integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()) != 0) { + logger.debug("Initial amount different: " + arg0.getInitialAmount() + ", " + arg1.getInitialAmount()); + return integerComparator.compare(arg0.getInitialAmount(), arg1.getInitialAmount()); + } + + if (integerComparator.compare(arg0.getCharge(), arg1.getCharge()) != 0) { + logger.debug("Charge different: " + arg0.getCharge() + ", " + arg1.getCharge()); + return integerComparator.compare(arg0.getCharge(), arg1.getCharge()); + } + + if (integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()) != 0) { + logger.debug("Initial concentration different: " + arg0.getInitialConcentration() + ", " + arg1.getInitialConcentration()); + return integerComparator.compare(arg0.getInitialConcentration(), arg1.getInitialConcentration()); + } + + if (booleanComparator.compare(arg0.hasOnlySubstanceUnits(), arg1.hasOnlySubstanceUnits()) != 0) { + logger.debug("OnlySubstanceUnits different: " + arg0.hasOnlySubstanceUnits() + ", " + arg1.hasOnlySubstanceUnits()); + return booleanComparator.compare(arg0.hasOnlySubstanceUnits(), arg1.hasOnlySubstanceUnits()); + } + + if (arg0.getPositionToCompartment() != null || arg1.getPositionToCompartment() != null) { + Integer pos0 = null; + Integer pos1 = null; + if (arg0.getPositionToCompartment() != null) { + pos0 = arg0.getPositionToCompartment().ordinal(); + } + if (arg1.getPositionToCompartment() != null) { + pos1 = arg1.getPositionToCompartment().ordinal(); + } + if (integerComparator.compare(pos0, pos1) != 0) { + logger.debug("PositionToCompartment different: \"" + arg0.getPositionToCompartment() + "\", \"" + arg1.getPositionToCompartment() + "\""); + return integerComparator.compare(pos0, pos1); + } + } + + if (booleanComparator.compare(arg0.isHypothetical(), arg1.isHypothetical()) != 0) { + logger.debug("Hypothetical different: \"" + arg0.isHypothetical() + "\", \"" + arg1.isHypothetical() + "\""); + return booleanComparator.compare(arg0.isHypothetical(), arg1.isHypothetical()); + } + + return 0; + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/graph/AllGraphTests.java b/model/src/test/java/lcsb/mapviewer/model/map/graph/AllGraphTests.java index cf3393ddfb..8c4095db7b 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/graph/AllGraphTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/graph/AllGraphTests.java @@ -1,15 +1,15 @@ -package lcsb.mapviewer.model.map.graph; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ DataMiningSetComparatorTest.class, // - DataMiningSetTest.class, // - DataMiningTest.class, // - DataMiningTypeTest.class,// -}) -public class AllGraphTests { - -} +package lcsb.mapviewer.model.map.graph; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ DataMiningSetComparatorTest.class, // + DataMiningSetTest.class, // + DataMiningTest.class, // + DataMiningTypeTest.class,// +}) +public class AllGraphTests { + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetComparatorTest.java index f1118e77e1..acc71fb5fb 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetComparatorTest.java @@ -1,115 +1,115 @@ -package lcsb.mapviewer.model.map.graph; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class DataMiningSetComparatorTest { - - DataMiningSetComparator comparator = new DataMiningSetComparator(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testCompareEmpty() throws Exception { - try { - DataMiningSet obj1 = new DataMiningSet(); - DataMiningSet obj2 = new DataMiningSet(); - - assertTrue(comparator.compare(obj1, obj2) == 0); - assertTrue(comparator.compare(obj2, obj1) == 0); - assertTrue(comparator.compare(obj1, obj1) == 0); - assertTrue(comparator.compare(obj2, obj2) == 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCompareNull() throws Exception { - try { - DataMiningSet obj1 = new DataMiningSet(); - DataMiningSet obj2 = new DataMiningSet(); - - assertTrue(comparator.compare(null, null) == 0); - assertTrue(comparator.compare(obj2, null) != 0); - assertTrue(comparator.compare(null, obj1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCompareInvalid() throws Exception { - try { - DataMiningSet obj1 = new DataMiningSet(); - DataMiningSet obj2 = new DataMiningSet(); - - assertTrue(comparator.compare(obj2, new DataMiningSet() { - private static final long serialVersionUID = 1L; - }) != 0); - assertTrue(comparator.compare(null, obj1) != 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCompareInvalid2() throws Exception { - try { - - class Tmp extends DataMiningSet { - private static final long serialVersionUID = 1L; - }; - DataMiningSet obj1 = new Tmp(); - DataMiningSet obj2 = new Tmp(); - - comparator.compare(obj2, obj1); - - fail("Exception expeced"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCompareName() throws Exception { - try { - DataMiningSet obj1 = new DataMiningSet(); - DataMiningSet obj2 = new DataMiningSet(); - obj1.setName("test"); - - assertTrue(comparator.compare(obj1, obj2) != 0); - assertTrue(comparator.compare(obj2, obj1) != 0); - - obj2.setName("test"); - - assertTrue(comparator.compare(obj1, obj2) == 0); - assertTrue(comparator.compare(obj2, obj1) == 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.graph; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class DataMiningSetComparatorTest { + + DataMiningSetComparator comparator = new DataMiningSetComparator(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCompareEmpty() throws Exception { + try { + DataMiningSet obj1 = new DataMiningSet(); + DataMiningSet obj2 = new DataMiningSet(); + + assertTrue(comparator.compare(obj1, obj2) == 0); + assertTrue(comparator.compare(obj2, obj1) == 0); + assertTrue(comparator.compare(obj1, obj1) == 0); + assertTrue(comparator.compare(obj2, obj2) == 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCompareNull() throws Exception { + try { + DataMiningSet obj1 = new DataMiningSet(); + DataMiningSet obj2 = new DataMiningSet(); + + assertTrue(comparator.compare(null, null) == 0); + assertTrue(comparator.compare(obj2, null) != 0); + assertTrue(comparator.compare(null, obj1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCompareInvalid() throws Exception { + try { + DataMiningSet obj1 = new DataMiningSet(); + DataMiningSet obj2 = new DataMiningSet(); + + assertTrue(comparator.compare(obj2, new DataMiningSet() { + private static final long serialVersionUID = 1L; + }) != 0); + assertTrue(comparator.compare(null, obj1) != 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCompareInvalid2() throws Exception { + try { + + class Tmp extends DataMiningSet { + private static final long serialVersionUID = 1L; + }; + DataMiningSet obj1 = new Tmp(); + DataMiningSet obj2 = new Tmp(); + + comparator.compare(obj2, obj1); + + fail("Exception expeced"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCompareName() throws Exception { + try { + DataMiningSet obj1 = new DataMiningSet(); + DataMiningSet obj2 = new DataMiningSet(); + obj1.setName("test"); + + assertTrue(comparator.compare(obj1, obj2) != 0); + assertTrue(comparator.compare(obj2, obj1) != 0); + + obj2.setName("test"); + + assertTrue(comparator.compare(obj1, obj2) == 0); + assertTrue(comparator.compare(obj2, obj1) == 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetTest.java b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetTest.java index 26c65183d9..d2dd1b20ef 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningSetTest.java @@ -1,83 +1,83 @@ -package lcsb.mapviewer.model.map.graph; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; - -public class DataMiningSetTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new DataMiningSet()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - DataMiningSet dms = new DataMiningSet(); - DataMiningSet dms3 = new DataMiningSet(dms); - assertNull(dms3.getInputData()); - dms.setInputData(new byte[] { 3 }); - - DataMiningSet dms2 = new DataMiningSet(dms); - assertArrayEquals(dms2.getInputData(), dms.getInputData()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - DataMiningSet dms = new DataMiningSet(); - String description = "desc"; - String name = "n"; - int id = 7; - DataMiningType type = DataMiningType.STRUCTURE_ANALYSIS; - String source = "src"; - - Model model = new ModelFullIndexed(null); - - dms.setDescription(description); - dms.setId(id); - dms.setModel(model); - dms.setModel(model.getModelData()); - dms.setName(name); - dms.setSource(source); - dms.setType(type); - - assertEquals(description, dms.getDescription()); - assertEquals(id, dms.getId()); - assertEquals(model.getModelData(), dms.getModel()); - assertEquals(name, dms.getName()); - assertEquals(source, dms.getSource()); - assertEquals(type, dms.getType()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.graph; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; + +public class DataMiningSetTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new DataMiningSet()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + DataMiningSet dms = new DataMiningSet(); + DataMiningSet dms3 = new DataMiningSet(dms); + assertNull(dms3.getInputData()); + dms.setInputData(new byte[] { 3 }); + + DataMiningSet dms2 = new DataMiningSet(dms); + assertArrayEquals(dms2.getInputData(), dms.getInputData()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + DataMiningSet dms = new DataMiningSet(); + String description = "desc"; + String name = "n"; + int id = 7; + DataMiningType type = DataMiningType.STRUCTURE_ANALYSIS; + String source = "src"; + + Model model = new ModelFullIndexed(null); + + dms.setDescription(description); + dms.setId(id); + dms.setModel(model); + dms.setModel(model.getModelData()); + dms.setName(name); + dms.setSource(source); + dms.setType(type); + + assertEquals(description, dms.getDescription()); + assertEquals(id, dms.getId()); + assertEquals(model.getModelData(), dms.getModel()); + assertEquals(name, dms.getName()); + assertEquals(source, dms.getSource()); + assertEquals(type, dms.getType()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningTypeTest.java b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningTypeTest.java index 4dfdb19d0f..37c2bdba7a 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningTypeTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/graph/DataMiningTypeTest.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.model.map.graph; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class DataMiningTypeTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (DataMiningType type : DataMiningType.values()) { - assertNotNull(type); - - // for coverage tests - DataMiningType.valueOf(type.toString()); - assertNotNull(type.getCommonName()); - type.getSource(); - } - } -} +package lcsb.mapviewer.model.map.graph; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class DataMiningTypeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (DataMiningType type : DataMiningType.values()) { + assertNotNull(type); + + // for coverage tests + DataMiningType.valueOf(type.toString()); + assertNotNull(type.getCommonName()); + type.getSource(); + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/AllLayoutTests.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/AllLayoutTests.java index 06e7aae3d6..217cad91d9 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/AllLayoutTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/AllLayoutTests.java @@ -1,26 +1,26 @@ -package lcsb.mapviewer.model.map.layout; - -import lcsb.mapviewer.model.map.layout.alias.AllAliasTests; -import lcsb.mapviewer.model.map.layout.graphics.AllGraphicsTests; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ AllAliasTests.class, // - AllGraphicsTests.class, // - ColorSchemaTest.class, // - GenericColorSchemaTest.class, // - GeneVariationTest.class, // - GeneVariationColorSchemaTest.class, // - InvalidColorSchemaExceptionTest.class, // - LayoutStatusTest.class, // - LayoutTest.class, // - ReferenceGenomeGeneMappingTest.class, // - ReferenceGenomeTest.class,// - ReferenceGenomeTypeTest.class,// -}) -public class AllLayoutTests { - -} +package lcsb.mapviewer.model.map.layout; + +import lcsb.mapviewer.model.map.layout.alias.AllAliasTests; +import lcsb.mapviewer.model.map.layout.graphics.AllGraphicsTests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ AllAliasTests.class, // + AllGraphicsTests.class, // + ColorSchemaTest.class, // + GenericColorSchemaTest.class, // + GeneVariationTest.class, // + GeneVariationColorSchemaTest.class, // + InvalidColorSchemaExceptionTest.class, // + LayoutStatusTest.class, // + LayoutTest.class, // + ReferenceGenomeGeneMappingTest.class, // + ReferenceGenomeTest.class,// + ReferenceGenomeTypeTest.class,// +}) +public class AllLayoutTests { + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/ColorSchemaTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/ColorSchemaTest.java index c165770309..7262b65932 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/ColorSchemaTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/ColorSchemaTest.java @@ -1,219 +1,219 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.model.map.species.Species; - -public class ColorSchemaTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSetGetters() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - List<String> compartments = new ArrayList<>(); - List<Class<? extends Species>> types = new ArrayList<>(); - String name = "S"; - String generalIdentifier = "id"; - List<Pair<MiriamType, String>> identifierColumns = new ArrayList<>(); - int matches = 79; - Double lineWidth = 5.89; - String reactionIdentifier = "re id"; - Boolean reverseReaction = true; - - cs.setName(name); - assertEquals(name, cs.getName()); - - cs.setCompartments(compartments); - assertEquals(compartments, cs.getCompartments()); - - cs.setTypes(types); - assertEquals(types, cs.getTypes()); - - cs.setGeneralIdentifier(generalIdentifier); - assertEquals(generalIdentifier, cs.getGeneralIdentifier()); - - cs.setIdentifierColumns(identifierColumns); - assertEquals(identifierColumns, cs.getIdentifierColumns()); - - cs.setMatches(matches); - assertEquals(matches, cs.getMatches()); - - cs.setLineWidth(lineWidth); - assertEquals(lineWidth, cs.getLineWidth()); - - cs.setReactionIdentifier(reactionIdentifier); - assertEquals(reactionIdentifier, cs.getReactionIdentifier()); - - cs.setReverseReaction(reverseReaction); - assertEquals(reverseReaction, cs.getReverseReaction()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInvalidColor() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - cs.setColor("qwe"); - fail("Exception expected"); - } catch (InvalidColorSchemaException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInvalidColor2() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - cs.setColor("fffffff"); - fail("Exception expected"); - } catch (InvalidColorSchemaException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetColor() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - cs.setColor("#ffffff"); - assertEquals(Color.WHITE, cs.getColor()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetColorForValue() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - assertEquals(Color.GREEN, cs.getColorForValue(1.0)); - assertEquals(Color.RED, cs.getColorForValue(-1.0)); - assertEquals(Color.WHITE, cs.getColorForValue(0.0)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetNormalizedColor() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - cs.setColor(Color.BLUE); - assertEquals(Color.BLUE, cs.getNormalizedColor()); - - cs = new GenericColorSchema(); - cs.setValue(1.0); - assertEquals(Color.GREEN, cs.getNormalizedColor()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToString() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - assertNotNull(cs.toString()); - cs.setName("gene name"); - cs.addCompartment("A"); - cs.addType(Species.class); - cs.setValue(1.2); - cs.setColor(Color.BLACK); - cs.setGeneralIdentifier("a"); - cs.addIdentifierColumn(new Pair<MiriamType, String>(MiriamType.CAS, "X")); - assertNotNull(cs.toString()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCompartments() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - cs.addCompartments(new String[] { "a", "b" }); - assertEquals(2, cs.getCompartments().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddCompartments2() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - List<String> compartments = new ArrayList<>(); - compartments.add("a"); - compartments.add("b"); - cs.addCompartments(compartments); - assertEquals(2, cs.getCompartments().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddIdentifgierColumns() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - List<Pair<MiriamType,String>> compartments = new ArrayList<>(); - compartments.add(new Pair<MiriamType, String>(MiriamType.CAS, "x")); - cs.addIdentifierColumns(compartments); - assertEquals(1, cs.getIdentifierColumns().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddTypes() throws Exception { - try { - ColorSchema cs = new GenericColorSchema(); - List<Class<? extends Species>> compartments = new ArrayList<>(); - compartments.add(Species.class); - compartments.add(Protein.class); - cs.addTypes(compartments); - assertEquals(2, cs.getTypes().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.Species; + +public class ColorSchemaTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSetGetters() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + List<String> compartments = new ArrayList<>(); + List<Class<? extends Species>> types = new ArrayList<>(); + String name = "S"; + String generalIdentifier = "id"; + List<Pair<MiriamType, String>> identifierColumns = new ArrayList<>(); + int matches = 79; + Double lineWidth = 5.89; + String reactionIdentifier = "re id"; + Boolean reverseReaction = true; + + cs.setName(name); + assertEquals(name, cs.getName()); + + cs.setCompartments(compartments); + assertEquals(compartments, cs.getCompartments()); + + cs.setTypes(types); + assertEquals(types, cs.getTypes()); + + cs.setGeneralIdentifier(generalIdentifier); + assertEquals(generalIdentifier, cs.getGeneralIdentifier()); + + cs.setIdentifierColumns(identifierColumns); + assertEquals(identifierColumns, cs.getIdentifierColumns()); + + cs.setMatches(matches); + assertEquals(matches, cs.getMatches()); + + cs.setLineWidth(lineWidth); + assertEquals(lineWidth, cs.getLineWidth()); + + cs.setReactionIdentifier(reactionIdentifier); + assertEquals(reactionIdentifier, cs.getReactionIdentifier()); + + cs.setReverseReaction(reverseReaction); + assertEquals(reverseReaction, cs.getReverseReaction()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInvalidColor() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + cs.setColor("qwe"); + fail("Exception expected"); + } catch (InvalidColorSchemaException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInvalidColor2() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + cs.setColor("fffffff"); + fail("Exception expected"); + } catch (InvalidColorSchemaException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetColor() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + cs.setColor("#ffffff"); + assertEquals(Color.WHITE, cs.getColor()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetColorForValue() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + assertEquals(Color.GREEN, cs.getColorForValue(1.0)); + assertEquals(Color.RED, cs.getColorForValue(-1.0)); + assertEquals(Color.WHITE, cs.getColorForValue(0.0)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetNormalizedColor() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + cs.setColor(Color.BLUE); + assertEquals(Color.BLUE, cs.getNormalizedColor()); + + cs = new GenericColorSchema(); + cs.setValue(1.0); + assertEquals(Color.GREEN, cs.getNormalizedColor()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToString() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + assertNotNull(cs.toString()); + cs.setName("gene name"); + cs.addCompartment("A"); + cs.addType(Species.class); + cs.setValue(1.2); + cs.setColor(Color.BLACK); + cs.setGeneralIdentifier("a"); + cs.addIdentifierColumn(new Pair<MiriamType, String>(MiriamType.CAS, "X")); + assertNotNull(cs.toString()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCompartments() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + cs.addCompartments(new String[] { "a", "b" }); + assertEquals(2, cs.getCompartments().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddCompartments2() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + List<String> compartments = new ArrayList<>(); + compartments.add("a"); + compartments.add("b"); + cs.addCompartments(compartments); + assertEquals(2, cs.getCompartments().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddIdentifgierColumns() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + List<Pair<MiriamType,String>> compartments = new ArrayList<>(); + compartments.add(new Pair<MiriamType, String>(MiriamType.CAS, "x")); + cs.addIdentifierColumns(compartments); + assertEquals(1, cs.getIdentifierColumns().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddTypes() throws Exception { + try { + ColorSchema cs = new GenericColorSchema(); + List<Class<? extends Species>> compartments = new ArrayList<>(); + compartments.add(Species.class); + compartments.add(Protein.class); + cs.addTypes(compartments); + assertEquals(2, cs.getTypes().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationColorSchemaTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationColorSchemaTest.java index da6babd624..e7dc2f79b4 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationColorSchemaTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationColorSchemaTest.java @@ -1,124 +1,124 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class GeneVariationColorSchemaTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new GeneVariationColorSchema()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - GeneVariationColorSchema schema = new GeneVariationColorSchema(); - schema.setDescription("desc"); - GeneVariationColorSchema copy = new GeneVariationColorSchema(schema); - assertEquals("desc", copy.getDescription()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - GeneVariationColorSchema schema = new GeneVariationColorSchema(); - schema.setDescription("desc"); - GeneVariationColorSchema copy = schema.copy(); - - assertEquals("desc", copy.getDescription()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - - List<GeneVariation> geneVariations = new ArrayList<>(); - - GeneVariationColorSchema schema = new GeneVariationColorSchema(); - schema.setGeneVariations(geneVariations); - - assertEquals(geneVariations, schema.getGeneVariations()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddGeneVariations() { - try { - - List<GeneVariation> geneVariations = new ArrayList<>(); - geneVariations.add(new GeneVariation()); - - GeneVariationColorSchema schema = new GeneVariationColorSchema(); - schema.addGeneVariations(geneVariations); - - assertEquals(1, schema.getGeneVariations().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - GeneVariationColorSchema schema = new GeneVariationColorSchema() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }; - schema.copy(); - fail("Exception expected"); - - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class GeneVariationColorSchemaTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new GeneVariationColorSchema()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + GeneVariationColorSchema schema = new GeneVariationColorSchema(); + schema.setDescription("desc"); + GeneVariationColorSchema copy = new GeneVariationColorSchema(schema); + assertEquals("desc", copy.getDescription()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + GeneVariationColorSchema schema = new GeneVariationColorSchema(); + schema.setDescription("desc"); + GeneVariationColorSchema copy = schema.copy(); + + assertEquals("desc", copy.getDescription()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + + List<GeneVariation> geneVariations = new ArrayList<>(); + + GeneVariationColorSchema schema = new GeneVariationColorSchema(); + schema.setGeneVariations(geneVariations); + + assertEquals(geneVariations, schema.getGeneVariations()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddGeneVariations() { + try { + + List<GeneVariation> geneVariations = new ArrayList<>(); + geneVariations.add(new GeneVariation()); + + GeneVariationColorSchema schema = new GeneVariationColorSchema(); + schema.addGeneVariations(geneVariations); + + assertEquals(1, schema.getGeneVariations().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + GeneVariationColorSchema schema = new GeneVariationColorSchema() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }; + schema.copy(); + fail("Exception expected"); + + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationTest.java index 6474d485b9..f0c15a3242 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/GeneVariationTest.java @@ -1,101 +1,101 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.MiriamData; - -public class GeneVariationTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetters() throws Exception { - try { - String modifiedDna = "str"; - - int position = 12; - - GeneVariation gv = new GeneVariation(); - - gv.setModifiedDna(modifiedDna); - assertEquals(modifiedDna, gv.getModifiedDna()); - - gv.setPosition(position); - - assertEquals((long) position, (long) gv.getPosition()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddReference() throws Exception { - try { - GeneVariation gv = new GeneVariation(); - gv.addReference(new MiriamData()); - assertEquals(1, gv.getReferences().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() throws Exception { - try { - String modifiedDna = "str"; - - GeneVariation gv = new GeneVariation(); - - gv.setModifiedDna(modifiedDna); - gv.addReference(new MiriamData()); - - GeneVariation copy = gv.copy(); - - assertEquals(gv.getModifiedDna(), copy.getModifiedDna()); - assertEquals(1, copy.getReferences().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() throws Exception { - try { - GeneVariation gv = new GeneVariation() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }; - - gv.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.MiriamData; + +public class GeneVariationTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetters() throws Exception { + try { + String modifiedDna = "str"; + + int position = 12; + + GeneVariation gv = new GeneVariation(); + + gv.setModifiedDna(modifiedDna); + assertEquals(modifiedDna, gv.getModifiedDna()); + + gv.setPosition(position); + + assertEquals((long) position, (long) gv.getPosition()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddReference() throws Exception { + try { + GeneVariation gv = new GeneVariation(); + gv.addReference(new MiriamData()); + assertEquals(1, gv.getReferences().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() throws Exception { + try { + String modifiedDna = "str"; + + GeneVariation gv = new GeneVariation(); + + gv.setModifiedDna(modifiedDna); + gv.addReference(new MiriamData()); + + GeneVariation copy = gv.copy(); + + assertEquals(gv.getModifiedDna(), copy.getModifiedDna()); + assertEquals(1, copy.getReferences().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() throws Exception { + try { + GeneVariation gv = new GeneVariation() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }; + + gv.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/GenericColorSchemaTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/GenericColorSchemaTest.java index 02c2315dc8..e855e26768 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/GenericColorSchemaTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/GenericColorSchemaTest.java @@ -1,81 +1,81 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class GenericColorSchemaTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new GenericColorSchema()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - GenericColorSchema schema = new GenericColorSchema(); - schema.setDescription("desc"); - GenericColorSchema copy = new GenericColorSchema(schema); - assertEquals("desc", copy.getDescription()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - GenericColorSchema schema = new GenericColorSchema(); - schema.setDescription("desc"); - GenericColorSchema copy = schema.copy(); - - assertEquals("desc", copy.getDescription()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - GenericColorSchema schema = new GenericColorSchema() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }; - schema.copy(); - fail("Exception expected"); - - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class GenericColorSchemaTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new GenericColorSchema()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + GenericColorSchema schema = new GenericColorSchema(); + schema.setDescription("desc"); + GenericColorSchema copy = new GenericColorSchema(schema); + assertEquals("desc", copy.getDescription()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + GenericColorSchema schema = new GenericColorSchema(); + schema.setDescription("desc"); + GenericColorSchema copy = schema.copy(); + + assertEquals("desc", copy.getDescription()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + GenericColorSchema schema = new GenericColorSchema() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }; + schema.copy(); + fail("Exception expected"); + + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/InvalidColorSchemaExceptionTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/InvalidColorSchemaExceptionTest.java index 24130c2591..4d3126561d 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/InvalidColorSchemaExceptionTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/InvalidColorSchemaExceptionTest.java @@ -1,57 +1,57 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.*; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -public class InvalidColorSchemaExceptionTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new InvalidColorSchemaException("x")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - Exception e = new InvalidColorSchemaException(new Exception()); - assertNotNull(e); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor2() { - try { - Exception e = new InvalidColorSchemaException("message", new Exception()); - assertNotNull(e); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.*; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +public class InvalidColorSchemaExceptionTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new InvalidColorSchemaException("x")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + Exception e = new InvalidColorSchemaException(new Exception()); + assertNotNull(e); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor2() { + try { + Exception e = new InvalidColorSchemaException("message", new Exception()); + assertNotNull(e); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutStatusTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutStatusTest.java index 7517897fd9..624b3f47ae 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutStatusTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutStatusTest.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class LayoutStatusTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (LayoutStatus type : LayoutStatus.values()) { - assertNotNull(type); - - // for coverage tests - LayoutStatus.valueOf(type.toString()); - assertNotNull(type.getCommonName()); - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class LayoutStatusTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (LayoutStatus type : LayoutStatus.values()) { + assertNotNull(type); + + // for coverage tests + LayoutStatus.valueOf(type.toString()); + assertNotNull(type.getCommonName()); + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java index 75db76edcb..1c8759c39c 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java @@ -1,167 +1,167 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.model.map.model.ModelData; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; - -public class LayoutTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Layout()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - assertEquals(title, layout.getTitle()); - assertEquals(dir, layout.getDirectory()); - assertEquals(publicL, layout.isPublicLayout()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor2() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - Layout layout2 = new Layout(layout); - assertNotNull(layout2); - UploadedFileEntry fileEntry = new UploadedFileEntry(); - fileEntry.setFileContent(new byte[] {}); - - layout.setInputData(fileEntry); - Layout layout3 = new Layout(layout); - assertNotNull(layout3); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - Layout layout2 = layout.copy(); - assertNotNull(layout2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - Layout layout = new Layout() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }; - layout.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - ModelFullIndexed model = new ModelFullIndexed(null); - Set<Layout> layouts = new HashSet<>(); - boolean hierarchicalView = false; - boolean publicLayout = true; - int id = 62; - String description = "qds"; - String directory = "vcccv"; - String title = "tit"; - LayoutStatus status = LayoutStatus.FAILURE; - double progress = 1.6; - UploadedFileEntry inputData = new UploadedFileEntry(); - Layout parentLayout = new Layout(); - Layout layout = new Layout(); - layout.setHierarchicalView(hierarchicalView); - assertEquals(hierarchicalView, layout.isHierarchicalView()); - layout.setId(id); - assertEquals(id, layout.getId()); - layout.setDescription(description); - assertEquals(description, layout.getDescription()); - layout.setDirectory(directory); - assertEquals(directory, layout.getDirectory()); - layout.setTitle(title); - assertEquals(title, layout.getTitle()); - layout.setModel((ModelData) null); - assertNull(layout.getModel()); - layout.setCreator(null); - assertNull(layout.getCreator()); - layout.setStatus(status); - assertEquals(status, layout.getStatus()); - layout.setProgress(progress); - assertEquals(progress, layout.getProgress(), Configuration.EPSILON); - layout.setInputData(inputData); - assertEquals(inputData, layout.getInputData()); - layout.setParentLayout(parentLayout); - assertEquals(parentLayout, layout.getParentLayout()); - layout.setPublicLayout(publicLayout); - assertEquals(publicLayout, layout.isPublicLayout()); - - layout.setLayouts(layouts); - assertEquals(layouts, layout.getLayouts()); - layout.addLayout(parentLayout); - assertEquals(1, layouts.size()); - layout.setModel(model); - assertEquals(model.getModelData(), layout.getModel()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.map.model.ModelData; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; + +public class LayoutTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Layout()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + assertEquals(title, layout.getTitle()); + assertEquals(dir, layout.getDirectory()); + assertEquals(publicL, layout.isPublicLayout()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor2() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + Layout layout2 = new Layout(layout); + assertNotNull(layout2); + UploadedFileEntry fileEntry = new UploadedFileEntry(); + fileEntry.setFileContent(new byte[] {}); + + layout.setInputData(fileEntry); + Layout layout3 = new Layout(layout); + assertNotNull(layout3); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + Layout layout2 = layout.copy(); + assertNotNull(layout2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + Layout layout = new Layout() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }; + layout.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + ModelFullIndexed model = new ModelFullIndexed(null); + Set<Layout> layouts = new HashSet<>(); + boolean hierarchicalView = false; + boolean publicLayout = true; + int id = 62; + String description = "qds"; + String directory = "vcccv"; + String title = "tit"; + LayoutStatus status = LayoutStatus.FAILURE; + double progress = 1.6; + UploadedFileEntry inputData = new UploadedFileEntry(); + Layout parentLayout = new Layout(); + Layout layout = new Layout(); + layout.setHierarchicalView(hierarchicalView); + assertEquals(hierarchicalView, layout.isHierarchicalView()); + layout.setId(id); + assertEquals(id, layout.getId()); + layout.setDescription(description); + assertEquals(description, layout.getDescription()); + layout.setDirectory(directory); + assertEquals(directory, layout.getDirectory()); + layout.setTitle(title); + assertEquals(title, layout.getTitle()); + layout.setModel((ModelData) null); + assertNull(layout.getModel()); + layout.setCreator(null); + assertNull(layout.getCreator()); + layout.setStatus(status); + assertEquals(status, layout.getStatus()); + layout.setProgress(progress); + assertEquals(progress, layout.getProgress(), Configuration.EPSILON); + layout.setInputData(inputData); + assertEquals(inputData, layout.getInputData()); + layout.setParentLayout(parentLayout); + assertEquals(parentLayout, layout.getParentLayout()); + layout.setPublicLayout(publicLayout); + assertEquals(publicLayout, layout.isPublicLayout()); + + layout.setLayouts(layouts); + assertEquals(layouts, layout.getLayouts()); + layout.addLayout(parentLayout); + assertEquals(1, layouts.size()); + layout.setModel(model); + assertEquals(model.getModelData(), layout.getModel()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeGeneMappingTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeGeneMappingTest.java index 48aa9f1695..a3f9bd8ea7 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeGeneMappingTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeGeneMappingTest.java @@ -1,54 +1,54 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.assertEquals; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.ModelTestFunctions; -import lcsb.mapviewer.common.Configuration; - -public class ReferenceGenomeGeneMappingTest extends ModelTestFunctions { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetters() { - try { - int id = 96; - ReferenceGenome genome = new ReferenceGenome(); - String name = "test_name_97"; - String url = "http://some.url/"; - double progress = 4; - - ReferenceGenomeGeneMapping mapping = new ReferenceGenomeGeneMapping(); - mapping.setId(id); - mapping.setReferenceGenome(genome); - mapping.setName(name); - mapping.setSourceUrl(url); - mapping.setDownloadProgress(progress); - - assertEquals(genome, mapping.getReferenceGenome()); - assertEquals(name, mapping.getName()); - assertEquals(url, mapping.getSourceUrl()); - assertEquals(progress, mapping.getDownloadProgress(), Configuration.EPSILON); - assertEquals(id, mapping.getId()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.ModelTestFunctions; +import lcsb.mapviewer.common.Configuration; + +public class ReferenceGenomeGeneMappingTest extends ModelTestFunctions { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetters() { + try { + int id = 96; + ReferenceGenome genome = new ReferenceGenome(); + String name = "test_name_97"; + String url = "http://some.url/"; + double progress = 4; + + ReferenceGenomeGeneMapping mapping = new ReferenceGenomeGeneMapping(); + mapping.setId(id); + mapping.setReferenceGenome(genome); + mapping.setName(name); + mapping.setSourceUrl(url); + mapping.setDownloadProgress(progress); + + assertEquals(genome, mapping.getReferenceGenome()); + assertEquals(name, mapping.getName()); + assertEquals(url, mapping.getSourceUrl()); + assertEquals(progress, mapping.getDownloadProgress(), Configuration.EPSILON); + assertEquals(id, mapping.getId()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTest.java index d1416e065c..9195a401a8 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTest.java @@ -1,89 +1,89 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; - -public class ReferenceGenomeTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new ReferenceGenome()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAddReferenceGenomeGeneMapping() { - try { - ReferenceGenome genome = new ReferenceGenome(); - assertEquals(0, genome.getGeneMapping().size()); - genome.addReferenceGenomeGeneMapping(new ReferenceGenomeGeneMapping()); - assertEquals(1, genome.getGeneMapping().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - int id = 16; - MiriamData organism = new MiriamData(MiriamType.TAXONOMY, "9606"); - ReferenceGenomeType type = ReferenceGenomeType.UCSC; - String version = "hg19"; - double downloadProgress = 3.0; - String sourceUrl = "google.pl"; - List<ReferenceGenomeGeneMapping> geneMapping = new ArrayList<>(); - - ReferenceGenome genome = new ReferenceGenome(); - - genome.setDownloadProgress(downloadProgress); - genome.setId(id); - genome.setOrganism(organism); - genome.setSourceUrl(sourceUrl); - genome.setType(type); - genome.setVersion(version); - genome.setGeneMapping(geneMapping); - - assertEquals(downloadProgress, genome.getDownloadProgress(), Configuration.EPSILON); - assertEquals(id, genome.getId()); - assertEquals(organism, genome.getOrganism()); - assertEquals(sourceUrl, genome.getSourceUrl()); - assertEquals(type, genome.getType()); - assertEquals(version, genome.getVersion()); - assertEquals(geneMapping, genome.getGeneMapping()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; + +public class ReferenceGenomeTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new ReferenceGenome()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAddReferenceGenomeGeneMapping() { + try { + ReferenceGenome genome = new ReferenceGenome(); + assertEquals(0, genome.getGeneMapping().size()); + genome.addReferenceGenomeGeneMapping(new ReferenceGenomeGeneMapping()); + assertEquals(1, genome.getGeneMapping().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + int id = 16; + MiriamData organism = new MiriamData(MiriamType.TAXONOMY, "9606"); + ReferenceGenomeType type = ReferenceGenomeType.UCSC; + String version = "hg19"; + double downloadProgress = 3.0; + String sourceUrl = "google.pl"; + List<ReferenceGenomeGeneMapping> geneMapping = new ArrayList<>(); + + ReferenceGenome genome = new ReferenceGenome(); + + genome.setDownloadProgress(downloadProgress); + genome.setId(id); + genome.setOrganism(organism); + genome.setSourceUrl(sourceUrl); + genome.setType(type); + genome.setVersion(version); + genome.setGeneMapping(geneMapping); + + assertEquals(downloadProgress, genome.getDownloadProgress(), Configuration.EPSILON); + assertEquals(id, genome.getId()); + assertEquals(organism, genome.getOrganism()); + assertEquals(sourceUrl, genome.getSourceUrl()); + assertEquals(type, genome.getType()); + assertEquals(version, genome.getVersion()); + assertEquals(geneMapping, genome.getGeneMapping()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTypeTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTypeTest.java index 1b4c5c817b..cbd1a60cea 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTypeTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/ReferenceGenomeTypeTest.java @@ -1,35 +1,35 @@ -package lcsb.mapviewer.model.map.layout; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -public class ReferenceGenomeTypeTest { - - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (ReferenceGenomeType type : ReferenceGenomeType.values()) { - assertNotNull(type); - - // for coverage tests - ReferenceGenomeType.valueOf(type.toString()); - assertNotNull(type.getHomepage()); - } - } - -} +package lcsb.mapviewer.model.map.layout; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +public class ReferenceGenomeTypeTest { + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (ReferenceGenomeType type : ReferenceGenomeType.values()) { + assertNotNull(type); + + // for coverage tests + ReferenceGenomeType.valueOf(type.toString()); + assertNotNull(type.getHomepage()); + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/AliasSubmodelConnectionTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/AliasSubmodelConnectionTest.java index 30ffa0ed99..c07be70f0e 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/AliasSubmodelConnectionTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/AliasSubmodelConnectionTest.java @@ -1,94 +1,94 @@ -package lcsb.mapviewer.model.map.model; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class AliasSubmodelConnectionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new AliasSubmodelConnection()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - AliasSubmodelConnection connection = new AliasSubmodelConnection(new ModelData(), SubmodelType.DOWNSTREAM_TARGETS); - assertNotNull(connection); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor2() { - try { - AliasSubmodelConnection connection = new AliasSubmodelConnection(new AliasSubmodelConnection(new ModelData(), SubmodelType.DOWNSTREAM_TARGETS)); - assertNotNull(connection); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor3() { - try { - AliasSubmodelConnection connection = new AliasSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "sd"); - assertNotNull(connection); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - AliasSubmodelConnection connection = new AliasSubmodelConnection().copy(); - assertNotNull(connection); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new AliasSubmodelConnection() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.model; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class AliasSubmodelConnectionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new AliasSubmodelConnection()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + AliasSubmodelConnection connection = new AliasSubmodelConnection(new ModelData(), SubmodelType.DOWNSTREAM_TARGETS); + assertNotNull(connection); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor2() { + try { + AliasSubmodelConnection connection = new AliasSubmodelConnection(new AliasSubmodelConnection(new ModelData(), SubmodelType.DOWNSTREAM_TARGETS)); + assertNotNull(connection); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor3() { + try { + AliasSubmodelConnection connection = new AliasSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "sd"); + assertNotNull(connection); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + AliasSubmodelConnection connection = new AliasSubmodelConnection().copy(); + assertNotNull(connection); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + new AliasSubmodelConnection() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelSubmodelConnectionTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelSubmodelConnectionTest.java index 5652e39481..a81b8062dc 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/ModelSubmodelConnectionTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/ModelSubmodelConnectionTest.java @@ -1,102 +1,102 @@ -package lcsb.mapviewer.model.map.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class ModelSubmodelConnectionTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new ModelSubmodelConnection()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); - ModelSubmodelConnection connection2 = new ModelSubmodelConnection(connection); - assertNotNull(connection2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor2() { - try { - ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); - - assertNotNull(connection); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); - ModelSubmodelConnection degraded = connection.copy(); - assertNotNull(degraded); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); - - int id = 30; - connection.setId(id); - assertEquals(id, connection.getId()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new ModelSubmodelConnection() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class ModelSubmodelConnectionTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new ModelSubmodelConnection()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); + ModelSubmodelConnection connection2 = new ModelSubmodelConnection(connection); + assertNotNull(connection2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor2() { + try { + ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); + + assertNotNull(connection); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); + ModelSubmodelConnection degraded = connection.copy(); + assertNotNull(degraded); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + ModelSubmodelConnection connection = new ModelSubmodelConnection(new ModelFullIndexed(null), SubmodelType.DOWNSTREAM_TARGETS, "str"); + + int id = 30; + connection.setId(id); + assertEquals(id, connection.getId()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + new ModelSubmodelConnection() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/model/SubmodelTypeTest.java b/model/src/test/java/lcsb/mapviewer/model/map/model/SubmodelTypeTest.java index 202a2f1996..ed6ab6d99b 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/model/SubmodelTypeTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/model/SubmodelTypeTest.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.model.map.model; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SubmodelTypeTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (SubmodelType type : SubmodelType.values()) { - assertNotNull(type); - - // for coverage tests - SubmodelType.valueOf(type.toString()); - assertNotNull(type.getCommonName()); - } - } - -} +package lcsb.mapviewer.model.map.model; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SubmodelTypeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (SubmodelType type : SubmodelType.values()) { + assertNotNull(type); + + // for coverage tests + SubmodelType.valueOf(type.toString()); + assertNotNull(type.getCommonName()); + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparatorTest.java index 2074082e10..6e01b620a4 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparatorTest.java @@ -1,76 +1,76 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.InvalidClassException; - -public class AbstractNodeComparatorTest { - - public class Mock extends AbstractNode { - - /** - * - */ - private static final long serialVersionUID = 1L; - - @Override - public AbstractNode copy() { - // TODO Auto-generated method stub - return null; - } - - } - - AbstractNodeComparator comparator = new AbstractNodeComparator(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testCompareException() { - try { - comparator.compare(new Mock(), new Mock()); - - fail("Exception should occur"); - } catch (InvalidClassException e) { - - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } - - @Test - public void testCompareOk() { - try { - assertEquals(0, comparator.compare(new AndOperator(), new AndOperator())); - assertEquals(0, comparator.compare(null, null)); - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } - - @Test - public void testDifferent() { - try { - assertTrue(comparator.compare(new AndOperator(), null) != 0); - assertTrue(comparator.compare(null, new AndOperator()) != 0); - } catch (Exception e) { - e.printStackTrace(); - fail("Unkowne exception"); - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.InvalidClassException; + +public class AbstractNodeComparatorTest { + + public class Mock extends AbstractNode { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public AbstractNode copy() { + // TODO Auto-generated method stub + return null; + } + + } + + AbstractNodeComparator comparator = new AbstractNodeComparator(); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testCompareException() { + try { + comparator.compare(new Mock(), new Mock()); + + fail("Exception should occur"); + } catch (InvalidClassException e) { + + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } + + @Test + public void testCompareOk() { + try { + assertEquals(0, comparator.compare(new AndOperator(), new AndOperator())); + assertEquals(0, comparator.compare(null, null)); + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } + + @Test + public void testDifferent() { + try { + assertTrue(comparator.compare(new AndOperator(), null) != 0); + assertTrue(comparator.compare(null, new AndOperator()) != 0); + } catch (Exception e) { + e.printStackTrace(); + fail("Unkowne exception"); + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AllReactionTests.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AllReactionTests.java index 99a848941d..adb267fb6b 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AllReactionTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AllReactionTests.java @@ -1,31 +1,31 @@ -package lcsb.mapviewer.model.map.reaction; - -import lcsb.mapviewer.model.map.reaction.type.AllReactionTypeTests; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ AbstractNodeComparatorTest.class, // - AllReactionTypeTests.class,// - AndOperatorTest.class, // - AssociationOperatorTest.class, // - DissociationOperatorTest.class, // - ModifierTest.class,// - NandOperatorTest.class, // - NodeOperatorComparatorTest.class, // - NodeOperatorTest.class, // - OrOperatorTest.class, // - ProductTest.class, // - ReactantTest.class,// - ReactionComparatorTest.class, // - ReactionNodeComparatorTest.class, // - ReactionTest.class, // - SplitOperatorTest.class,// - TruncationOperatorTest.class, // - UnknownOperatorTest.class,// -}) -public class AllReactionTests { - -} +package lcsb.mapviewer.model.map.reaction; + +import lcsb.mapviewer.model.map.reaction.type.AllReactionTypeTests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ AbstractNodeComparatorTest.class, // + AllReactionTypeTests.class,// + AndOperatorTest.class, // + AssociationOperatorTest.class, // + DissociationOperatorTest.class, // + ModifierTest.class,// + NandOperatorTest.class, // + NodeOperatorComparatorTest.class, // + NodeOperatorTest.class, // + OrOperatorTest.class, // + ProductTest.class, // + ReactantTest.class,// + ReactionComparatorTest.class, // + ReactionNodeComparatorTest.class, // + ReactionTest.class, // + SplitOperatorTest.class,// + TruncationOperatorTest.class, // + UnknownOperatorTest.class,// +}) +public class AllReactionTests { + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AndOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AndOperatorTest.java index 47395602c3..586f91b930 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AndOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AndOperatorTest.java @@ -1,104 +1,104 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class AndOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new AndOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - AndOperator op = new AndOperator(); - op.setLine(new PolylineData()); - AndOperator operator = new AndOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - AndOperator operator = new AndOperator(); - assertFalse("".equals(new AndOperator().getSBGNOperatorText())); - assertFalse("".equals(operator.getOperatorText())); - - NodeOperator nodeOperatorForInput = new AndOperator(); - NodeOperator nodeOperatorForOutput = new AndOperator(); - - Reaction reaction = new Reaction(); - - operator.setReaction(reaction); - operator.setNodeOperatorForInput(nodeOperatorForInput); - operator.setNodeOperatorForOutput(nodeOperatorForOutput); - - assertEquals(reaction, operator.getReaction()); - assertEquals(nodeOperatorForInput, operator.getNodeOperatorForInput()); - assertEquals(nodeOperatorForOutput, operator.getNodeOperatorForOutput()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - AndOperator op = new AndOperator(); - op.setLine(new PolylineData()); - AndOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new AndOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class AndOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new AndOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + AndOperator op = new AndOperator(); + op.setLine(new PolylineData()); + AndOperator operator = new AndOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + AndOperator operator = new AndOperator(); + assertFalse("".equals(new AndOperator().getSBGNOperatorText())); + assertFalse("".equals(operator.getOperatorText())); + + NodeOperator nodeOperatorForInput = new AndOperator(); + NodeOperator nodeOperatorForOutput = new AndOperator(); + + Reaction reaction = new Reaction(); + + operator.setReaction(reaction); + operator.setNodeOperatorForInput(nodeOperatorForInput); + operator.setNodeOperatorForOutput(nodeOperatorForOutput); + + assertEquals(reaction, operator.getReaction()); + assertEquals(nodeOperatorForInput, operator.getNodeOperatorForInput()); + assertEquals(nodeOperatorForOutput, operator.getNodeOperatorForOutput()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + AndOperator op = new AndOperator(); + op.setLine(new PolylineData()); + AndOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new AndOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AssociationOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AssociationOperatorTest.java index 776734631d..096cdc6369 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/AssociationOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/AssociationOperatorTest.java @@ -1,89 +1,89 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class AssociationOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new AssociationOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - AssociationOperator op = new AssociationOperator(); - op.setLine(new PolylineData()); - AssociationOperator operator = new AssociationOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertFalse("".equals(new AssociationOperator().getSBGNOperatorText())); - assertFalse("".equals(new AssociationOperator().getOperatorText())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - AssociationOperator op = new AssociationOperator(); - op.setLine(new PolylineData()); - AssociationOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new AssociationOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class AssociationOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new AssociationOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + AssociationOperator op = new AssociationOperator(); + op.setLine(new PolylineData()); + AssociationOperator operator = new AssociationOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertFalse("".equals(new AssociationOperator().getSBGNOperatorText())); + assertFalse("".equals(new AssociationOperator().getOperatorText())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + AssociationOperator op = new AssociationOperator(); + op.setLine(new PolylineData()); + AssociationOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new AssociationOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/DissociationOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/DissociationOperatorTest.java index 87f1ab6c13..fde2c74cd4 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/DissociationOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/DissociationOperatorTest.java @@ -1,89 +1,89 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class DissociationOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new DissociationOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - DissociationOperator op = new DissociationOperator(); - op.setLine(new PolylineData()); - DissociationOperator operator = new DissociationOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertFalse("".equals(new DissociationOperator().getSBGNOperatorText())); - assertFalse("".equals(new DissociationOperator().getOperatorText())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - DissociationOperator op = new DissociationOperator(); - op.setLine(new PolylineData()); - DissociationOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new DissociationOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class DissociationOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new DissociationOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + DissociationOperator op = new DissociationOperator(); + op.setLine(new PolylineData()); + DissociationOperator operator = new DissociationOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertFalse("".equals(new DissociationOperator().getSBGNOperatorText())); + assertFalse("".equals(new DissociationOperator().getOperatorText())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + DissociationOperator op = new DissociationOperator(); + op.setLine(new PolylineData()); + DissociationOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new DissociationOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ModifierTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ModifierTest.java index a00c5a8b36..4730c68acd 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ModifierTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ModifierTest.java @@ -1,78 +1,78 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class ModifierTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Modifier()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - Modifier original = new Modifier(); - original.setLine(new PolylineData()); - Modifier modifier = new Modifier(original); - assertNotNull(modifier); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - Modifier original = new Modifier(); - original.setLine(new PolylineData()); - Modifier modifier = original.copy(); - assertNotNull(modifier); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new Modifier() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class ModifierTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Modifier()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + Modifier original = new Modifier(); + original.setLine(new PolylineData()); + Modifier modifier = new Modifier(original); + assertNotNull(modifier); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + Modifier original = new Modifier(); + original.setLine(new PolylineData()); + Modifier modifier = original.copy(); + assertNotNull(modifier); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + new Modifier() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NandOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NandOperatorTest.java index 306860fef6..53d56ce1a3 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NandOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NandOperatorTest.java @@ -1,89 +1,89 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class NandOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new NandOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - NandOperator op = new NandOperator(); - op.setLine(new PolylineData()); - NandOperator operator = new NandOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertFalse("".equals(new NandOperator().getSBGNOperatorText())); - assertFalse("".equals(new NandOperator().getOperatorText())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - NandOperator op = new NandOperator(); - op.setLine(new PolylineData()); - NandOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new NandOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class NandOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new NandOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + NandOperator op = new NandOperator(); + op.setLine(new PolylineData()); + NandOperator operator = new NandOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertFalse("".equals(new NandOperator().getSBGNOperatorText())); + assertFalse("".equals(new NandOperator().getOperatorText())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + NandOperator op = new NandOperator(); + op.setLine(new PolylineData()); + NandOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new NandOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorMock.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorMock.java index 73a6e2ee50..39f4a8ded9 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorMock.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorMock.java @@ -1,30 +1,30 @@ -package lcsb.mapviewer.model.map.reaction; - -import lcsb.mapviewer.common.exception.NotImplementedException; - -public class NodeOperatorMock extends NodeOperator { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public NodeOperatorMock(NodeOperator operator) { - super(operator); - } - - public NodeOperatorMock() { - super(); - } - - @Override - public String getOperatorText() { - return "mock string"; - } - - @Override - public AbstractNode copy() { - throw new NotImplementedException(); - } - -} +package lcsb.mapviewer.model.map.reaction; + +import lcsb.mapviewer.common.exception.NotImplementedException; + +public class NodeOperatorMock extends NodeOperator { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public NodeOperatorMock(NodeOperator operator) { + super(operator); + } + + public NodeOperatorMock() { + super(); + } + + @Override + public String getOperatorText() { + return "mock string"; + } + + @Override + public AbstractNode copy() { + throw new NotImplementedException(); + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorTest.java index de27fe0cce..5cb9896c1a 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/NodeOperatorTest.java @@ -1,210 +1,210 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class NodeOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testConstructor() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - NodeOperator operator3 = new NodeOperatorMock(); - operator.addInput(operator2); - operator.addOutput(operator3); - operator.setLine(new PolylineData()); - - NodeOperator result = new NodeOperatorMock(operator); - assertEquals(1, result.getInputs().size()); - assertEquals(1, result.getOutputs().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAddInput() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - operator.addInput(operator2); - assertEquals(1, operator.getInputs().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAddInputs() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - List<NodeOperator> list = new ArrayList<>(); - list.add(operator2); - operator.addInputs(list); - assertEquals(1, operator.getInputs().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAddInput2() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - operator.addInput(operator2); - operator.addInput(operator2); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testIsReactantOperator() { - try { - NodeOperator operator = new NodeOperatorMock(); - assertFalse(operator.isReactantOperator()); - - AndOperator op1 = new AndOperator(); - operator.addInput(op1); - assertFalse(operator.isReactantOperator()); - - op1.addInput(new Reactant()); - assertTrue(operator.isReactantOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAddOutputs() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - List<NodeOperator> list = new ArrayList<>(); - list.add(operator2); - operator.addOutputs(list); - assertEquals(1, operator.getOutputs().size()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAddOutput2() { - try { - NodeOperator operator = new NodeOperatorMock(); - NodeOperator operator2 = new NodeOperatorMock(); - operator.addOutput(operator2); - operator.addOutput(operator2); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testIsProductOperator() { - try { - NodeOperator operator = new NodeOperatorMock(); - assertFalse(operator.isReactantOperator()); - - AndOperator op1 = new AndOperator(); - operator.addInput(op1); - assertFalse(operator.isProductOperator()); - - op1.addInput(new Reactant()); - assertFalse(operator.isProductOperator()); - - SplitOperator op2 = new SplitOperator(); - operator.addOutput(op2); - assertFalse(operator.isProductOperator()); - - op2.addOutput(new Product()); - assertTrue(operator.isProductOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testGetters() { - try { - NodeOperator operator = new NodeOperatorMock(); - assertNotNull(operator.getSBGNOperatorText()); - List<AbstractNode> inputs = new ArrayList<>(); - List<AbstractNode> outputs = new ArrayList<>(); - operator.setInputs(inputs); - operator.setOutputs(outputs); - assertEquals(inputs, operator.getInputs()); - assertEquals(outputs, operator.getOutputs()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testIsModifierOperator() { - try { - NodeOperator operator = new NodeOperatorMock(); - assertFalse(operator.isReactantOperator()); - - AndOperator op1 = new AndOperator(); - operator.addInput(op1); - assertFalse(operator.isModifierOperator()); - - op1.addInput(new Modifier()); - assertTrue(operator.isModifierOperator()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class NodeOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testConstructor() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + NodeOperator operator3 = new NodeOperatorMock(); + operator.addInput(operator2); + operator.addOutput(operator3); + operator.setLine(new PolylineData()); + + NodeOperator result = new NodeOperatorMock(operator); + assertEquals(1, result.getInputs().size()); + assertEquals(1, result.getOutputs().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAddInput() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + operator.addInput(operator2); + assertEquals(1, operator.getInputs().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAddInputs() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + List<NodeOperator> list = new ArrayList<>(); + list.add(operator2); + operator.addInputs(list); + assertEquals(1, operator.getInputs().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAddInput2() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + operator.addInput(operator2); + operator.addInput(operator2); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testIsReactantOperator() { + try { + NodeOperator operator = new NodeOperatorMock(); + assertFalse(operator.isReactantOperator()); + + AndOperator op1 = new AndOperator(); + operator.addInput(op1); + assertFalse(operator.isReactantOperator()); + + op1.addInput(new Reactant()); + assertTrue(operator.isReactantOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAddOutputs() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + List<NodeOperator> list = new ArrayList<>(); + list.add(operator2); + operator.addOutputs(list); + assertEquals(1, operator.getOutputs().size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAddOutput2() { + try { + NodeOperator operator = new NodeOperatorMock(); + NodeOperator operator2 = new NodeOperatorMock(); + operator.addOutput(operator2); + operator.addOutput(operator2); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testIsProductOperator() { + try { + NodeOperator operator = new NodeOperatorMock(); + assertFalse(operator.isReactantOperator()); + + AndOperator op1 = new AndOperator(); + operator.addInput(op1); + assertFalse(operator.isProductOperator()); + + op1.addInput(new Reactant()); + assertFalse(operator.isProductOperator()); + + SplitOperator op2 = new SplitOperator(); + operator.addOutput(op2); + assertFalse(operator.isProductOperator()); + + op2.addOutput(new Product()); + assertTrue(operator.isProductOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testGetters() { + try { + NodeOperator operator = new NodeOperatorMock(); + assertNotNull(operator.getSBGNOperatorText()); + List<AbstractNode> inputs = new ArrayList<>(); + List<AbstractNode> outputs = new ArrayList<>(); + operator.setInputs(inputs); + operator.setOutputs(outputs); + assertEquals(inputs, operator.getInputs()); + assertEquals(outputs, operator.getOutputs()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testIsModifierOperator() { + try { + NodeOperator operator = new NodeOperatorMock(); + assertFalse(operator.isReactantOperator()); + + AndOperator op1 = new AndOperator(); + operator.addInput(op1); + assertFalse(operator.isModifierOperator()); + + op1.addInput(new Modifier()); + assertTrue(operator.isModifierOperator()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/OrOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/OrOperatorTest.java index 88588235e0..cf29b85920 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/OrOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/OrOperatorTest.java @@ -1,89 +1,89 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class OrOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new OrOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - OrOperator op = new OrOperator(); - op.setLine(new PolylineData()); - OrOperator operator = new OrOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertFalse("".equals(new OrOperator().getSBGNOperatorText())); - assertFalse("".equals(new OrOperator().getOperatorText())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - OrOperator op = new OrOperator(); - op.setLine(new PolylineData()); - OrOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new OrOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class OrOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new OrOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + OrOperator op = new OrOperator(); + op.setLine(new PolylineData()); + OrOperator operator = new OrOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertFalse("".equals(new OrOperator().getSBGNOperatorText())); + assertFalse("".equals(new OrOperator().getOperatorText())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + OrOperator op = new OrOperator(); + op.setLine(new PolylineData()); + OrOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new OrOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ProductTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ProductTest.java index 011623f13e..89aca1b92e 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ProductTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ProductTest.java @@ -1,77 +1,77 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class ProductTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Product()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - Product original = new Product(); - original.setLine(new PolylineData()); - Product product = new Product(original); - assertNotNull(product); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - Product original = new Product(); - original.setLine(new PolylineData()); - Product product = original.copy(); - assertNotNull(product); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new Product() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class ProductTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Product()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + Product original = new Product(); + original.setLine(new PolylineData()); + Product product = new Product(original); + assertNotNull(product); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + Product original = new Product(); + original.setLine(new PolylineData()); + Product product = original.copy(); + assertNotNull(product); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + new Product() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ReactantTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ReactantTest.java index b638337de1..4de27c1a58 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/ReactantTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/ReactantTest.java @@ -1,78 +1,78 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class ReactantTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Reactant()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - Reactant original = new Reactant(); - original.setLine(new PolylineData()); - Reactant reactant = new Reactant(original); - assertNotNull(reactant); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - Reactant original = new Reactant(); - original.setLine(new PolylineData()); - Reactant reactant = original.copy(); - assertNotNull(reactant); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new Reactant() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class ReactantTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Reactant()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + Reactant original = new Reactant(); + original.setLine(new PolylineData()); + Reactant reactant = new Reactant(original); + assertNotNull(reactant); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + Reactant original = new Reactant(); + original.setLine(new PolylineData()); + Reactant reactant = original.copy(); + assertNotNull(reactant); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + new Reactant() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/SplitOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/SplitOperatorTest.java index 9ccc02e588..510029a3a9 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/SplitOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/SplitOperatorTest.java @@ -1,88 +1,88 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class SplitOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new SplitOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - SplitOperator op = new SplitOperator(); - op.setLine(new PolylineData()); - SplitOperator operator = new SplitOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertNotNull(new SplitOperator().getSBGNOperatorText()); - assertNotNull(new SplitOperator().getOperatorText()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - SplitOperator op = new SplitOperator(); - op.setLine(new PolylineData()); - SplitOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new SplitOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class SplitOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new SplitOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + SplitOperator op = new SplitOperator(); + op.setLine(new PolylineData()); + SplitOperator operator = new SplitOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertNotNull(new SplitOperator().getSBGNOperatorText()); + assertNotNull(new SplitOperator().getOperatorText()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + SplitOperator op = new SplitOperator(); + op.setLine(new PolylineData()); + SplitOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new SplitOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/TruncationOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/TruncationOperatorTest.java index bb15f7eb9d..a9ea3be433 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/TruncationOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/TruncationOperatorTest.java @@ -1,88 +1,88 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class TruncationOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new TruncationOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - TruncationOperator op = new TruncationOperator(); - op.setLine(new PolylineData()); - TruncationOperator operator = new TruncationOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertNotNull(new TruncationOperator().getSBGNOperatorText()); - assertNotNull(new TruncationOperator().getOperatorText()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - TruncationOperator op = new TruncationOperator(); - op.setLine(new PolylineData()); - TruncationOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new TruncationOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class TruncationOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new TruncationOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + TruncationOperator op = new TruncationOperator(); + op.setLine(new PolylineData()); + TruncationOperator operator = new TruncationOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertNotNull(new TruncationOperator().getSBGNOperatorText()); + assertNotNull(new TruncationOperator().getOperatorText()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + TruncationOperator op = new TruncationOperator(); + op.setLine(new PolylineData()); + TruncationOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new TruncationOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/reaction/UnknownOperatorTest.java b/model/src/test/java/lcsb/mapviewer/model/map/reaction/UnknownOperatorTest.java index 5495066dd7..2731cb1fe7 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/reaction/UnknownOperatorTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/reaction/UnknownOperatorTest.java @@ -1,90 +1,90 @@ -package lcsb.mapviewer.model.map.reaction; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.PolylineData; - -public class UnknownOperatorTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new UnknownOperator()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - - @Test - public void testConstructor() { - try { - UnknownOperator op = new UnknownOperator(); - op.setLine(new PolylineData()); - UnknownOperator operator = new UnknownOperator(op); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - assertFalse("".equals(new UnknownOperator().getSBGNOperatorText())); - assertFalse("".equals(new UnknownOperator().getOperatorText())); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy1() { - try { - UnknownOperator op = new UnknownOperator(); - op.setLine(new PolylineData()); - UnknownOperator operator = op.copy(); - assertNotNull(operator); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy2() { - try { - new UnknownOperator() { - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.reaction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.PolylineData; + +public class UnknownOperatorTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new UnknownOperator()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + + @Test + public void testConstructor() { + try { + UnknownOperator op = new UnknownOperator(); + op.setLine(new PolylineData()); + UnknownOperator operator = new UnknownOperator(op); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + assertFalse("".equals(new UnknownOperator().getSBGNOperatorText())); + assertFalse("".equals(new UnknownOperator().getOperatorText())); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy1() { + try { + UnknownOperator op = new UnknownOperator(); + op.setLine(new PolylineData()); + UnknownOperator operator = op.copy(); + assertNotNull(operator); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy2() { + try { + new UnknownOperator() { + /** + * + */ + private static final long serialVersionUID = 1L; + }.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesTest.java index 9ea4812ac1..cb3b3ec810 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/SpeciesTest.java @@ -1,319 +1,319 @@ -package lcsb.mapviewer.model.map.species; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.ModelTestFunctions; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.MiriamData; - -public class SpeciesTest extends ModelTestFunctions { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Species()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - Species species = new Species(); - String elementId = "51"; - Integer initialAmount = 54; - Integer initialConcentration = 58; - Boolean onlySubstanceUnits = true; - - String trueStr = "true"; - species.setHypothetical(trueStr); - assertTrue(species.isHypothetical()); - - species.setElementId(elementId); - assertEquals(elementId, species.getElementId()); - - try { - assertNull(species.getStringType()); - fail("Exception expected"); - } catch (NotImplementedException e) { - } - - species.setInitialAmount(initialAmount); - assertEquals(initialAmount, species.getInitialAmount()); - - species.setOnlySubstanceUnits(onlySubstanceUnits); - assertEquals(onlySubstanceUnits, species.getOnlySubstanceUnits()); - - species.setInitialConcentration(initialConcentration); - assertEquals(initialConcentration, species.getInitialConcentration()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - String id = "as_id"; - Species species = new Species(id); - assertEquals(id, species.getElementId()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetId() { - try { - Species species = new Species(); - species.setElementId(""); - species.setElementId("xx"); - try { - species.setElementId("yy"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - - } - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate1() { - try { - int warningsCount = getWarnings().size(); - Species species = new Species(); - species.setName("A"); - species.setNotes("XXX"); - Species species2 = new Species(); - species2.setName("B"); - species.update(species2); - int warningsCount2 = getWarnings().size(); - assertEquals(1, warningsCount2 - warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate2() { - try { - Species species = new Species(); - species.setNotes("XXX"); - Species species2 = new Species(); - species2.addMiriamData(new MiriamData()); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate3() { - try { - Species species = new Species(); - species.setNotes("XXX"); - Species species2 = new Species(); - species2.setNotes("xx"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate4() { - try { - Species species = new Species(); - species.setNotes("XX"); - Species species2 = new Species(); - species2.setNotes("xxX"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - assertEquals(3, species.getNotes().length()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate5() { - try { - Species species = new Species(); - species.setNotes("XX"); - Species species2 = new Species(); - species2.setNotes("a as x"); - species2.setHypothetical(true); - species2.setSymbol("sym"); - species2.setHomodimer(2); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate6() { - try { - Species species = new Species(); - species.setSymbol("sym1"); - species.setFullName("a_sym1"); - Species species2 = new Species(); - species2.setSymbol("sym2"); - species2.setFullName("b_sym1"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(2, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate7() { - try { - Species species = new Species(); - Species species2 = new Species(); - species2.addSynonym("syn"); - species2.addFormerSymbol("sym"); - species.update(species2); - int warningsCount = getWarnings().size(); - assertEquals(0, warningsCount); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInitialAmount() { - try { - Species species = new Species(); - species.setInitialAmount("1"); - assertEquals((Integer) 1, species.getInitialAmount()); - try { - species.setInitialAmount("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setInitialAmount("1"); - species.setInitialAmount((String) null); - assertNull(species.getInitialAmount()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetCharge() { - try { - Species species = new Species(); - species.setCharge("1"); - assertEquals((Integer) 1, species.getCharge()); - try { - species.setCharge("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setCharge("1"); - species.setCharge((String) null); - assertNull(species.getCharge()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetOnlySubstanceUnits() { - try { - Species species = new Species(); - species.setOnlySubstanceUnits("true"); - assertTrue(species.getOnlySubstanceUnits()); - try { - species.setOnlySubstanceUnits("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setOnlySubstanceUnits("false"); - assertFalse(species.getOnlySubstanceUnits()); - species.setOnlySubstanceUnits((String) null); - assertNull(species.getOnlySubstanceUnits()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSetInitialConcentration() { - try { - Species species = new Species(); - species.setInitialConcentration("1"); - assertEquals((Integer) 1, species.getInitialConcentration()); - try { - species.setInitialConcentration("a1"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - species.setInitialConcentration("1"); - species.setInitialConcentration((String) null); - assertNull(species.getInitialConcentration()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.model.map.species; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.ModelTestFunctions; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.MiriamData; + +public class SpeciesTest extends ModelTestFunctions { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Species()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + Species species = new Species(); + String elementId = "51"; + Integer initialAmount = 54; + Integer initialConcentration = 58; + Boolean onlySubstanceUnits = true; + + String trueStr = "true"; + species.setHypothetical(trueStr); + assertTrue(species.isHypothetical()); + + species.setElementId(elementId); + assertEquals(elementId, species.getElementId()); + + try { + assertNull(species.getStringType()); + fail("Exception expected"); + } catch (NotImplementedException e) { + } + + species.setInitialAmount(initialAmount); + assertEquals(initialAmount, species.getInitialAmount()); + + species.setOnlySubstanceUnits(onlySubstanceUnits); + assertEquals(onlySubstanceUnits, species.getOnlySubstanceUnits()); + + species.setInitialConcentration(initialConcentration); + assertEquals(initialConcentration, species.getInitialConcentration()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + String id = "as_id"; + Species species = new Species(id); + assertEquals(id, species.getElementId()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetId() { + try { + Species species = new Species(); + species.setElementId(""); + species.setElementId("xx"); + try { + species.setElementId("yy"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate1() { + try { + int warningsCount = getWarnings().size(); + Species species = new Species(); + species.setName("A"); + species.setNotes("XXX"); + Species species2 = new Species(); + species2.setName("B"); + species.update(species2); + int warningsCount2 = getWarnings().size(); + assertEquals(1, warningsCount2 - warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate2() { + try { + Species species = new Species(); + species.setNotes("XXX"); + Species species2 = new Species(); + species2.addMiriamData(new MiriamData()); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate3() { + try { + Species species = new Species(); + species.setNotes("XXX"); + Species species2 = new Species(); + species2.setNotes("xx"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate4() { + try { + Species species = new Species(); + species.setNotes("XX"); + Species species2 = new Species(); + species2.setNotes("xxX"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + assertEquals(3, species.getNotes().length()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate5() { + try { + Species species = new Species(); + species.setNotes("XX"); + Species species2 = new Species(); + species2.setNotes("a as x"); + species2.setHypothetical(true); + species2.setSymbol("sym"); + species2.setHomodimer(2); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate6() { + try { + Species species = new Species(); + species.setSymbol("sym1"); + species.setFullName("a_sym1"); + Species species2 = new Species(); + species2.setSymbol("sym2"); + species2.setFullName("b_sym1"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(2, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate7() { + try { + Species species = new Species(); + Species species2 = new Species(); + species2.addSynonym("syn"); + species2.addFormerSymbol("sym"); + species.update(species2); + int warningsCount = getWarnings().size(); + assertEquals(0, warningsCount); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInitialAmount() { + try { + Species species = new Species(); + species.setInitialAmount("1"); + assertEquals((Integer) 1, species.getInitialAmount()); + try { + species.setInitialAmount("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setInitialAmount("1"); + species.setInitialAmount((String) null); + assertNull(species.getInitialAmount()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetCharge() { + try { + Species species = new Species(); + species.setCharge("1"); + assertEquals((Integer) 1, species.getCharge()); + try { + species.setCharge("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setCharge("1"); + species.setCharge((String) null); + assertNull(species.getCharge()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetOnlySubstanceUnits() { + try { + Species species = new Species(); + species.setOnlySubstanceUnits("true"); + assertTrue(species.getOnlySubstanceUnits()); + try { + species.setOnlySubstanceUnits("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setOnlySubstanceUnits("false"); + assertFalse(species.getOnlySubstanceUnits()); + species.setOnlySubstanceUnits((String) null); + assertNull(species.getOnlySubstanceUnits()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSetInitialConcentration() { + try { + Species species = new Species(); + species.setInitialConcentration("1"); + assertEquals((Integer) 1, species.getInitialConcentration()); + try { + species.setInitialConcentration("a1"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + species.setInitialConcentration("1"); + species.setInitialConcentration((String) null); + assertNull(species.getInitialConcentration()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/statistics/AllStatisticsTests.java b/model/src/test/java/lcsb/mapviewer/model/map/statistics/AllStatisticsTests.java index 278b07f38d..b059c1fd94 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/statistics/AllStatisticsTests.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/statistics/AllStatisticsTests.java @@ -1,13 +1,13 @@ -package lcsb.mapviewer.model.map.statistics; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ SearchHistoryTest.class, // - SearchTypeTest.class,// -}) -public class AllStatisticsTests { - -} +package lcsb.mapviewer.model.map.statistics; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ SearchHistoryTest.class, // + SearchTypeTest.class,// +}) +public class AllStatisticsTests { + +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchHistoryTest.java b/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchHistoryTest.java index bbbda64dde..a1eff9d1da 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchHistoryTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchHistoryTest.java @@ -1,63 +1,63 @@ -package lcsb.mapviewer.model.map.statistics; - -import static org.junit.Assert.assertEquals; - -import java.util.Calendar; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SearchHistoryTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new SearchHistory()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - SearchHistory sh = new SearchHistory(); - - int id = 60; - String query = "q"; - String map = "e"; - Calendar timestamp = Calendar.getInstance(); - SearchType type = SearchType.DRUG; - String ipAddress = "3.4"; - - sh.setId(id); - sh.setQuery(query); - sh.setMap(map); - sh.setTimestamp(timestamp); - sh.setType(type); - sh.setIpAddress(ipAddress); - - assertEquals(id, sh.getId()); - assertEquals(query, sh.getQuery()); - assertEquals(map, sh.getMap()); - assertEquals(timestamp, sh.getTimestamp()); - assertEquals(type, sh.getType()); - assertEquals(ipAddress, sh.getIpAddress()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } -} +package lcsb.mapviewer.model.map.statistics; + +import static org.junit.Assert.assertEquals; + +import java.util.Calendar; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SearchHistoryTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new SearchHistory()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + SearchHistory sh = new SearchHistory(); + + int id = 60; + String query = "q"; + String map = "e"; + Calendar timestamp = Calendar.getInstance(); + SearchType type = SearchType.DRUG; + String ipAddress = "3.4"; + + sh.setId(id); + sh.setQuery(query); + sh.setMap(map); + sh.setTimestamp(timestamp); + sh.setType(type); + sh.setIpAddress(ipAddress); + + assertEquals(id, sh.getId()); + assertEquals(query, sh.getQuery()); + assertEquals(map, sh.getMap()); + assertEquals(timestamp, sh.getTimestamp()); + assertEquals(type, sh.getType()); + assertEquals(ipAddress, sh.getIpAddress()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } +} diff --git a/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchTypeTest.java b/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchTypeTest.java index 0d0ed2796f..cacbcc2ff7 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchTypeTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/statistics/SearchTypeTest.java @@ -1,28 +1,28 @@ -package lcsb.mapviewer.model.map.statistics; - -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class SearchTypeTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testValidValues() { - for (SearchType type : SearchType.values()) { - assertNotNull(type); - - // for coverage tests - SearchType.valueOf(type.toString()); - } - } -} +package lcsb.mapviewer.model.map.statistics; + +import static org.junit.Assert.assertNotNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SearchTypeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testValidValues() { + for (SearchType type : SearchType.values()) { + assertNotNull(type); + + // for coverage tests + SearchType.valueOf(type.toString()); + } + } +} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/BigFileEntryDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/BigFileEntryDao.java index 9ebe79e58a..9622308ec7 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/BigFileEntryDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/BigFileEntryDao.java @@ -1,51 +1,51 @@ -package lcsb.mapviewer.persist.dao.cache; - -import java.util.List; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.cache.BigFileEntry; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object for cached values. - * - * @author Piotr Gawron - * - */ -public class BigFileEntryDao extends BaseDao<BigFileEntry> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(BigFileEntryDao.class); - - /** - * Default constructor. - */ - public BigFileEntryDao() { - super(BigFileEntry.class, "removed"); - } - - /** - * Return {@link BigFileEntry} identified by remote url. - * - * @param url - * url of the file - * @return {@link BigFileEntry} identified by remote url - */ - public BigFileEntry getByUrl(String url) { - List<?> list = getElementsByParameter("url", url); - if (list.size() == 0) { - return null; - } - return (BigFileEntry) list.get(0); - } - - @Override - public void delete(BigFileEntry entry) { - entry.setRemoved(true); - update(entry); - } - -} +package lcsb.mapviewer.persist.dao.cache; + +import java.util.List; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.model.cache.BigFileEntry; +import lcsb.mapviewer.persist.dao.BaseDao; + +/** + * Data access object for cached values. + * + * @author Piotr Gawron + * + */ +public class BigFileEntryDao extends BaseDao<BigFileEntry> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(BigFileEntryDao.class); + + /** + * Default constructor. + */ + public BigFileEntryDao() { + super(BigFileEntry.class, "removed"); + } + + /** + * Return {@link BigFileEntry} identified by remote url. + * + * @param url + * url of the file + * @return {@link BigFileEntry} identified by remote url + */ + public BigFileEntry getByUrl(String url) { + List<?> list = getElementsByParameter("url", url); + if (list.size() == 0) { + return null; + } + return (BigFileEntry) list.get(0); + } + + @Override + public void delete(BigFileEntry entry) { + entry.setRemoved(true); + update(entry); + } + +} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheQueryDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheQueryDao.java index a889d72032..fa7ced7f43 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheQueryDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheQueryDao.java @@ -1,58 +1,58 @@ -package lcsb.mapviewer.persist.dao.cache; - -import java.util.List; - -import lcsb.mapviewer.model.cache.CacheQuery; -import lcsb.mapviewer.model.cache.CacheType; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object for cached values. - * - * @author Piotr Gawron - * - */ -public class CacheQueryDao extends BaseDao<CacheQuery> { - - /** - * Default constructor. - */ - public CacheQueryDao() { - super(CacheQuery.class); - } - - /** - * Returns the cached value based on the type of resource and identifier in - * remote resource. - * - * @param identifier - * identifier in remote resource - * @param type - * type of the resource - * @return cached value, if value wasn't cached then null is returned - */ - public CacheQuery getByQuery(String identifier, Integer type) { - List<?> list = getSession() - .createQuery(" from " + this.getClazz().getSimpleName() + " where query = :query and type = :type").setParameter("query", identifier) - .setParameter("type", type).list(); - if (list.size() == 0) { - return null; - } - return (CacheQuery) list.get(0); - } - - /** - * Returns the cached value based on the type of resource and identifier in - * remote resource. - * - * @param identifier - * identifier in remote resource - * @param type - * type of the resource - * @return cached value, if value wasn't cached then null is returned - */ - public CacheQuery getByQuery(String identifier, CacheType type) { - return getByQuery(identifier, type.getId()); - } - -} +package lcsb.mapviewer.persist.dao.cache; + +import java.util.List; + +import lcsb.mapviewer.model.cache.CacheQuery; +import lcsb.mapviewer.model.cache.CacheType; +import lcsb.mapviewer.persist.dao.BaseDao; + +/** + * Data access object for cached values. + * + * @author Piotr Gawron + * + */ +public class CacheQueryDao extends BaseDao<CacheQuery> { + + /** + * Default constructor. + */ + public CacheQueryDao() { + super(CacheQuery.class); + } + + /** + * Returns the cached value based on the type of resource and identifier in + * remote resource. + * + * @param identifier + * identifier in remote resource + * @param type + * type of the resource + * @return cached value, if value wasn't cached then null is returned + */ + public CacheQuery getByQuery(String identifier, Integer type) { + List<?> list = getSession() + .createQuery(" from " + this.getClazz().getSimpleName() + " where query = :query and type = :type").setParameter("query", identifier) + .setParameter("type", type).list(); + if (list.size() == 0) { + return null; + } + return (CacheQuery) list.get(0); + } + + /** + * Returns the cached value based on the type of resource and identifier in + * remote resource. + * + * @param identifier + * identifier in remote resource + * @param type + * type of the resource + * @return cached value, if value wasn't cached then null is returned + */ + public CacheQuery getByQuery(String identifier, CacheType type) { + return getByQuery(identifier, type.getId()); + } + +} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDao.java index d22ec148f0..f678cad053 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/CacheTypeDao.java @@ -1,45 +1,45 @@ -package lcsb.mapviewer.persist.dao.cache; - -import java.util.List; - -import lcsb.mapviewer.model.cache.CacheType; -import lcsb.mapviewer.persist.dao.BaseDao; - -import org.apache.log4j.Logger; - -/** - * Data access object for cached values. - * - * @author Piotr Gawron - * - */ -public class CacheTypeDao extends BaseDao<CacheType> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(CacheTypeDao.class); - - /** - * Default constructor. - */ - public CacheTypeDao() { - super(CacheType.class); - } - - /** - * Returns the cach type for the class name identified by a canonical name. - * - * @param className - * canonical name of the class - * @return type of cache that should be used by this cachable interface - */ - public CacheType getByClassName(String className) { - List<?> list = getElementsByParameter("className", className); - if (list.size() == 0) { - return null; - } - return (CacheType) list.get(0); - } - -} +package lcsb.mapviewer.persist.dao.cache; + +import java.util.List; + +import lcsb.mapviewer.model.cache.CacheType; +import lcsb.mapviewer.persist.dao.BaseDao; + +import org.apache.log4j.Logger; + +/** + * Data access object for cached values. + * + * @author Piotr Gawron + * + */ +public class CacheTypeDao extends BaseDao<CacheType> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(CacheTypeDao.class); + + /** + * Default constructor. + */ + public CacheTypeDao() { + super(CacheType.class); + } + + /** + * Returns the cach type for the class name identified by a canonical name. + * + * @param className + * canonical name of the class + * @return type of cache that should be used by this cachable interface + */ + public CacheType getByClassName(String className) { + List<?> list = getElementsByParameter("className", className); + if (list.size() == 0) { + return null; + } + return (CacheType) list.get(0); + } + +} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/UploadedFileEntryDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/UploadedFileEntryDao.java index f5b36bf38b..1ec9fdcbb5 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/UploadedFileEntryDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/cache/UploadedFileEntryDao.java @@ -1,34 +1,34 @@ -package lcsb.mapviewer.persist.dao.cache; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object for cached values. - * - * @author Piotr Gawron - * - */ -public class UploadedFileEntryDao extends BaseDao<UploadedFileEntry> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(UploadedFileEntryDao.class); - - /** - * Default constructor. - */ - public UploadedFileEntryDao() { - super(UploadedFileEntry.class, "removed"); - } - - @Override - public void delete(UploadedFileEntry entry) { - entry.setRemoved(true); - update(entry); - } - -} +package lcsb.mapviewer.persist.dao.cache; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.persist.dao.BaseDao; + +/** + * Data access object for cached values. + * + * @author Piotr Gawron + * + */ +public class UploadedFileEntryDao extends BaseDao<UploadedFileEntry> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(UploadedFileEntryDao.class); + + /** + * Default constructor. + */ + public UploadedFileEntryDao() { + super(UploadedFileEntry.class, "removed"); + } + + @Override + public void delete(UploadedFileEntry entry) { + entry.setRemoved(true); + update(entry); + } + +} diff --git a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/LogDao.java b/persist/src/main/java/lcsb/mapviewer/persist/dao/log/LogDao.java index b371c71a5b..62c5d42c2c 100644 --- a/persist/src/main/java/lcsb/mapviewer/persist/dao/log/LogDao.java +++ b/persist/src/main/java/lcsb/mapviewer/persist/dao/log/LogDao.java @@ -1,40 +1,40 @@ -package lcsb.mapviewer.persist.dao.log; - -import java.util.List; - -import org.hibernate.Query; - -import lcsb.mapviewer.model.log.GenericLog; -import lcsb.mapviewer.persist.dao.BaseDao; - -/** - * Data access object class for Log objects. - * - * @author Piotr Gawron - * - */ -public class LogDao extends BaseDao<GenericLog> { - /** - * Default constructor. - */ - public LogDao() { - super(GenericLog.class); - } - - /** - * Returns last logged event. - * - * @return last log event - */ - public GenericLog getLastLog() { - String queryString = "from " + this.getClazz().getSimpleName() + " order by id desc"; - Query query = getSession().createQuery(queryString); - List<?> list = query.list(); - if (list.size() > 0) { - return (GenericLog) list.get(0); - } else { - return null; - } - } - -} +package lcsb.mapviewer.persist.dao.log; + +import java.util.List; + +import org.hibernate.Query; + +import lcsb.mapviewer.model.log.GenericLog; +import lcsb.mapviewer.persist.dao.BaseDao; + +/** + * Data access object class for Log objects. + * + * @author Piotr Gawron + * + */ +public class LogDao extends BaseDao<GenericLog> { + /** + * Default constructor. + */ + public LogDao() { + super(GenericLog.class); + } + + /** + * Returns last logged event. + * + * @return last log event + */ + public GenericLog getLastLog() { + String queryString = "from " + this.getClazz().getSimpleName() + " order by id desc"; + Query query = getSession().createQuery(queryString); + List<?> list = query.list(); + if (list.size() > 0) { + return (GenericLog) list.get(0); + } else { + return null; + } + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ANodeComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ANodeComparator.java index e5105452c6..c660f34fd6 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ANodeComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ANodeComparator.java @@ -1,233 +1,233 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.Set; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import lcsb.mapviewer.annotation.services.annotators.ChebiAnnotator; -import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.reactome.model.ReactomeDatabaseObject; -import lcsb.mapviewer.reactome.utils.ComparatorException; -import lcsb.mapviewer.reactome.utils.ElementUtil; -import lcsb.mapviewer.reactome.utils.ReactomeQueryUtil; - -/** - * This abstract class define interface for comparison between object in interal - * representation (model package) and object from the reactome database. - * - * @author Piotr Gawron - * - * @param <T> - * class type of the object in internal representation - * @param <U> - * class type of the object in reactome representation - */ - -// TODO should implements comparable<T,U> -@Transactional(value = "txManager") -public abstract class ANodeComparator<T extends Species, U extends ReactomeDatabaseObject> { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ANodeComparator.class); - - /** - * Service used for annotation of proteins (and finding annotation of - * proteins). - */ - @Autowired - private HgncAnnotator hgncAnnotator; - - /** - * Util object used for processing elements. - */ - @Autowired - private ElementUtil elementUtil; - - /** - * Service accessing chebi database. - */ - @Autowired - private ChebiAnnotator chebiBackend; - - /** - * This object allows to query reactome database for missing elements. - */ - @Autowired - private ReactomeQueryUtil rcu; - - /** - * Comparator that allows to compare everything with everything else. - */ - private ANodeComparator<Species, ReactomeDatabaseObject> globalComparator; - - /** - * Type of the object in internal representation for which the comparator is - * designed for. - */ - private Class<T> speciesClass; - - /** - * Type of the object in reactome representation for which the comparator is - * designed for. - */ - private Class<U> reactomeSpeciesClass; - - /** - * Default constructor. - * - * @param clazzA - * Type of the object in internal representation for which the - * comparator is designed for. - * @param clazzB - * Type of the object in reactome representation for which the - * comparator is designed for. - */ - public ANodeComparator(Class<T> clazzA, Class<U> clazzB) { - speciesClass = clazzA; - reactomeSpeciesClass = clazzB; - } - - /** - * Method that compares two species. - * - * @param species - * object in internal representation to compare - * @param reactomeSpecies - * object in reactome representation to compare - * @return <i>true</i> if objects can be considered as equal,<br/> - * <i>false</i> otherwise - * @throws ComparatorException - * thrown when there is a problem during comparison - */ - public boolean compareNodes(T species, U reactomeSpecies) throws ComparatorException { - logger.warn("Don't know how to compare: " + species.getClass() + " and " + reactomeSpecies.getClass() + ". Assuming false."); - return false; - } - - /** - * - * @return the speciesClass object - */ - public Class<T> getSpeciesClass() { - return speciesClass; - } - - /** - * - * @return the reactomeSpeciesClass object - */ - public Class<U> getReactomeSpeciesClass() { - return reactomeSpeciesClass; - } - - /** - * Method that compares two sets of strings. - * - * @param localSet - * set of strings and subsets of strings - * @param reactomeSet - * second set of strings - * @return <i>true</i> if two sets contain the same strings,<br/> - * <i>false</i> otherwise - */ - protected boolean compareSets(Set<MiriamData> localSet, Set<MiriamData> reactomeSet) { - if (localSet.size() != reactomeSet.size()) { - return false; - } - for (MiriamData md : reactomeSet) { - if (!localSet.contains(md)) { - return false; - } - } - return true; - } - - /** - * - * @return the rcu object - */ - public ReactomeQueryUtil getRcu() { - return rcu; - } - - /** - * - * @param rcu - * the rcu to set - */ - public void setRcu(ReactomeQueryUtil rcu) { - this.rcu = rcu; - } - - /** - * @return the globalComparator - */ - protected ANodeComparator<Species, ReactomeDatabaseObject> getGlobalComparator() { - return globalComparator; - } - - /** - * @param globalComparator - * the globalComparator to set - */ - protected void setGlobalComparator(ANodeComparator<Species, ReactomeDatabaseObject> globalComparator) { - this.globalComparator = globalComparator; - } - - /** - * @return the chebiBackend - * @see #chebiBackend - */ - public ChebiAnnotator getChebiBackend() { - return chebiBackend; - } - - /** - * @param chebiBackend - * the chebiBackend to set - * @see #chebiBackend - */ - public void setChebiBackend(ChebiAnnotator chebiBackend) { - this.chebiBackend = chebiBackend; - } - - /** - * @return the elementUtil - * @see #elementUtil - */ - protected ElementUtil getElementUtil() { - return elementUtil; - } - - /** - * @param elementUtil - * the elementUtil to set - * @see #elementUtil - */ - protected void setElementUtil(ElementUtil elementUtil) { - this.elementUtil = elementUtil; - } - - /** - * @return the hgncAnnotator - * @see #hgncAnnotator - */ - public HgncAnnotator getHgncAnnotator() { - return hgncAnnotator; - } - - /** - * @param hgncAnnotator - * the hgncAnnotator to set - * @see #hgncAnnotator - */ - public void setHgncAnnotator(HgncAnnotator hgncAnnotator) { - this.hgncAnnotator = hgncAnnotator; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.Set; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import lcsb.mapviewer.annotation.services.annotators.ChebiAnnotator; +import lcsb.mapviewer.annotation.services.annotators.HgncAnnotator; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.reactome.model.ReactomeDatabaseObject; +import lcsb.mapviewer.reactome.utils.ComparatorException; +import lcsb.mapviewer.reactome.utils.ElementUtil; +import lcsb.mapviewer.reactome.utils.ReactomeQueryUtil; + +/** + * This abstract class define interface for comparison between object in interal + * representation (model package) and object from the reactome database. + * + * @author Piotr Gawron + * + * @param <T> + * class type of the object in internal representation + * @param <U> + * class type of the object in reactome representation + */ + +// TODO should implements comparable<T,U> +@Transactional(value = "txManager") +public abstract class ANodeComparator<T extends Species, U extends ReactomeDatabaseObject> { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ANodeComparator.class); + + /** + * Service used for annotation of proteins (and finding annotation of + * proteins). + */ + @Autowired + private HgncAnnotator hgncAnnotator; + + /** + * Util object used for processing elements. + */ + @Autowired + private ElementUtil elementUtil; + + /** + * Service accessing chebi database. + */ + @Autowired + private ChebiAnnotator chebiBackend; + + /** + * This object allows to query reactome database for missing elements. + */ + @Autowired + private ReactomeQueryUtil rcu; + + /** + * Comparator that allows to compare everything with everything else. + */ + private ANodeComparator<Species, ReactomeDatabaseObject> globalComparator; + + /** + * Type of the object in internal representation for which the comparator is + * designed for. + */ + private Class<T> speciesClass; + + /** + * Type of the object in reactome representation for which the comparator is + * designed for. + */ + private Class<U> reactomeSpeciesClass; + + /** + * Default constructor. + * + * @param clazzA + * Type of the object in internal representation for which the + * comparator is designed for. + * @param clazzB + * Type of the object in reactome representation for which the + * comparator is designed for. + */ + public ANodeComparator(Class<T> clazzA, Class<U> clazzB) { + speciesClass = clazzA; + reactomeSpeciesClass = clazzB; + } + + /** + * Method that compares two species. + * + * @param species + * object in internal representation to compare + * @param reactomeSpecies + * object in reactome representation to compare + * @return <i>true</i> if objects can be considered as equal,<br/> + * <i>false</i> otherwise + * @throws ComparatorException + * thrown when there is a problem during comparison + */ + public boolean compareNodes(T species, U reactomeSpecies) throws ComparatorException { + logger.warn("Don't know how to compare: " + species.getClass() + " and " + reactomeSpecies.getClass() + ". Assuming false."); + return false; + } + + /** + * + * @return the speciesClass object + */ + public Class<T> getSpeciesClass() { + return speciesClass; + } + + /** + * + * @return the reactomeSpeciesClass object + */ + public Class<U> getReactomeSpeciesClass() { + return reactomeSpeciesClass; + } + + /** + * Method that compares two sets of strings. + * + * @param localSet + * set of strings and subsets of strings + * @param reactomeSet + * second set of strings + * @return <i>true</i> if two sets contain the same strings,<br/> + * <i>false</i> otherwise + */ + protected boolean compareSets(Set<MiriamData> localSet, Set<MiriamData> reactomeSet) { + if (localSet.size() != reactomeSet.size()) { + return false; + } + for (MiriamData md : reactomeSet) { + if (!localSet.contains(md)) { + return false; + } + } + return true; + } + + /** + * + * @return the rcu object + */ + public ReactomeQueryUtil getRcu() { + return rcu; + } + + /** + * + * @param rcu + * the rcu to set + */ + public void setRcu(ReactomeQueryUtil rcu) { + this.rcu = rcu; + } + + /** + * @return the globalComparator + */ + protected ANodeComparator<Species, ReactomeDatabaseObject> getGlobalComparator() { + return globalComparator; + } + + /** + * @param globalComparator + * the globalComparator to set + */ + protected void setGlobalComparator(ANodeComparator<Species, ReactomeDatabaseObject> globalComparator) { + this.globalComparator = globalComparator; + } + + /** + * @return the chebiBackend + * @see #chebiBackend + */ + public ChebiAnnotator getChebiBackend() { + return chebiBackend; + } + + /** + * @param chebiBackend + * the chebiBackend to set + * @see #chebiBackend + */ + public void setChebiBackend(ChebiAnnotator chebiBackend) { + this.chebiBackend = chebiBackend; + } + + /** + * @return the elementUtil + * @see #elementUtil + */ + protected ElementUtil getElementUtil() { + return elementUtil; + } + + /** + * @param elementUtil + * the elementUtil to set + * @see #elementUtil + */ + protected void setElementUtil(ElementUtil elementUtil) { + this.elementUtil = elementUtil; + } + + /** + * @return the hgncAnnotator + * @see #hgncAnnotator + */ + public HgncAnnotator getHgncAnnotator() { + return hgncAnnotator; + } + + /** + * @param hgncAnnotator + * the hgncAnnotator to set + * @see #hgncAnnotator + */ + public void setHgncAnnotator(HgncAnnotator hgncAnnotator) { + this.hgncAnnotator = hgncAnnotator; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndCandidateSetComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndCandidateSetComparator.java index 9ad9342b75..194d11aeae 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndCandidateSetComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndCandidateSetComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.ComplexSpecies; -import lcsb.mapviewer.reactome.model.ReactomeCandidateSet; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Complex} element (internal - * representation) and {@link ReactomeCandidateSet} (reactome model). - * - * @author Piotr Gawron - * - */ -public class ComplexAndCandidateSetComparator extends ANodeComparator<ComplexSpecies, ReactomeCandidateSet> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ComplexAndCandidateSetComparator.class); - - /** - * Default constructor. - */ - public ComplexAndCandidateSetComparator() { - super(ComplexSpecies.class, ReactomeCandidateSet.class); - } - - @Override - public boolean compareNodes(ComplexSpecies species, ReactomeCandidateSet rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.ComplexSpecies; +import lcsb.mapviewer.reactome.model.ReactomeCandidateSet; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Complex} element (internal + * representation) and {@link ReactomeCandidateSet} (reactome model). + * + * @author Piotr Gawron + * + */ +public class ComplexAndCandidateSetComparator extends ANodeComparator<ComplexSpecies, ReactomeCandidateSet> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ComplexAndCandidateSetComparator.class); + + /** + * Default constructor. + */ + public ComplexAndCandidateSetComparator() { + super(ComplexSpecies.class, ReactomeCandidateSet.class); + } + + @Override + public boolean compareNodes(ComplexSpecies species, ReactomeCandidateSet rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndDefinedSetComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndDefinedSetComparator.java index 12b80f75a5..56959beb33 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndDefinedSetComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndDefinedSetComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.ComplexSpecies; -import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Complex} element (internal - * representation) and {@link ReactomeDefinedSet} (reactome model). - * - * @author Piotr Gawron - * - */ -public class ComplexAndDefinedSetComparator extends ANodeComparator<ComplexSpecies, ReactomeDefinedSet> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ComplexAndDefinedSetComparator.class); - - /** - * Default constructor. - */ - public ComplexAndDefinedSetComparator() { - super(ComplexSpecies.class, ReactomeDefinedSet.class); - } - - @Override - public boolean compareNodes(ComplexSpecies species, ReactomeDefinedSet rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.ComplexSpecies; +import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Complex} element (internal + * representation) and {@link ReactomeDefinedSet} (reactome model). + * + * @author Piotr Gawron + * + */ +public class ComplexAndDefinedSetComparator extends ANodeComparator<ComplexSpecies, ReactomeDefinedSet> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ComplexAndDefinedSetComparator.class); + + /** + * Default constructor. + */ + public ComplexAndDefinedSetComparator() { + super(ComplexSpecies.class, ReactomeDefinedSet.class); + } + + @Override + public boolean compareNodes(ComplexSpecies species, ReactomeDefinedSet rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndOtherEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndOtherEntityComparator.java index 1831df2d8c..27632cd127 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndOtherEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndOtherEntityComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.ComplexSpecies; -import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Complex} element (internal - * representation) and {@link ReactomeOtherEntity} (reactome model). - * - * @author Piotr Gawron - * - */ -public class ComplexAndOtherEntityComparator extends ANodeComparator<ComplexSpecies, ReactomeOtherEntity> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ComplexAndOtherEntityComparator.class); - - /** - * Default constructor. - */ - public ComplexAndOtherEntityComparator() { - super(ComplexSpecies.class, ReactomeOtherEntity.class); - } - - @Override - public boolean compareNodes(ComplexSpecies species, ReactomeOtherEntity rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.ComplexSpecies; +import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Complex} element (internal + * representation) and {@link ReactomeOtherEntity} (reactome model). + * + * @author Piotr Gawron + * + */ +public class ComplexAndOtherEntityComparator extends ANodeComparator<ComplexSpecies, ReactomeOtherEntity> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ComplexAndOtherEntityComparator.class); + + /** + * Default constructor. + */ + public ComplexAndOtherEntityComparator() { + super(ComplexSpecies.class, ReactomeOtherEntity.class); + } + + @Override + public boolean compareNodes(ComplexSpecies species, ReactomeOtherEntity rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndDefinedSetComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndDefinedSetComparator.java index 9036c4ad4a..d670bd8555 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndDefinedSetComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndDefinedSetComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Gene} element (internal - * representation) and {@link ReactomeDefinedSet} (reactome model). - * - * @author Piotr Gawron - * - */ -public class GeneAndDefinedSetComparator extends ANodeComparator<Gene, ReactomeDefinedSet> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(GeneAndDefinedSetComparator.class); - - /** - * Default constructor. - */ - public GeneAndDefinedSetComparator() { - super(Gene.class, ReactomeDefinedSet.class); - } - - @Override - public boolean compareNodes(Gene species, ReactomeDefinedSet rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.Gene; +import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Gene} element (internal + * representation) and {@link ReactomeDefinedSet} (reactome model). + * + * @author Piotr Gawron + * + */ +public class GeneAndDefinedSetComparator extends ANodeComparator<Gene, ReactomeDefinedSet> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(GeneAndDefinedSetComparator.class); + + /** + * Default constructor. + */ + public GeneAndDefinedSetComparator() { + super(Gene.class, ReactomeDefinedSet.class); + } + + @Override + public boolean compareNodes(Gene species, ReactomeDefinedSet rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndOtherEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndOtherEntityComparator.java index 3994356424..166956a6ec 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndOtherEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/GeneAndOtherEntityComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.Gene; -import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Gene} element (internal - * representation) and {@link ReactomeOtherEntity} (reactome model). - * - * @author Piotr Gawron - * - */ -public class GeneAndOtherEntityComparator extends ANodeComparator<Gene, ReactomeOtherEntity> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(GeneAndOtherEntityComparator.class); - - /** - * Default constructor. - */ - public GeneAndOtherEntityComparator() { - super(Gene.class, ReactomeOtherEntity.class); - } - - @Override - public boolean compareNodes(Gene species, ReactomeOtherEntity rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.Gene; +import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Gene} element (internal + * representation) and {@link ReactomeOtherEntity} (reactome model). + * + * @author Piotr Gawron + * + */ +public class GeneAndOtherEntityComparator extends ANodeComparator<Gene, ReactomeOtherEntity> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(GeneAndOtherEntityComparator.class); + + /** + * Default constructor. + */ + public GeneAndOtherEntityComparator() { + super(Gene.class, ReactomeOtherEntity.class); + } + + @Override + public boolean compareNodes(Gene species, ReactomeOtherEntity rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java index a6712bd6f8..3034a45482 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java @@ -1,90 +1,90 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.List; - -import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.species.Ion; -import lcsb.mapviewer.reactome.model.ReactomeComplex; -import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; -import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; -import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; -import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; -import lcsb.mapviewer.reactome.model.ReactomeReferenceMolecule; -import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -/** - * This class allows to compare {@link Ion} element (internal representation) - * and {@link ReactomeComplex} (reactome model). - * - * @author Piotr Gawron - * - */ -public class IonAndComplexComparator extends ANodeComparator<Ion, ReactomeComplex> { - - /** - * Default constructor. - */ - public IonAndComplexComparator() { - super(Ion.class, ReactomeComplex.class); - } - - @Override - public boolean compareNodes(Ion species, ReactomeComplex entity) throws ComparatorException { - try { - List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); - String chebi2 = null; - if (chebi1.size() == 0) { // if we don't have id then return false (even - // with - // two null values we cannot claim that they are - // equal) - return false; - } - int matched = 0; - for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { - if (entity2 instanceof ReactomeSimpleEntity) { - for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { - if (reference instanceof ReactomeReferenceMolecule) { - boolean isChebi = false; - if (reference.getReferenceDatabase() != null) { - for (String name : reference.getReferenceDatabase().getNames()) { - if (name.equalsIgnoreCase("ChEBI")) { - isChebi = true; - } - } - } - if (isChebi) { - chebi2 = "CHEBI:" + reference.getIdentifier(); - if (chebi1.contains(chebi2)) { - matched++; - } // in other case we cannot claim that there are different - // (maybe - // there are more molecule references and other is going to - // point to correct chebi id) - } - } - } - } else if (entity2 instanceof ReactomeDefinedSet) { - if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeComplex) { - if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { - return false; - } else { - throw new InvalidArgumentException( - "Cannot determine the way of comparison for provided class types: " + species.getClass() + ", " + entity2.getClass()); - } - } - return matched == entity.getHasComponents().size(); - } catch (ChebiSearchException e) { - throw new ComparatorException(e); - } - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.List; + +import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.species.Ion; +import lcsb.mapviewer.reactome.model.ReactomeComplex; +import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; +import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; +import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; +import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; +import lcsb.mapviewer.reactome.model.ReactomeReferenceMolecule; +import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +/** + * This class allows to compare {@link Ion} element (internal representation) + * and {@link ReactomeComplex} (reactome model). + * + * @author Piotr Gawron + * + */ +public class IonAndComplexComparator extends ANodeComparator<Ion, ReactomeComplex> { + + /** + * Default constructor. + */ + public IonAndComplexComparator() { + super(Ion.class, ReactomeComplex.class); + } + + @Override + public boolean compareNodes(Ion species, ReactomeComplex entity) throws ComparatorException { + try { + List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); + String chebi2 = null; + if (chebi1.size() == 0) { // if we don't have id then return false (even + // with + // two null values we cannot claim that they are + // equal) + return false; + } + int matched = 0; + for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { + if (entity2 instanceof ReactomeSimpleEntity) { + for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { + if (reference instanceof ReactomeReferenceMolecule) { + boolean isChebi = false; + if (reference.getReferenceDatabase() != null) { + for (String name : reference.getReferenceDatabase().getNames()) { + if (name.equalsIgnoreCase("ChEBI")) { + isChebi = true; + } + } + } + if (isChebi) { + chebi2 = "CHEBI:" + reference.getIdentifier(); + if (chebi1.contains(chebi2)) { + matched++; + } // in other case we cannot claim that there are different + // (maybe + // there are more molecule references and other is going to + // point to correct chebi id) + } + } + } + } else if (entity2 instanceof ReactomeDefinedSet) { + if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeComplex) { + if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { + return false; + } else { + throw new InvalidArgumentException( + "Cannot determine the way of comparison for provided class types: " + species.getClass() + ", " + entity2.getClass()); + } + } + return matched == entity.getHasComponents().size(); + } catch (ChebiSearchException e) { + throw new ComparatorException(e); + } + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndSimpleEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndSimpleEntityComparator.java index 4e7490f387..6914aa5fb8 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndSimpleEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndSimpleEntityComparator.java @@ -1,51 +1,51 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.List; -import java.util.Set; - -import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.species.Ion; -import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -/** - * This class allows to compare {@link Ion} element (internal representation) - * and {@link ReactomeSimpleEntity} (reactome model). - * - * @author Piotr Gawron - * - */ -public class IonAndSimpleEntityComparator extends ANodeComparator<Ion, ReactomeSimpleEntity> { - - /** - * Default constructor. - */ - public IonAndSimpleEntityComparator() { - super(Ion.class, ReactomeSimpleEntity.class); - } - - @Override - public boolean compareNodes(Ion species, ReactomeSimpleEntity simpleEntity) throws ComparatorException { - try { - List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); - if (chebi1.size() == 0) { // if we don't have id then return false (even - // withtwo null values we cannot claim that they - // are equal) - return false; - } - Set<MiriamData> chebiIds2 = getRcu().getIdentifiersForReactomeEntity(simpleEntity); - // no match was found, so lets assume that they are different - for (MiriamData string : chebi1) { - if (chebiIds2.contains(string)) { - return true; - } - } - return false; - } catch (ChebiSearchException e) { - throw new ComparatorException(e); - } - - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.List; +import java.util.Set; + +import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.species.Ion; +import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +/** + * This class allows to compare {@link Ion} element (internal representation) + * and {@link ReactomeSimpleEntity} (reactome model). + * + * @author Piotr Gawron + * + */ +public class IonAndSimpleEntityComparator extends ANodeComparator<Ion, ReactomeSimpleEntity> { + + /** + * Default constructor. + */ + public IonAndSimpleEntityComparator() { + super(Ion.class, ReactomeSimpleEntity.class); + } + + @Override + public boolean compareNodes(Ion species, ReactomeSimpleEntity simpleEntity) throws ComparatorException { + try { + List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); + if (chebi1.size() == 0) { // if we don't have id then return false (even + // withtwo null values we cannot claim that they + // are equal) + return false; + } + Set<MiriamData> chebiIds2 = getRcu().getIdentifiersForReactomeEntity(simpleEntity); + // no match was found, so lets assume that they are different + for (MiriamData string : chebi1) { + if (chebiIds2.contains(string)) { + return true; + } + } + return false; + } catch (ChebiSearchException e) { + throw new ComparatorException(e); + } + + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndComplexComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndComplexComparator.java index 1070936d2e..0f4c3b37b8 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndComplexComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndComplexComparator.java @@ -1,88 +1,88 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.species.SimpleMolecule; -import lcsb.mapviewer.reactome.model.ReactomeComplex; -import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; -import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; -import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; -import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; -import lcsb.mapviewer.reactome.model.ReactomeReferenceMolecule; -import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -/** - * This class allows to compare {@link SimpleMolecule} element (internal - * representation) and {@link ReactomeComplex} (reactome model). - * - * @author Piotr Gawron - * - */ -public class MoleculeAndComplexComparator extends ANodeComparator<SimpleMolecule, ReactomeComplex> { - - /** - * Default constructor. - */ - public MoleculeAndComplexComparator() { - super(SimpleMolecule.class, ReactomeComplex.class); - } - - @Override - public boolean compareNodes(SimpleMolecule species, ReactomeComplex entity) throws ComparatorException { - try { - MiriamData chebi1 = getChebiBackend().getChebiForChebiName(species.getName()); - String chebi2 = null; - if (chebi1 == null) { // if we don't have id then return false (even with - // two null values we cannot claim that they are - // equal) - return false; - } - int matched = 0; - for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { - if (entity2 instanceof ReactomeSimpleEntity) { - for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { - if (reference instanceof ReactomeReferenceMolecule) { - boolean isChebi = false; - if (reference.getReferenceDatabase() != null) { - for (String name : reference.getReferenceDatabase().getNames()) { - if (name.equalsIgnoreCase("ChEBI")) { - isChebi = true; - } - } - } - if (isChebi) { - chebi2 = "CHEBI:" + reference.getIdentifier(); - if (chebi1.getResource().contains(chebi2)) { - matched++; - } // in other case we cannot claim that there are different - // (maybe - // there are more molecule references and other is going to - // point to correct chebi id) - } - } - } - } else if (entity2 instanceof ReactomeDefinedSet) { - if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeComplex) { - if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { - return false; - } else { - throw new InvalidArgumentException( - "Cannot determine the way of comparison for provided class types: " + species.getClass() + ", " + entity2.getClass()); - } - } - return matched == entity.getHasComponents().size(); - } catch (ChebiSearchException e) { - throw new ComparatorException(e); - } - - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.species.SimpleMolecule; +import lcsb.mapviewer.reactome.model.ReactomeComplex; +import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; +import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; +import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; +import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; +import lcsb.mapviewer.reactome.model.ReactomeReferenceMolecule; +import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +/** + * This class allows to compare {@link SimpleMolecule} element (internal + * representation) and {@link ReactomeComplex} (reactome model). + * + * @author Piotr Gawron + * + */ +public class MoleculeAndComplexComparator extends ANodeComparator<SimpleMolecule, ReactomeComplex> { + + /** + * Default constructor. + */ + public MoleculeAndComplexComparator() { + super(SimpleMolecule.class, ReactomeComplex.class); + } + + @Override + public boolean compareNodes(SimpleMolecule species, ReactomeComplex entity) throws ComparatorException { + try { + MiriamData chebi1 = getChebiBackend().getChebiForChebiName(species.getName()); + String chebi2 = null; + if (chebi1 == null) { // if we don't have id then return false (even with + // two null values we cannot claim that they are + // equal) + return false; + } + int matched = 0; + for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { + if (entity2 instanceof ReactomeSimpleEntity) { + for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { + if (reference instanceof ReactomeReferenceMolecule) { + boolean isChebi = false; + if (reference.getReferenceDatabase() != null) { + for (String name : reference.getReferenceDatabase().getNames()) { + if (name.equalsIgnoreCase("ChEBI")) { + isChebi = true; + } + } + } + if (isChebi) { + chebi2 = "CHEBI:" + reference.getIdentifier(); + if (chebi1.getResource().contains(chebi2)) { + matched++; + } // in other case we cannot claim that there are different + // (maybe + // there are more molecule references and other is going to + // point to correct chebi id) + } + } + } + } else if (entity2 instanceof ReactomeDefinedSet) { + if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeComplex) { + if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { + return false; + } else { + throw new InvalidArgumentException( + "Cannot determine the way of comparison for provided class types: " + species.getClass() + ", " + entity2.getClass()); + } + } + return matched == entity.getHasComponents().size(); + } catch (ChebiSearchException e) { + throw new ComparatorException(e); + } + + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndSimpleEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndSimpleEntityComparator.java index ccb0892dd1..e40a5f9535 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndSimpleEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/MoleculeAndSimpleEntityComparator.java @@ -1,51 +1,51 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.List; -import java.util.Set; - -import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.species.SimpleMolecule; -import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -/** - * This class allows to compare {@link SimpleMolecule} element (internal - * representation) and {@link ReactomeSimpleEntity} (reactome model). - * - * @author Piotr Gawron - * - */ -public class MoleculeAndSimpleEntityComparator extends ANodeComparator<SimpleMolecule, ReactomeSimpleEntity> { - - /** - * Default constructor. - */ - public MoleculeAndSimpleEntityComparator() { - super(SimpleMolecule.class, ReactomeSimpleEntity.class); - } - - @Override - public boolean compareNodes(SimpleMolecule species, ReactomeSimpleEntity simpleEntity) throws ComparatorException { - try { - List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); - if (chebi1.size() == 0) { // if we don't have id then return false (even - // with two null values we cannot claim that - // they - // are equal) - return false; - } - Set<MiriamData> chebiIds2 = getRcu().getIdentifiersForReactomeEntity(simpleEntity); - // no match was found, so lets assume that they are different - for (MiriamData string : chebi1) { - if (chebiIds2.contains(string)) { - return true; - } - } - return false; - } catch (ChebiSearchException e) { - throw new ComparatorException(e); - } - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.List; +import java.util.Set; + +import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.species.SimpleMolecule; +import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +/** + * This class allows to compare {@link SimpleMolecule} element (internal + * representation) and {@link ReactomeSimpleEntity} (reactome model). + * + * @author Piotr Gawron + * + */ +public class MoleculeAndSimpleEntityComparator extends ANodeComparator<SimpleMolecule, ReactomeSimpleEntity> { + + /** + * Default constructor. + */ + public MoleculeAndSimpleEntityComparator() { + super(SimpleMolecule.class, ReactomeSimpleEntity.class); + } + + @Override + public boolean compareNodes(SimpleMolecule species, ReactomeSimpleEntity simpleEntity) throws ComparatorException { + try { + List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); + if (chebi1.size() == 0) { // if we don't have id then return false (even + // with two null values we cannot claim that + // they + // are equal) + return false; + } + Set<MiriamData> chebiIds2 = getRcu().getIdentifiersForReactomeEntity(simpleEntity); + // no match was found, so lets assume that they are different + for (MiriamData string : chebi1) { + if (chebiIds2.contains(string)) { + return true; + } + } + return false; + } catch (ChebiSearchException e) { + throw new ComparatorException(e); + } + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/NodeComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/NodeComparator.java index f08896433f..8173ac703f 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/NodeComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/NodeComparator.java @@ -1,132 +1,132 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.persist.SpringApplicationContext; -import lcsb.mapviewer.reactome.model.ReactomeDatabaseObject; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -/** - * Comparator that allows to compare nodes in our format with nodes in reactome - * format. - * - * @author Piotr Gawron - * - */ -public class NodeComparator extends ANodeComparator<Species, ReactomeDatabaseObject> { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(NodeComparator.class); - - /** - * This map contains implementation of all known comparators between local - * node representation and reactome node representation. - */ - private Map<String, ANodeComparator<?, ?>> comparators = new HashMap<String, ANodeComparator<?, ?>>(); - - /** - * Default constructor. Initializes {@link #comparators} with every known - * implementation of {@link ANodeComparator}. - */ - public NodeComparator() { - super(Species.class, ReactomeDatabaseObject.class); - } - - /** - * Adds comparator to the list of known comparators. - * - * @param comparator - * comparator to add - */ - private void addComparator(ANodeComparator<?, ?> comparator) { - comparators.put(comparator.getSpeciesClass().getName() + "," + comparator.getReactomeSpeciesClass().getName(), comparator); - comparator.setGlobalComparator(this); - } - - @SuppressWarnings("unchecked") - @Override - public boolean compareNodes(Species species, ReactomeDatabaseObject reactomeSpecies) throws ComparatorException { - String speciesName = species.getClass().getName(); - if (species instanceof Protein) { - speciesName = Protein.class.getName(); - } - String serializedClassComparator = speciesName + "," + reactomeSpecies.getClass().getName(); - if (serializedClassComparator.indexOf("_$$_javassist_") >= 0) { - serializedClassComparator = serializedClassComparator.substring(0, serializedClassComparator.indexOf("_$$_javassist_")); - } - @SuppressWarnings("rawtypes") - ANodeComparator comparator = getComparator(serializedClassComparator); - if (comparator != null) { - return comparator.compareNodes(species, reactomeSpecies); - } else { - logger.debug("Debug information for exception: "); - logger.debug("Species: " + species.getElementId()); - logger.debug("Reactome object: " + reactomeSpecies.getDbId()); - throw new InvalidArgumentException("Unknown comparator for classes: " + serializedClassComparator); - } - - } - - /** - * Initializes node comparators. We cannot do in constructor, because - * {@link #applicationContext} is not set yet. - */ - private void init() { - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndCandidateSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndComplexComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndOtherEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndSimpleEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(DrugAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(GeneAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(GeneAndOtherEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndComplexComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndSimpleEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndComplexComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndSimpleEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndCandidateSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndComplexComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndDefinedSetComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndGenomeEncodedEntity.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndPolymerComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndSimpleEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndOtherEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(UnknownAndCatalystComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(UnknownAndGenomeEncodedEntityComparator.class.getSimpleName())); - addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(DegradedAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); - } - - /** - * Returns a comparator for nodes represented by the string. - * - * @param serializedClassComparator - * string with two class names separated by a coma - * @return comparator for given node classes - */ - @SuppressWarnings("rawtypes") - private ANodeComparator getComparator(String serializedClassComparator) { - if (comparators.size() == 0) { - init(); - } - return comparators.get(serializedClassComparator); - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.model.map.species.Species; +import lcsb.mapviewer.persist.SpringApplicationContext; +import lcsb.mapviewer.reactome.model.ReactomeDatabaseObject; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +/** + * Comparator that allows to compare nodes in our format with nodes in reactome + * format. + * + * @author Piotr Gawron + * + */ +public class NodeComparator extends ANodeComparator<Species, ReactomeDatabaseObject> { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(NodeComparator.class); + + /** + * This map contains implementation of all known comparators between local + * node representation and reactome node representation. + */ + private Map<String, ANodeComparator<?, ?>> comparators = new HashMap<String, ANodeComparator<?, ?>>(); + + /** + * Default constructor. Initializes {@link #comparators} with every known + * implementation of {@link ANodeComparator}. + */ + public NodeComparator() { + super(Species.class, ReactomeDatabaseObject.class); + } + + /** + * Adds comparator to the list of known comparators. + * + * @param comparator + * comparator to add + */ + private void addComparator(ANodeComparator<?, ?> comparator) { + comparators.put(comparator.getSpeciesClass().getName() + "," + comparator.getReactomeSpeciesClass().getName(), comparator); + comparator.setGlobalComparator(this); + } + + @SuppressWarnings("unchecked") + @Override + public boolean compareNodes(Species species, ReactomeDatabaseObject reactomeSpecies) throws ComparatorException { + String speciesName = species.getClass().getName(); + if (species instanceof Protein) { + speciesName = Protein.class.getName(); + } + String serializedClassComparator = speciesName + "," + reactomeSpecies.getClass().getName(); + if (serializedClassComparator.indexOf("_$$_javassist_") >= 0) { + serializedClassComparator = serializedClassComparator.substring(0, serializedClassComparator.indexOf("_$$_javassist_")); + } + @SuppressWarnings("rawtypes") + ANodeComparator comparator = getComparator(serializedClassComparator); + if (comparator != null) { + return comparator.compareNodes(species, reactomeSpecies); + } else { + logger.debug("Debug information for exception: "); + logger.debug("Species: " + species.getElementId()); + logger.debug("Reactome object: " + reactomeSpecies.getDbId()); + throw new InvalidArgumentException("Unknown comparator for classes: " + serializedClassComparator); + } + + } + + /** + * Initializes node comparators. We cannot do in constructor, because + * {@link #applicationContext} is not set yet. + */ + private void init() { + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndCandidateSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndComplexComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndOtherEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ComplexAndSimpleEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(DrugAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(GeneAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(GeneAndOtherEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndComplexComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(IonAndSimpleEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndComplexComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(MoleculeAndSimpleEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndCandidateSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndComplexComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndDefinedSetComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndGenomeEncodedEntity.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndPolymerComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndSimpleEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(ProteinAndOtherEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(UnknownAndCatalystComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(UnknownAndGenomeEncodedEntityComparator.class.getSimpleName())); + addComparator((ANodeComparator<?, ?>) SpringApplicationContext.getBean(DegradedAndEntityWithAccessionedSequenceComparator.class.getSimpleName())); + } + + /** + * Returns a comparator for nodes represented by the string. + * + * @param serializedClassComparator + * string with two class names separated by a coma + * @return comparator for given node classes + */ + @SuppressWarnings("rawtypes") + private ANodeComparator getComparator(String serializedClassComparator) { + if (comparators.size() == 0) { + init(); + } + return comparators.get(serializedClassComparator); + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndOtherEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndOtherEntityComparator.java index 3cf9644d83..558796548e 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndOtherEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndOtherEntityComparator.java @@ -1,36 +1,36 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Protein} element (internal - * representation) and {@link ReactomeOtherEntity} (reactome model). - * - * @author Piotr Gawron - * - */ -public class ProteinAndOtherEntityComparator extends ANodeComparator<Protein, ReactomeOtherEntity> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ProteinAndOtherEntityComparator.class); - - /** - * Default constructor. - */ - public ProteinAndOtherEntityComparator() { - super(Protein.class, ReactomeOtherEntity.class); - } - - @Override - public boolean compareNodes(Protein species, ReactomeOtherEntity rSpecies) { - logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() - + " should be comparable, but how??? Assuming FALSE"); - return false; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Protein} element (internal + * representation) and {@link ReactomeOtherEntity} (reactome model). + * + * @author Piotr Gawron + * + */ +public class ProteinAndOtherEntityComparator extends ANodeComparator<Protein, ReactomeOtherEntity> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ProteinAndOtherEntityComparator.class); + + /** + * Default constructor. + */ + public ProteinAndOtherEntityComparator() { + super(Protein.class, ReactomeOtherEntity.class); + } + + @Override + public boolean compareNodes(Protein species, ReactomeOtherEntity rSpecies) { + logger.warn(species.getClass() + ", " + species.getElementId() + " and " + rSpecies.getClass() + ", " + rSpecies.getDbId() + + " should be comparable, but how??? Assuming FALSE"); + return false; + } + +} diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndPolymerComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndPolymerComparator.java index fce9b5770f..735ce48ff5 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndPolymerComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ProteinAndPolymerComparator.java @@ -1,106 +1,106 @@ -package lcsb.mapviewer.reactome.utils.comparators; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.species.Protein; -import lcsb.mapviewer.reactome.model.ReactomeComplex; -import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; -import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; -import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; -import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; -import lcsb.mapviewer.reactome.model.ReactomePolymer; -import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; -import lcsb.mapviewer.reactome.model.ReactomeReferenceGeneProduct; -import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; -import lcsb.mapviewer.reactome.utils.ComparatorException; - -import org.apache.log4j.Logger; - -/** - * This class allows to compare {@link Protein} element (internal - * representation) and {@link ReactomePolymer} (reactome model). - * - * @author Piotr Gawron - * - */ -public class ProteinAndPolymerComparator extends ANodeComparator<Protein, ReactomePolymer> { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ProteinAndPolymerComparator.class); - - /** - * Default constructor. - */ - public ProteinAndPolymerComparator() { - super(Protein.class, ReactomePolymer.class); - } - - @Override - public boolean compareNodes(Protein species, ReactomePolymer polymer) throws ComparatorException { - Set<MiriamData> uniprotIds1 = new HashSet<MiriamData>(); - Set<MiriamData> uniprotIds2 = new HashSet<MiriamData>(); - for (MiriamData md : species.getMiriamData()) { - if (MiriamType.UNIPROT.equals(md.getDataType())) { - uniprotIds1.add(md); - } - } - if (uniprotIds1.size() == 0) { - try { - for (MiriamData md : species.getMiriamData()) { - if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) { - List<MiriamData> uniprot = getHgncAnnotator().hgncToUniprot(md); - uniprotIds1.addAll(uniprot); - } - } - if (uniprotIds1.size() == 0) { - logger.warn("Cannot find uniprot identifier for: " + species.getName()); - return false; - } - } catch (Exception e) { - throw new InvalidArgumentException("Problem with converting ids: " + e.getMessage()); - } - } - - for (ReactomePhysicalEntity entity : polymer.getRepeatedUnits()) { - if (entity instanceof ReactomeEntityWithAccessionedSequence) { - ReactomeReferenceEntity reference = ((ReactomeEntityWithAccessionedSequence) entity).getReferenceEntity(); - if (reference instanceof ReactomeReferenceGeneProduct) { - uniprotIds2.add(new MiriamData(MiriamType.UNIPROT, reference.getIdentifier())); - } else { - throw new InvalidArgumentException("Unknown class type (" + reference.getClass() + "). Don't know what to do"); - } - } else if (entity instanceof ReactomeDefinedSet) { - logger.warn("Too complicated nesting... Ommiting..."); - } else if (entity instanceof ReactomeSimpleEntity) { - // cannot compare protein and chemical - return false; - } else if (entity instanceof ReactomeOtherEntity) { - // cannot compare protein and other entities - return false; - } else if (entity instanceof ReactomeComplex) { - // if subcomplex match then add appropriate ids - if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity)) { - uniprotIds2.addAll(uniprotIds1); - } - } else { - throw new InvalidArgumentException("Unknown class type (" + entity.getClass() + "). Don't know what to do"); - } - } - if (uniprotIds1.size() != uniprotIds2.size()) { - return false; - } - for (MiriamData string : uniprotIds2) { - if (!uniprotIds1.contains(string)) { - return false; - } - } - return true; - } - -} +package lcsb.mapviewer.reactome.utils.comparators; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.species.Protein; +import lcsb.mapviewer.reactome.model.ReactomeComplex; +import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; +import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; +import lcsb.mapviewer.reactome.model.ReactomeOtherEntity; +import lcsb.mapviewer.reactome.model.ReactomePhysicalEntity; +import lcsb.mapviewer.reactome.model.ReactomePolymer; +import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; +import lcsb.mapviewer.reactome.model.ReactomeReferenceGeneProduct; +import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; +import lcsb.mapviewer.reactome.utils.ComparatorException; + +import org.apache.log4j.Logger; + +/** + * This class allows to compare {@link Protein} element (internal + * representation) and {@link ReactomePolymer} (reactome model). + * + * @author Piotr Gawron + * + */ +public class ProteinAndPolymerComparator extends ANodeComparator<Protein, ReactomePolymer> { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ProteinAndPolymerComparator.class); + + /** + * Default constructor. + */ + public ProteinAndPolymerComparator() { + super(Protein.class, ReactomePolymer.class); + } + + @Override + public boolean compareNodes(Protein species, ReactomePolymer polymer) throws ComparatorException { + Set<MiriamData> uniprotIds1 = new HashSet<MiriamData>(); + Set<MiriamData> uniprotIds2 = new HashSet<MiriamData>(); + for (MiriamData md : species.getMiriamData()) { + if (MiriamType.UNIPROT.equals(md.getDataType())) { + uniprotIds1.add(md); + } + } + if (uniprotIds1.size() == 0) { + try { + for (MiriamData md : species.getMiriamData()) { + if (MiriamType.HGNC_SYMBOL.equals(md.getDataType())) { + List<MiriamData> uniprot = getHgncAnnotator().hgncToUniprot(md); + uniprotIds1.addAll(uniprot); + } + } + if (uniprotIds1.size() == 0) { + logger.warn("Cannot find uniprot identifier for: " + species.getName()); + return false; + } + } catch (Exception e) { + throw new InvalidArgumentException("Problem with converting ids: " + e.getMessage()); + } + } + + for (ReactomePhysicalEntity entity : polymer.getRepeatedUnits()) { + if (entity instanceof ReactomeEntityWithAccessionedSequence) { + ReactomeReferenceEntity reference = ((ReactomeEntityWithAccessionedSequence) entity).getReferenceEntity(); + if (reference instanceof ReactomeReferenceGeneProduct) { + uniprotIds2.add(new MiriamData(MiriamType.UNIPROT, reference.getIdentifier())); + } else { + throw new InvalidArgumentException("Unknown class type (" + reference.getClass() + "). Don't know what to do"); + } + } else if (entity instanceof ReactomeDefinedSet) { + logger.warn("Too complicated nesting... Ommiting..."); + } else if (entity instanceof ReactomeSimpleEntity) { + // cannot compare protein and chemical + return false; + } else if (entity instanceof ReactomeOtherEntity) { + // cannot compare protein and other entities + return false; + } else if (entity instanceof ReactomeComplex) { + // if subcomplex match then add appropriate ids + if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity)) { + uniprotIds2.addAll(uniprotIds1); + } + } else { + throw new InvalidArgumentException("Unknown class type (" + entity.getClass() + "). Don't know what to do"); + } + } + if (uniprotIds1.size() != uniprotIds2.size()) { + return false; + } + for (MiriamData string : uniprotIds2) { + if (!uniprotIds1.contains(string)) { + return false; + } + } + return true; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/comment/CommentDetails.java b/service/src/main/java/lcsb/mapviewer/services/search/comment/CommentDetails.java index cd7743d5a9..87315d0d24 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/comment/CommentDetails.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/comment/CommentDetails.java @@ -1,87 +1,87 @@ -package lcsb.mapviewer.services.search.comment; - -import lcsb.mapviewer.model.map.Comment; -import lcsb.mapviewer.services.search.ElementIdentifierDetails; - -/** - * Class with detailed information about element comments. - * - * @author Piotr Gawron - * - */ -public class CommentDetails extends ElementIdentifierDetails { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Identifier of the comment. - */ - private String commentId; - - /** - * Content of the comment. - */ - private String commentContent; - - /** - * Default constructor. - * - * @param id - * {@link #commentId} - * @param content - * {@link #commentContent} - */ - public CommentDetails(String id, String content) { - this.commentId = id; - this.commentContent = content; - } - - /** - * Default constructor. - * - * @param comment - * comment with detailed information - */ - public CommentDetails(Comment comment) { - commentId = comment.getId() + ""; - commentContent = comment.getContent(); - } - - /** - * @return the commentId - * @see #commentId - */ - public String getCommentId() { - return commentId; - } - - /** - * @param commentId - * the commentId to set - * @see #commentId - */ - public void setCommentId(String commentId) { - this.commentId = commentId; - } - - /** - * @return the commentContent - * @see #commentContent - */ - public String getCommentContent() { - return commentContent; - } - - /** - * @param commentContent - * the commentContent to set - * @see #commentContent - */ - public void setCommentContent(String commentContent) { - this.commentContent = commentContent; - } - -} +package lcsb.mapviewer.services.search.comment; + +import lcsb.mapviewer.model.map.Comment; +import lcsb.mapviewer.services.search.ElementIdentifierDetails; + +/** + * Class with detailed information about element comments. + * + * @author Piotr Gawron + * + */ +public class CommentDetails extends ElementIdentifierDetails { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Identifier of the comment. + */ + private String commentId; + + /** + * Content of the comment. + */ + private String commentContent; + + /** + * Default constructor. + * + * @param id + * {@link #commentId} + * @param content + * {@link #commentContent} + */ + public CommentDetails(String id, String content) { + this.commentId = id; + this.commentContent = content; + } + + /** + * Default constructor. + * + * @param comment + * comment with detailed information + */ + public CommentDetails(Comment comment) { + commentId = comment.getId() + ""; + commentContent = comment.getContent(); + } + + /** + * @return the commentId + * @see #commentId + */ + public String getCommentId() { + return commentId; + } + + /** + * @param commentId + * the commentId to set + * @see #commentId + */ + public void setCommentId(String commentId) { + this.commentId = commentId; + } + + /** + * @return the commentContent + * @see #commentContent + */ + public String getCommentContent() { + return commentContent; + } + + /** + * @param commentContent + * the commentContent to set + * @see #commentContent + */ + public void setCommentContent(String commentContent) { + this.commentContent = commentContent; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/comment/FullCommentViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/comment/FullCommentViewFactory.java index d1936b6c41..8a5d4112be 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/comment/FullCommentViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/comment/FullCommentViewFactory.java @@ -1,84 +1,84 @@ -package lcsb.mapviewer.services.search.comment; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.Comment; -import lcsb.mapviewer.model.map.layout.alias.Alias; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.services.overlay.IconManager; -import lcsb.mapviewer.services.search.SearchResultFactory; -import lcsb.mapviewer.services.search.data.ElementIdentifier; -import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType; - -/** - * Factory class for {@link FullCommentView} class. - * - * @author Piotr Gawron - * - */ -public class FullCommentViewFactory extends SearchResultFactory<List<Comment>, FullCommentView> { - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(FullCommentViewFactory.class); - - @Override - public FullCommentView create(List<Comment> list) { - Point2D point = new Point2D.Double(0, 0); - Comment comment = list.get(0); - Class<?> type; - FullCommentView result; - if (comment.getTableName() != null) { - result = new FullCommentView(comment.getTableId(), comment.getSubmodelData().getId()); - if (comment.getTableName().getName().contains("Reaction")) { - type = Reaction.class; - } else { - type = Alias.class; - } - } else { - point.setLocation(comment.getCoordinates().getX(), comment.getCoordinates().getY()); - result = new FullCommentView(point, comment.getSubmodelData().getId()); - type = Point2D.class; - } - result.setType(type); - - for (int i = 0; i < list.size(); i++) { - Pair<String, String> pair = new Pair<String, String>("" + list.get(i).getId(), list.get(i).getContent()); - result.getComments().add(pair); - } - return result; - } - - @Override - public String createGson(FullCommentView object) { - return new Gson().toJson(object); - } - - @Override - public List<ElementIdentifier> searchResultToElementIdentifier(FullCommentView comment, Model model) { - List<ElementIdentifier> result = new ArrayList<>(); - if (Reaction.class.equals(comment.getType())) { - result - .add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.REACTION, IconManager.getInstance().getCommentIcon())); - } else if (Alias.class.equals(comment.getType())) { - result.add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.ALIAS, IconManager.getInstance().getCommentIcon())); - } else if (Point2D.class.equals(comment.getType())) { - result.add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.POINT, IconManager.getInstance().getCommentIcon())); - } else { - throw new InvalidArgumentException("Unknown comment type: " + comment.getType()); - } - return result; - } - -} +package lcsb.mapviewer.services.search.comment; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.map.Comment; +import lcsb.mapviewer.model.map.layout.alias.Alias; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.services.overlay.IconManager; +import lcsb.mapviewer.services.search.SearchResultFactory; +import lcsb.mapviewer.services.search.data.ElementIdentifier; +import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType; + +/** + * Factory class for {@link FullCommentView} class. + * + * @author Piotr Gawron + * + */ +public class FullCommentViewFactory extends SearchResultFactory<List<Comment>, FullCommentView> { + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(FullCommentViewFactory.class); + + @Override + public FullCommentView create(List<Comment> list) { + Point2D point = new Point2D.Double(0, 0); + Comment comment = list.get(0); + Class<?> type; + FullCommentView result; + if (comment.getTableName() != null) { + result = new FullCommentView(comment.getTableId(), comment.getSubmodelData().getId()); + if (comment.getTableName().getName().contains("Reaction")) { + type = Reaction.class; + } else { + type = Alias.class; + } + } else { + point.setLocation(comment.getCoordinates().getX(), comment.getCoordinates().getY()); + result = new FullCommentView(point, comment.getSubmodelData().getId()); + type = Point2D.class; + } + result.setType(type); + + for (int i = 0; i < list.size(); i++) { + Pair<String, String> pair = new Pair<String, String>("" + list.get(i).getId(), list.get(i).getContent()); + result.getComments().add(pair); + } + return result; + } + + @Override + public String createGson(FullCommentView object) { + return new Gson().toJson(object); + } + + @Override + public List<ElementIdentifier> searchResultToElementIdentifier(FullCommentView comment, Model model) { + List<ElementIdentifier> result = new ArrayList<>(); + if (Reaction.class.equals(comment.getType())) { + result + .add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.REACTION, IconManager.getInstance().getCommentIcon())); + } else if (Alias.class.equals(comment.getType())) { + result.add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.ALIAS, IconManager.getInstance().getCommentIcon())); + } else if (Point2D.class.equals(comment.getType())) { + result.add(new ElementIdentifier(comment.getIdObject(), comment.getModelId(), ElementIdentifierType.POINT, IconManager.getInstance().getCommentIcon())); + } else { + throw new InvalidArgumentException("Unknown comment type: " + comment.getType()); + } + return result; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/data/ElementIdentifier.java b/service/src/main/java/lcsb/mapviewer/services/search/data/ElementIdentifier.java index 7298c2d7d0..84ba728014 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/data/ElementIdentifier.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/data/ElementIdentifier.java @@ -1,250 +1,250 @@ -package lcsb.mapviewer.services.search.data; - -import java.io.Serializable; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.map.layout.alias.Alias; - -/** - * Light class identifing element to visualize on map in a browser. - * - * @author Piotr Gawron - * - */ -public class ElementIdentifier implements Serializable { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ElementIdentifier.class); - - /** - * Enum identifing type of {@link ElementIdentifier}. - * - * @author Piotr Gawron - * - */ - public enum ElementIdentifierType { - - /** - * Type representing alias object on the map. - */ - ALIAS("ALIAS"), - - /** - * Type representing any point on the map. - */ - POINT("POINT"), - - /** - * Type representing reaction object on the map. - */ - REACTION("REACTION"); - - /** - * String used in Javascript code to identify type. - */ - private String jsName; - - /** - * Constructor intializing enum type. - * - * @param jsName - * {@link #jsName} - */ - ElementIdentifierType(String jsName) { - this.jsName = jsName; - } - - /** - * @return the jsName - * @see #jsName - */ - public String getJsName() { - return jsName; - } - - /** - * Returns {@link ElementIdentifierType} by the javascript name. - * - * @param jsName - * javascript name of the type - * @return {@link ElementIdentifierType} by the javascript name - */ - public static ElementIdentifierType getTypeByJsName(String jsName) { - for (ElementIdentifierType value : values()) { - if (value.getJsName().equalsIgnoreCase(jsName)) { - return value; - } - } - logger.warn("Cannot find ElementIdentifierType for jsName: " + jsName); - return null; - } - - } - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Identifier of the element. - */ - private String objectId; - - /** - * Model on which element is placed. - */ - private Integer modelId; - - /** - * Type of the element. - */ - private String type; - - /** - * Icon associated with the element. - */ - private String icon; - - /** - * Default constructor. - * - * @param objectId - * {@link #objectId} - * @param modelId - * {@link #modelId} - * @param type - * {@link #type} - * @param icon - * {@link #icon} - */ - public ElementIdentifier(Integer objectId, Integer modelId, ElementIdentifierType type, String icon) { - this(objectId + "", modelId, type, icon); - } - - /** - * Default constructor. - * - * @param objectId - * {@link #objectId} - * @param modelId - * {@link #modelId} - * @param type - * {@link #type} - * @param icon - * {@link #icon} - */ - public ElementIdentifier(String objectId, Integer modelId, ElementIdentifierType type, String icon) { - this.objectId = objectId; - this.modelId = modelId; - this.type = type.getJsName(); - this.icon = icon; - } - - /** - * Constructor creating object from {@link Alias}. - * - * @param speciesAlias - * {@link Alias} from which {@link ElementIdentifier} is created - * @param icon - * {@link #icon} - */ - public ElementIdentifier(Alias speciesAlias, String icon) { - this(speciesAlias.getId(), speciesAlias.getModel().getId(), ElementIdentifierType.ALIAS, icon); - } - - /** - * Default constructor. - * - * @param objectId - * {@link #objectId} - * @param modelId - * {@link #modelId} - * @param type - * {@link #type} - * @param icon - * {@link #icon} - */ - public ElementIdentifier(String objectId, String modelId, ElementIdentifierType type, String icon) { - this(objectId + "", Integer.valueOf(modelId), type, icon); - } - - /** - * @return the objectId - * @see #objectId - */ - public String getObjectId() { - return objectId; - } - - /** - * @param objectId - * the objectId to set - * @see #objectId - */ - public void setObjectId(String objectId) { - this.objectId = objectId; - } - - /** - * @return the modelId - * @see #modelId - */ - public Integer getModelId() { - return modelId; - } - - /** - * @param modelId - * the modelId to set - * @see #modelId - */ - public void setModelId(Integer modelId) { - this.modelId = modelId; - } - - /** - * @return the type - * @see #type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(String type) { - this.type = type; - } - - /** - * @return the icon - * @see #icon - */ - public String getIcon() { - return icon; - } - - /** - * @param icon - * the icon to set - * @see #icon - */ - public void setIcon(String icon) { - this.icon = icon; - } - - @Override - public String toString() { - String result = "[" + this.getClass().getSimpleName() + "]\t" + // - "objectId:" + objectId + "\t" + // - "modelId:" + modelId + "\t" + // - "type:" + type + "\t"; - return result; - } -} +package lcsb.mapviewer.services.search.data; + +import java.io.Serializable; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.model.map.layout.alias.Alias; + +/** + * Light class identifing element to visualize on map in a browser. + * + * @author Piotr Gawron + * + */ +public class ElementIdentifier implements Serializable { + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ElementIdentifier.class); + + /** + * Enum identifing type of {@link ElementIdentifier}. + * + * @author Piotr Gawron + * + */ + public enum ElementIdentifierType { + + /** + * Type representing alias object on the map. + */ + ALIAS("ALIAS"), + + /** + * Type representing any point on the map. + */ + POINT("POINT"), + + /** + * Type representing reaction object on the map. + */ + REACTION("REACTION"); + + /** + * String used in Javascript code to identify type. + */ + private String jsName; + + /** + * Constructor intializing enum type. + * + * @param jsName + * {@link #jsName} + */ + ElementIdentifierType(String jsName) { + this.jsName = jsName; + } + + /** + * @return the jsName + * @see #jsName + */ + public String getJsName() { + return jsName; + } + + /** + * Returns {@link ElementIdentifierType} by the javascript name. + * + * @param jsName + * javascript name of the type + * @return {@link ElementIdentifierType} by the javascript name + */ + public static ElementIdentifierType getTypeByJsName(String jsName) { + for (ElementIdentifierType value : values()) { + if (value.getJsName().equalsIgnoreCase(jsName)) { + return value; + } + } + logger.warn("Cannot find ElementIdentifierType for jsName: " + jsName); + return null; + } + + } + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Identifier of the element. + */ + private String objectId; + + /** + * Model on which element is placed. + */ + private Integer modelId; + + /** + * Type of the element. + */ + private String type; + + /** + * Icon associated with the element. + */ + private String icon; + + /** + * Default constructor. + * + * @param objectId + * {@link #objectId} + * @param modelId + * {@link #modelId} + * @param type + * {@link #type} + * @param icon + * {@link #icon} + */ + public ElementIdentifier(Integer objectId, Integer modelId, ElementIdentifierType type, String icon) { + this(objectId + "", modelId, type, icon); + } + + /** + * Default constructor. + * + * @param objectId + * {@link #objectId} + * @param modelId + * {@link #modelId} + * @param type + * {@link #type} + * @param icon + * {@link #icon} + */ + public ElementIdentifier(String objectId, Integer modelId, ElementIdentifierType type, String icon) { + this.objectId = objectId; + this.modelId = modelId; + this.type = type.getJsName(); + this.icon = icon; + } + + /** + * Constructor creating object from {@link Alias}. + * + * @param speciesAlias + * {@link Alias} from which {@link ElementIdentifier} is created + * @param icon + * {@link #icon} + */ + public ElementIdentifier(Alias speciesAlias, String icon) { + this(speciesAlias.getId(), speciesAlias.getModel().getId(), ElementIdentifierType.ALIAS, icon); + } + + /** + * Default constructor. + * + * @param objectId + * {@link #objectId} + * @param modelId + * {@link #modelId} + * @param type + * {@link #type} + * @param icon + * {@link #icon} + */ + public ElementIdentifier(String objectId, String modelId, ElementIdentifierType type, String icon) { + this(objectId + "", Integer.valueOf(modelId), type, icon); + } + + /** + * @return the objectId + * @see #objectId + */ + public String getObjectId() { + return objectId; + } + + /** + * @param objectId + * the objectId to set + * @see #objectId + */ + public void setObjectId(String objectId) { + this.objectId = objectId; + } + + /** + * @return the modelId + * @see #modelId + */ + public Integer getModelId() { + return modelId; + } + + /** + * @param modelId + * the modelId to set + * @see #modelId + */ + public void setModelId(Integer modelId) { + this.modelId = modelId; + } + + /** + * @return the type + * @see #type + */ + public String getType() { + return type; + } + + /** + * @param type + * the type to set + * @see #type + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the icon + * @see #icon + */ + public String getIcon() { + return icon; + } + + /** + * @param icon + * the icon to set + * @see #icon + */ + public void setIcon(String icon) { + this.icon = icon; + } + + @Override + public String toString() { + String result = "[" + this.getClass().getSimpleName() + "]\t" + // + "objectId:" + objectId + "\t" + // + "modelId:" + modelId + "\t" + // + "type:" + type + "\t"; + return result; + } +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/data/FullReactionViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/data/FullReactionViewFactory.java index b881de2c04..357b09b686 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/data/FullReactionViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/data/FullReactionViewFactory.java @@ -1,135 +1,135 @@ -package lcsb.mapviewer.services.search.data; - -import java.util.ArrayList; -import java.util.Collections; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; - -import lcsb.mapviewer.annotation.services.MiriamConnector; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.InvalidClassException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.Product; -import lcsb.mapviewer.model.map.reaction.Reactant; -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.reaction.ReactionNode; -import lcsb.mapviewer.services.search.ElementViewFactory; -import lcsb.mapviewer.services.view.AnnotationViewFactory; - -/** - * Factory class used to create {@link FullReactionView} elements from - * {@link Reaction} objects. - * - * @author Piotr Gawron - * - */ -public class FullReactionViewFactory extends ElementViewFactory<Reaction, FullReactionView> { - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(FullReactionViewFactory.class); - - /** - * Factory used to create {@link lcsb.mapviewer.services.view.AnnotationView - * AnnotationView} elements. - */ - @Autowired - private AnnotationViewFactory annotationViewFactory; - - /** - * Factory used to create {@link FullAliasView} elements. - */ - @Autowired - private FullAliasViewFactory fullAliasViewFactory; - - /** - * Connector to miriam database. - */ - @Autowired - private MiriamConnector mc; - - @Override - public FullReactionView create(Reaction reaction) { - FullReactionView result = new FullReactionView(reaction); - result.setGeneProteinReaction(convertToHtml(reaction.getGeneProteinReaction())); - - ArrayList<MiriamData> miriamList = new ArrayList<MiriamData>(reaction.getMiriamData()); - Collections.sort(miriamList); - result.setReferences(annotationViewFactory.createList(reaction.getMiriamData())); - - for (ReactionNode node : reaction.getReactionNodes()) { - FullAliasView fav = fullAliasViewFactory.create(node.getAlias()); - if (node instanceof Reactant) { - fav.addOther("NodeType", "Reactant"); - } else if (node instanceof Product) { - fav.addOther("NodeType", "Product"); - } else if (node instanceof Modifier) { - fav.addOther("NodeType", "Modifier"); - } else { - throw new InvalidClassException("Unknown reaction node type: " + node.getClass()); - } - result.getElements().add(fav); - } - - return result; - } - - @Override - public String createGson(FullReactionView object) { - throw new NotImplementedException(); - } - - /** - * Converts - * {@link lcsb.mapviewer.model.map.reaction.Reaction#geneProteinReaction} into - * html tags. - * - * @param string - * string to convert - * @return html string with hyperlinks to external databases - */ - public String convertToHtml(String string) { - if (string == null) { - return null; - } - String result = ""; - int index = 0; - - while (index >= 0) { - int begin = string.indexOf("(", index); - int end = -1; - if (begin >= 0) { - end = string.indexOf(")", begin); - } - if (end > 0) { - result += string.substring(index, begin); - String identifier = string.substring(begin + 1, end); - try { - MiriamData md = MiriamType.getMiriamByUri(identifier); - String link = mc.getUrlString(md); - if (link != null) { - result += "<a target=\"_blank\" href=\"" + link + "\"> " + md.getDataType().getCommonName() + " (" + md.getResource() + ")</a>"; - } else { - logger.warn("Cannot find url for: " + string); - } - } catch (InvalidArgumentException e) { - logger.warn("Unknown miriam urn: " + identifier); - result += "(" + identifier + ")"; - } - index = end + 1; - } else { - if (begin >= 0) { - logger.warn("Invalid GeneProteinReaction string: " + string); - } - index = -1; - } - } - return result; - } - -} +package lcsb.mapviewer.services.search.data; + +import java.util.ArrayList; +import java.util.Collections; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; + +import lcsb.mapviewer.annotation.services.MiriamConnector; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.InvalidClassException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.Product; +import lcsb.mapviewer.model.map.reaction.Reactant; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.model.map.reaction.ReactionNode; +import lcsb.mapviewer.services.search.ElementViewFactory; +import lcsb.mapviewer.services.view.AnnotationViewFactory; + +/** + * Factory class used to create {@link FullReactionView} elements from + * {@link Reaction} objects. + * + * @author Piotr Gawron + * + */ +public class FullReactionViewFactory extends ElementViewFactory<Reaction, FullReactionView> { + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(FullReactionViewFactory.class); + + /** + * Factory used to create {@link lcsb.mapviewer.services.view.AnnotationView + * AnnotationView} elements. + */ + @Autowired + private AnnotationViewFactory annotationViewFactory; + + /** + * Factory used to create {@link FullAliasView} elements. + */ + @Autowired + private FullAliasViewFactory fullAliasViewFactory; + + /** + * Connector to miriam database. + */ + @Autowired + private MiriamConnector mc; + + @Override + public FullReactionView create(Reaction reaction) { + FullReactionView result = new FullReactionView(reaction); + result.setGeneProteinReaction(convertToHtml(reaction.getGeneProteinReaction())); + + ArrayList<MiriamData> miriamList = new ArrayList<MiriamData>(reaction.getMiriamData()); + Collections.sort(miriamList); + result.setReferences(annotationViewFactory.createList(reaction.getMiriamData())); + + for (ReactionNode node : reaction.getReactionNodes()) { + FullAliasView fav = fullAliasViewFactory.create(node.getAlias()); + if (node instanceof Reactant) { + fav.addOther("NodeType", "Reactant"); + } else if (node instanceof Product) { + fav.addOther("NodeType", "Product"); + } else if (node instanceof Modifier) { + fav.addOther("NodeType", "Modifier"); + } else { + throw new InvalidClassException("Unknown reaction node type: " + node.getClass()); + } + result.getElements().add(fav); + } + + return result; + } + + @Override + public String createGson(FullReactionView object) { + throw new NotImplementedException(); + } + + /** + * Converts + * {@link lcsb.mapviewer.model.map.reaction.Reaction#geneProteinReaction} into + * html tags. + * + * @param string + * string to convert + * @return html string with hyperlinks to external databases + */ + public String convertToHtml(String string) { + if (string == null) { + return null; + } + String result = ""; + int index = 0; + + while (index >= 0) { + int begin = string.indexOf("(", index); + int end = -1; + if (begin >= 0) { + end = string.indexOf(")", begin); + } + if (end > 0) { + result += string.substring(index, begin); + String identifier = string.substring(begin + 1, end); + try { + MiriamData md = MiriamType.getMiriamByUri(identifier); + String link = mc.getUrlString(md); + if (link != null) { + result += "<a target=\"_blank\" href=\"" + link + "\"> " + md.getDataType().getCommonName() + " (" + md.getResource() + ")</a>"; + } else { + logger.warn("Cannot find url for: " + string); + } + } catch (InvalidArgumentException e) { + logger.warn("Unknown miriam urn: " + identifier); + result += "(" + identifier + ")"; + } + index = end + 1; + } else { + if (begin >= 0) { + logger.warn("Invalid GeneProteinReaction string: " + string); + } + index = -1; + } + } + return result; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/DbSearchCriteria.java b/service/src/main/java/lcsb/mapviewer/services/search/db/DbSearchCriteria.java index 4474a135a5..99305b7331 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/db/DbSearchCriteria.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/db/DbSearchCriteria.java @@ -1,167 +1,167 @@ -package lcsb.mapviewer.services.search.db; - -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.model.Model; - -/** - * Class with search criteria used by {@link IDbSearchService}. Contains - * information about {@link lcsb.mapviewer.model.map.MiriamType#TAXONOMY - * organisms}, {@link Model} where the search is performed, etc. - * - * @author Piotr Gawron - * - */ -public class DbSearchCriteria { - - /** - * Ip address of the client that requested this search. - */ - private String ipAddress; - - /** - * Id of disease to which results should be contextualized. - * - */ - private MiriamData disease; - - /** - * Model where client is looking for the results. - */ - private Model model; - - /** - * List of organisms used for filtering results. If the list is null or empty - * then filtering shouldn't be applied. Organisms must be represented as - * {@link lcsb.mapviewer.model.map.MiriamType#TAXONOMY} MiriamData objects. - * - */ - private List<MiriamData> organisms = new ArrayList<>(); - - /** - * Which set of icons should be used for representing results. - * - */ - private int colorSet = 0; - - /** - * @return the ipAddress - * @see #ipAddress - */ - public String getIpAddress() { - return ipAddress; - } - - /** - * @param ipAddress - * the ipAddress to set - * @see #ipAddress - * @return this object after changes - */ - public DbSearchCriteria ipAddress(String ipAddress) { - this.ipAddress = ipAddress; - return this; - } - - /** - * @return the model - * @see #model - */ - public Model getModel() { - return model; - } - - /** - * @param model - * the model to set - * @see #model - * @return this object after changes - */ - public DbSearchCriteria model(Model model) { - this.model = model; - return this; - } - - /** - * @return the organisms - * @see #organisms - */ - public List<MiriamData> getOrganisms() { - return organisms; - } - - /** - * @param organisms - * the organisms to add - * @see #organisms - * @return this object after changes - */ - public DbSearchCriteria organisms(List<MiriamData> organisms) { - this.organisms.addAll(organisms); - return this; - } - - /** - * @return the colorSet - * @see #colorSet - */ - public int getColorSet() { - return colorSet; - } - - /** - * @param colorSet - * the colorSet to set - * @see #colorSet - * @return this object after changes - */ - public DbSearchCriteria colorSet(int colorSet) { - this.colorSet = colorSet; - return this; - } - - /** - * @param organism - * the organism to add - * @see #organisms - * @return this object after changes - */ - public DbSearchCriteria organisms(MiriamData organism) { - this.organisms.add(organism); - return this; - } - - /** - * @param organisms - * the organisms to add - * @see #organisms - * @return this object after changes - */ - public DbSearchCriteria organisms(MiriamData[] organisms) { - for (MiriamData miriamData : organisms) { - this.organisms.add(miriamData); - } - return this; - } - - /** - * @return the disease - * @see #disease - */ - public MiriamData getDisease() { - return disease; - } - - /** - * @param disease - * the disease to set - * @see #disease - * @return this object after changes - */ - public DbSearchCriteria disease(MiriamData disease) { - this.disease = disease; - return this; - } -} +package lcsb.mapviewer.services.search.db; + +import java.util.ArrayList; +import java.util.List; + +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.model.Model; + +/** + * Class with search criteria used by {@link IDbSearchService}. Contains + * information about {@link lcsb.mapviewer.model.map.MiriamType#TAXONOMY + * organisms}, {@link Model} where the search is performed, etc. + * + * @author Piotr Gawron + * + */ +public class DbSearchCriteria { + + /** + * Ip address of the client that requested this search. + */ + private String ipAddress; + + /** + * Id of disease to which results should be contextualized. + * + */ + private MiriamData disease; + + /** + * Model where client is looking for the results. + */ + private Model model; + + /** + * List of organisms used for filtering results. If the list is null or empty + * then filtering shouldn't be applied. Organisms must be represented as + * {@link lcsb.mapviewer.model.map.MiriamType#TAXONOMY} MiriamData objects. + * + */ + private List<MiriamData> organisms = new ArrayList<>(); + + /** + * Which set of icons should be used for representing results. + * + */ + private int colorSet = 0; + + /** + * @return the ipAddress + * @see #ipAddress + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * @param ipAddress + * the ipAddress to set + * @see #ipAddress + * @return this object after changes + */ + public DbSearchCriteria ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * @return the model + * @see #model + */ + public Model getModel() { + return model; + } + + /** + * @param model + * the model to set + * @see #model + * @return this object after changes + */ + public DbSearchCriteria model(Model model) { + this.model = model; + return this; + } + + /** + * @return the organisms + * @see #organisms + */ + public List<MiriamData> getOrganisms() { + return organisms; + } + + /** + * @param organisms + * the organisms to add + * @see #organisms + * @return this object after changes + */ + public DbSearchCriteria organisms(List<MiriamData> organisms) { + this.organisms.addAll(organisms); + return this; + } + + /** + * @return the colorSet + * @see #colorSet + */ + public int getColorSet() { + return colorSet; + } + + /** + * @param colorSet + * the colorSet to set + * @see #colorSet + * @return this object after changes + */ + public DbSearchCriteria colorSet(int colorSet) { + this.colorSet = colorSet; + return this; + } + + /** + * @param organism + * the organism to add + * @see #organisms + * @return this object after changes + */ + public DbSearchCriteria organisms(MiriamData organism) { + this.organisms.add(organism); + return this; + } + + /** + * @param organisms + * the organisms to add + * @see #organisms + * @return this object after changes + */ + public DbSearchCriteria organisms(MiriamData[] organisms) { + for (MiriamData miriamData : organisms) { + this.organisms.add(miriamData); + } + return this; + } + + /** + * @return the disease + * @see #disease + */ + public MiriamData getDisease() { + return disease; + } + + /** + * @param disease + * the disease to set + * @see #disease + * @return this object after changes + */ + public DbSearchCriteria disease(MiriamData disease) { + this.disease = disease; + return this; + } +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/db/TargetDetails.java b/service/src/main/java/lcsb/mapviewer/services/search/db/TargetDetails.java index 1a25940054..579bec93e4 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/db/TargetDetails.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/db/TargetDetails.java @@ -1,71 +1,71 @@ -package lcsb.mapviewer.services.search.db; - -import java.util.ArrayList; -import java.util.List; - -import lcsb.mapviewer.services.search.ElementIdentifierDetails; -import lcsb.mapviewer.services.view.AnnotationView; - -/** - * Detailed information about drug targets. - * - * @author Piotr Gawron - * - */ -public class TargetDetails extends ElementIdentifierDetails { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * From where this information comes from. - */ - private AnnotationView databaseSource; - - /** - * List of references. - */ - private List<AnnotationView> references = new ArrayList<>(); - - /** - * @return the databaseSource - * @see #databaseSource - */ - public AnnotationView getDatabaseSource() { - return databaseSource; - } - - /** - * @param databaseSource - * the databaseSource to set - * @see #databaseSource - */ - public void setDatabaseSource(AnnotationView databaseSource) { - this.databaseSource = databaseSource; - } - - /** - * @return the references - * @see #references - */ - public List<AnnotationView> getReferences() { - return references; - } - - /** - * @param references - * the references to set - * @see #references - */ - public void setReferences(List<AnnotationView> references) { - this.references = references; - } - - @Override - public String toString() { - return "[TargetDetails]: " + databaseSource.toString() + "; " + references; - } - -} +package lcsb.mapviewer.services.search.db; + +import java.util.ArrayList; +import java.util.List; + +import lcsb.mapviewer.services.search.ElementIdentifierDetails; +import lcsb.mapviewer.services.view.AnnotationView; + +/** + * Detailed information about drug targets. + * + * @author Piotr Gawron + * + */ +public class TargetDetails extends ElementIdentifierDetails { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * From where this information comes from. + */ + private AnnotationView databaseSource; + + /** + * List of references. + */ + private List<AnnotationView> references = new ArrayList<>(); + + /** + * @return the databaseSource + * @see #databaseSource + */ + public AnnotationView getDatabaseSource() { + return databaseSource; + } + + /** + * @param databaseSource + * the databaseSource to set + * @see #databaseSource + */ + public void setDatabaseSource(AnnotationView databaseSource) { + this.databaseSource = databaseSource; + } + + /** + * @return the references + * @see #references + */ + public List<AnnotationView> getReferences() { + return references; + } + + /** + * @param references + * the references to set + * @see #references + */ + public void setReferences(List<AnnotationView> references) { + this.references = references; + } + + @Override + public String toString() { + return "[TargetDetails]: " + databaseSource.toString() + "; " + references; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasView.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasView.java index 0955cd5cc4..01e111ea77 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasView.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasView.java @@ -1,115 +1,115 @@ -package lcsb.mapviewer.services.search.layout; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.layout.GeneVariation; -import lcsb.mapviewer.model.map.layout.alias.Alias; -import lcsb.mapviewer.services.search.IHeavyView; -import lcsb.mapviewer.services.search.data.LightAliasView; -import lcsb.mapviewer.services.utils.data.ColorSchemaType; - -/** - * Heavy {@link LightAliasView view} for alias representing data that should be - * sent to client. - * - * @author Piotr Gawron - * - */ -public class FullLayoutAliasView extends LightLayoutAliasView implements IHeavyView { - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(FullLayoutAliasView.class); - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Description. - * - * @see ColorSchema#description - */ - private String description; - - /** - * Type of the layout. - * - * @see ColorSchema#getClass() - */ - private ColorSchemaType type; - - /** - * List of gene variants. - */ - private List<GeneVariation> geneVariations = new ArrayList<>(); - - /** - * Default constructor. - * - * @param alias - * object for which vie is created - */ - protected FullLayoutAliasView(Alias alias) { - super(alias); - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the type - * @see #type - */ - public ColorSchemaType getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(ColorSchemaType type) { - this.type = type; - } - - /** - * @return the geneVariations - * @see #geneVariations - */ - public List<GeneVariation> getGeneVariations() { - return geneVariations; - } - - /** - * @param geneVariations - * the geneVariations to set - * @see #geneVariations - */ - public void setGeneVariations(List<GeneVariation> geneVariations) { - this.geneVariations = geneVariations; - } - -} +package lcsb.mapviewer.services.search.layout; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.layout.GeneVariation; +import lcsb.mapviewer.model.map.layout.alias.Alias; +import lcsb.mapviewer.services.search.IHeavyView; +import lcsb.mapviewer.services.search.data.LightAliasView; +import lcsb.mapviewer.services.utils.data.ColorSchemaType; + +/** + * Heavy {@link LightAliasView view} for alias representing data that should be + * sent to client. + * + * @author Piotr Gawron + * + */ +public class FullLayoutAliasView extends LightLayoutAliasView implements IHeavyView { + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(FullLayoutAliasView.class); + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Description. + * + * @see ColorSchema#description + */ + private String description; + + /** + * Type of the layout. + * + * @see ColorSchema#getClass() + */ + private ColorSchemaType type; + + /** + * List of gene variants. + */ + private List<GeneVariation> geneVariations = new ArrayList<>(); + + /** + * Default constructor. + * + * @param alias + * object for which vie is created + */ + protected FullLayoutAliasView(Alias alias) { + super(alias); + } + + /** + * @return the description + * @see #description + */ + public String getDescription() { + return description; + } + + /** + * @param description + * the description to set + * @see #description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the type + * @see #type + */ + public ColorSchemaType getType() { + return type; + } + + /** + * @param type + * the type to set + * @see #type + */ + public void setType(ColorSchemaType type) { + this.type = type; + } + + /** + * @return the geneVariations + * @see #geneVariations + */ + public List<GeneVariation> getGeneVariations() { + return geneVariations; + } + + /** + * @param geneVariations + * the geneVariations to set + * @see #geneVariations + */ + public void setGeneVariations(List<GeneVariation> geneVariations) { + this.geneVariations = geneVariations; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java index c9141208c9..455cd161b0 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/FullLayoutAliasViewFactory.java @@ -1,49 +1,49 @@ -package lcsb.mapviewer.services.search.layout; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema; -import lcsb.mapviewer.model.map.layout.alias.Alias; -import lcsb.mapviewer.services.search.ElementViewFactory; -import lcsb.mapviewer.services.utils.data.ColorSchemaType; - -/** - * Factory class for {@link FullLayoutAliasView} class. - * - * @author Piotr Gawron - * - */ -public class FullLayoutAliasViewFactory extends ElementViewFactory<Pair<Alias, ColorSchema>, FullLayoutAliasView> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(FullLayoutAliasViewFactory.class); - - @Override - public FullLayoutAliasView create(Pair<Alias, ColorSchema> pair) { - ColorSchema schema = pair.getRight(); - - FullLayoutAliasView result = new FullLayoutAliasView(pair.getLeft()); - result.setColor(schema.getNormalizedColor()); - result.setValue(schema.getValue()); - result.setDescription(schema.getDescription()); - if (schema instanceof GeneVariationColorSchema) { - result.setGeneVariations(((GeneVariationColorSchema) schema).getGeneVariations()); - result.setType(ColorSchemaType.GENETIC_VARIANT); - } else { - result.setType(ColorSchemaType.GENERIC); - } - return result; - } - - @Override - public String createGson(FullLayoutAliasView object) { - return new Gson().toJson(object); - } - -} +package lcsb.mapviewer.services.search.layout; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema; +import lcsb.mapviewer.model.map.layout.alias.Alias; +import lcsb.mapviewer.services.search.ElementViewFactory; +import lcsb.mapviewer.services.utils.data.ColorSchemaType; + +/** + * Factory class for {@link FullLayoutAliasView} class. + * + * @author Piotr Gawron + * + */ +public class FullLayoutAliasViewFactory extends ElementViewFactory<Pair<Alias, ColorSchema>, FullLayoutAliasView> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(FullLayoutAliasViewFactory.class); + + @Override + public FullLayoutAliasView create(Pair<Alias, ColorSchema> pair) { + ColorSchema schema = pair.getRight(); + + FullLayoutAliasView result = new FullLayoutAliasView(pair.getLeft()); + result.setColor(schema.getNormalizedColor()); + result.setValue(schema.getValue()); + result.setDescription(schema.getDescription()); + if (schema instanceof GeneVariationColorSchema) { + result.setGeneVariations(((GeneVariationColorSchema) schema).getGeneVariations()); + result.setType(ColorSchemaType.GENETIC_VARIANT); + } else { + result.setType(ColorSchemaType.GENERIC); + } + return result; + } + + @Override + public String createGson(FullLayoutAliasView object) { + return new Gson().toJson(object); + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java index 68aad0d14d..c3666b448b 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutAliasViewFactory.java @@ -1,37 +1,37 @@ -package lcsb.mapviewer.services.search.layout; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.layout.alias.Alias; -import lcsb.mapviewer.services.search.ElementViewFactory; - -/** - * Factory class for {@link LightLayoutAliasView} class. - * - * @author Piotr Gawron - * - */ -public class LightLayoutAliasViewFactory extends ElementViewFactory<Pair<Alias, ColorSchema>, LightLayoutAliasView> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(LightLayoutAliasViewFactory.class); - - @Override - public LightLayoutAliasView create(Pair<Alias, ColorSchema> pair) { - LightLayoutAliasView result = new LightLayoutAliasView(pair.getLeft()); - result.setColor(pair.getRight().getNormalizedColor()); - result.setValue(pair.getRight().getValue()); - return result; - } - - @Override - public String createGson(LightLayoutAliasView object) { - return new Gson().toJson(object); - } -} +package lcsb.mapviewer.services.search.layout; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.layout.alias.Alias; +import lcsb.mapviewer.services.search.ElementViewFactory; + +/** + * Factory class for {@link LightLayoutAliasView} class. + * + * @author Piotr Gawron + * + */ +public class LightLayoutAliasViewFactory extends ElementViewFactory<Pair<Alias, ColorSchema>, LightLayoutAliasView> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(LightLayoutAliasViewFactory.class); + + @Override + public LightLayoutAliasView create(Pair<Alias, ColorSchema> pair) { + LightLayoutAliasView result = new LightLayoutAliasView(pair.getLeft()); + result.setColor(pair.getRight().getNormalizedColor()); + result.setValue(pair.getRight().getValue()); + return result; + } + + @Override + public String createGson(LightLayoutAliasView object) { + return new Gson().toJson(object); + } +} diff --git a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutReactionViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutReactionViewFactory.java index 2b54716467..fc7ff5ccac 100644 --- a/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutReactionViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/search/layout/LightLayoutReactionViewFactory.java @@ -1,38 +1,38 @@ -package lcsb.mapviewer.services.search.layout; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.services.search.ElementViewFactory; - -/** - * Factory class for {@link LightLayoutReactionView} class. - * - * @author Piotr Gawron - * - */ -public class LightLayoutReactionViewFactory extends ElementViewFactory<Pair<Reaction, ColorSchema>, LightLayoutReactionView> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(LightLayoutReactionViewFactory.class); - - @Override - public LightLayoutReactionView create(Pair<Reaction, ColorSchema> pair) { - LightLayoutReactionView result = new LightLayoutReactionView(pair.getLeft()); - result.setColor(pair.getRight().getNormalizedColor()); - result.setWidth(pair.getRight().getLineWidth()); - result.setReverse(pair.getRight().getReverseReaction()); - return result; - } - - @Override - public String createGson(LightLayoutReactionView object) { - return new Gson().toJson(object); - } -} +package lcsb.mapviewer.services.search.layout; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.services.search.ElementViewFactory; + +/** + * Factory class for {@link LightLayoutReactionView} class. + * + * @author Piotr Gawron + * + */ +public class LightLayoutReactionViewFactory extends ElementViewFactory<Pair<Reaction, ColorSchema>, LightLayoutReactionView> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(LightLayoutReactionViewFactory.class); + + @Override + public LightLayoutReactionView create(Pair<Reaction, ColorSchema> pair) { + LightLayoutReactionView result = new LightLayoutReactionView(pair.getLeft()); + result.setColor(pair.getRight().getNormalizedColor()); + result.setWidth(pair.getRight().getLineWidth()); + result.setReverse(pair.getRight().getReverseReaction()); + return result; + } + + @Override + public String createGson(LightLayoutReactionView object) { + return new Gson().toJson(object); + } +} diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java index a293276b46..2dfd6d892c 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java @@ -1,147 +1,147 @@ -package lcsb.mapviewer.services.utils.data; - -import java.util.HashSet; -import java.util.Set; - - -import lcsb.mapviewer.model.map.layout.ReferenceGenome; -import lcsb.mapviewer.model.map.layout.ReferenceGenomeType; - -/** - * This enum defines which columns are available for defining - * {@link lcsb.mapviewer.model.map.layout.ColorSchema}. - * - * @author Piotr Gawron - * - */ -public enum ColorSchemaColumn { - - /** - * Name of the element. - */ - NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Value that will be transformed into new color. - * - * @see ColorSchemaColumn#COLOR - */ - VALUE("value", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // - - /** - * In which compartment the element should be located. - */ - COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Class type of the element. - */ - TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * New element/reaction color. - */ - COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Identifier of the element. - */ - IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Reaction identifier. - */ - REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // - - /** - * New line width of the reaction. - */ - LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // - - /** - * Postion where gene variants starts. - */ - POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Original DNA of the variant. - */ - ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Alternative DNA of the variant. - */ - ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Short description of the entry. - */ - DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), // - - /** - * Variant references. - */ - REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * What's the {@link ReferenceGenomeType}. - */ - REFERENCE_GENOME_TYPE("reference_genome_type", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * {@link ReferenceGenome#version Version} of the reference genome. - */ - REFERENCE_GENOME_VERSION("reference_genome_version", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Contig where variant was observed. - */ - CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Should the direction of reaction be reversed. - */ - REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); // - - /** - * Default constructor that creates enum entry. - * - * @param title - * {@link #title} - * @param types - * list of {@link ColumnType types} where this column is allowed - */ - ColorSchemaColumn(String title, ColorSchemaType[] types) { - this.title = title; - for (ColorSchemaType colorSchemaType : types) { - this.types.add(colorSchemaType); - } - } - - /** - * Human readable title used in input file. - */ - private String title; - - /** - * Set of types where column is allowed. - */ - private Set<ColorSchemaType> types = new HashSet<>(); - - /** - * - * @return {@link #title} - */ - public String getTitle() { - return title; - } - - /** - * @return the types - * @see #types - */ - public Set<ColorSchemaType> getTypes() { - return types; - } - -} +package lcsb.mapviewer.services.utils.data; + +import java.util.HashSet; +import java.util.Set; + + +import lcsb.mapviewer.model.map.layout.ReferenceGenome; +import lcsb.mapviewer.model.map.layout.ReferenceGenomeType; + +/** + * This enum defines which columns are available for defining + * {@link lcsb.mapviewer.model.map.layout.ColorSchema}. + * + * @author Piotr Gawron + * + */ +public enum ColorSchemaColumn { + + /** + * Name of the element. + */ + NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Value that will be transformed into new color. + * + * @see ColorSchemaColumn#COLOR + */ + VALUE("value", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // + + /** + * In which compartment the element should be located. + */ + COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Class type of the element. + */ + TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * New element/reaction color. + */ + COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Identifier of the element. + */ + IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Reaction identifier. + */ + REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // + + /** + * New line width of the reaction. + */ + LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // + + /** + * Postion where gene variants starts. + */ + POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Original DNA of the variant. + */ + ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Alternative DNA of the variant. + */ + ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Short description of the entry. + */ + DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), // + + /** + * Variant references. + */ + REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * What's the {@link ReferenceGenomeType}. + */ + REFERENCE_GENOME_TYPE("reference_genome_type", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * {@link ReferenceGenome#version Version} of the reference genome. + */ + REFERENCE_GENOME_VERSION("reference_genome_version", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Contig where variant was observed. + */ + CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Should the direction of reaction be reversed. + */ + REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); // + + /** + * Default constructor that creates enum entry. + * + * @param title + * {@link #title} + * @param types + * list of {@link ColumnType types} where this column is allowed + */ + ColorSchemaColumn(String title, ColorSchemaType[] types) { + this.title = title; + for (ColorSchemaType colorSchemaType : types) { + this.types.add(colorSchemaType); + } + } + + /** + * Human readable title used in input file. + */ + private String title; + + /** + * Set of types where column is allowed. + */ + private Set<ColorSchemaType> types = new HashSet<>(); + + /** + * + * @return {@link #title} + */ + public String getTitle() { + return title; + } + + /** + * @return the types + * @see #types + */ + public Set<ColorSchemaType> getTypes() { + return types; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaType.java b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaType.java index 108a4ce7b1..7ab4f41a6f 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaType.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaType.java @@ -1,21 +1,21 @@ -package lcsb.mapviewer.services.utils.data; - -import lcsb.mapviewer.model.map.layout.ColorSchema; - -/** - * Type of the {@link ColorSchema}. - * - * @author Piotr Gawron - * - */ -public enum ColorSchemaType { - /** - * Generic color schema (used for expression levels, etc). - */ - GENERIC, - - /** - * Customized color schema used for highlightig genetic variants. - */ - GENETIC_VARIANT -} +package lcsb.mapviewer.services.utils.data; + +import lcsb.mapviewer.model.map.layout.ColorSchema; + +/** + * Type of the {@link ColorSchema}. + * + * @author Piotr Gawron + * + */ +public enum ColorSchemaType { + /** + * Generic color schema (used for expression levels, etc). + */ + GENERIC, + + /** + * Customized color schema used for highlightig genetic variants. + */ + GENETIC_VARIANT +} diff --git a/service/src/test/java/lcsb/mapviewer/services/search/comment/CommentDetailsTest.java b/service/src/test/java/lcsb/mapviewer/services/search/comment/CommentDetailsTest.java index d40216607a..538653fe47 100644 --- a/service/src/test/java/lcsb/mapviewer/services/search/comment/CommentDetailsTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/search/comment/CommentDetailsTest.java @@ -1,37 +1,37 @@ -package lcsb.mapviewer.services.search.comment; - -import java.awt.geom.Point2D; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.model.map.Comment; -import lcsb.mapviewer.model.map.model.ModelData; - -public class CommentDetailsTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - Comment comment = new Comment(); - comment.setCoordinates(new Point2D.Double()); - comment.setSubmodelData(new ModelData()); - - SerializationUtils.serialize(new CommentDetails(comment)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - -} +package lcsb.mapviewer.services.search.comment; + +import java.awt.geom.Point2D; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import lcsb.mapviewer.model.map.Comment; +import lcsb.mapviewer.model.map.model.ModelData; + +public class CommentDetailsTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + Comment comment = new Comment(); + comment.setCoordinates(new Point2D.Double()); + comment.setSubmodelData(new ModelData()); + + SerializationUtils.serialize(new CommentDetails(comment)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + +} diff --git a/service/src/test/java/lcsb/mapviewer/services/search/db/AllSearchDbTests.java b/service/src/test/java/lcsb/mapviewer/services/search/db/AllSearchDbTests.java index 82716f1126..dbcdf6e6c2 100644 --- a/service/src/test/java/lcsb/mapviewer/services/search/db/AllSearchDbTests.java +++ b/service/src/test/java/lcsb/mapviewer/services/search/db/AllSearchDbTests.java @@ -1,20 +1,20 @@ -package lcsb.mapviewer.services.search.db; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import lcsb.mapviewer.services.search.db.chemical.ChemicalServiceTest; -import lcsb.mapviewer.services.search.db.drug.AllSearchDrugTests; -import lcsb.mapviewer.services.search.db.mirna.MiRNAServiceTest; - -@RunWith(Suite.class) -@SuiteClasses({ AllSearchDrugTests.class, // - ChemicalServiceTest.class, // - MiRNAServiceTest.class, // - TargetViewFactoryTest.class, // - TargetViewTest.class,// -}) -public class AllSearchDbTests { - -} +package lcsb.mapviewer.services.search.db; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import lcsb.mapviewer.services.search.db.chemical.ChemicalServiceTest; +import lcsb.mapviewer.services.search.db.drug.AllSearchDrugTests; +import lcsb.mapviewer.services.search.db.mirna.MiRNAServiceTest; + +@RunWith(Suite.class) +@SuiteClasses({ AllSearchDrugTests.class, // + ChemicalServiceTest.class, // + MiRNAServiceTest.class, // + TargetViewFactoryTest.class, // + TargetViewTest.class,// +}) +public class AllSearchDbTests { + +} diff --git a/service/src/test/java/lcsb/mapviewer/services/search/layout/AllSearchLayoutTests.java b/service/src/test/java/lcsb/mapviewer/services/search/layout/AllSearchLayoutTests.java index ed9c1a6100..44246d3ba4 100644 --- a/service/src/test/java/lcsb/mapviewer/services/search/layout/AllSearchLayoutTests.java +++ b/service/src/test/java/lcsb/mapviewer/services/search/layout/AllSearchLayoutTests.java @@ -1,14 +1,14 @@ -package lcsb.mapviewer.services.search.layout; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ FullLayoutAliasViewFactoryTest.class, // - LightLayoutAliasViewTest.class, // - LightLayoutAliasViewFactoryTest.class, // - }) -public class AllSearchLayoutTests { - -} +package lcsb.mapviewer.services.search.layout; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ FullLayoutAliasViewFactoryTest.class, // + LightLayoutAliasViewTest.class, // + LightLayoutAliasViewFactoryTest.class, // + }) +public class AllSearchLayoutTests { + +} diff --git a/service/src/test/java/lcsb/mapviewer/services/utils/gmap/CoordinationConverterTest.java b/service/src/test/java/lcsb/mapviewer/services/utils/gmap/CoordinationConverterTest.java index 16957e1278..dd9abb96fa 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/gmap/CoordinationConverterTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/gmap/CoordinationConverterTest.java @@ -1,126 +1,126 @@ -package lcsb.mapviewer.services.utils.gmap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.awt.geom.Path2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; - -import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; -import lcsb.mapviewer.services.ServiceTestFunctions; - -import org.apache.commons.lang3.SerializationUtils; -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.primefaces.model.map.LatLng; - -public class CoordinationConverterTest extends ServiceTestFunctions { - - Logger logger = Logger.getLogger(CoordinationConverterTest.class); - LatLng latLng = new LatLng(81.49230582149616, -124.1015625); - Point2D point = new Point2D.Double(12428.0859375, 6917.519531249969); - private Model model; - - @Before - public void setUp() throws Exception { - model = new ModelFullIndexed(null); - model.setWidth(20010); - model.setHeight(20010); - model.setTileSize(256); - model.setZoomLevels(7); - model.addLayout(new Layout()); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testToLatLng() { - try { - CoordinationConverter converter = new CoordinationConverter(model); - LatLng latLng2 = converter.toLatLng(point); - assertEquals(Math.abs(latLng.getLat() - latLng2.getLat()) + Math.abs(latLng.getLng() - latLng2.getLng()), 0, EPSILON); - } catch (Exception e) { - e.printStackTrace(); - fail("Unknown exception occured"); - } - } - - @Test - public void testToPoint() { - try { - CoordinationConverter converter = new CoordinationConverter(model); - Point2D point2 = converter.toPoint(latLng); - assertEquals(0, point.distance(point2), EPSILON); - } catch (Exception e) { - e.printStackTrace(); - fail("Unknown exception occured"); - } - } - - @Test - public void testConvertPolygon() throws Exception { - try { - String latLngPolgyn = "84.21868256860863,164.619140625;83.3391531415795,-152.841796875;82.38497296909799,-171.1669921875;84.29345033920028,-178.1103515625;"; - - CoordinationConverter converter = new CoordinationConverter(model); - - Path2D polygon = converter.latLngToPolygon(latLngPolgyn); - PathIterator pi = polygon.getPathIterator(null); - int counter = 0; - while (!pi.isDone()) { - double[] value = new double[6]; - int type = pi.currentSegment(value); - if (type == PathIterator.SEG_MOVETO) - counter = 1; - else if (type == PathIterator.SEG_LINETO) - counter++; - pi.next(); - } - assertEquals(4, counter); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testToLatLng2() { - try { - Model m = new ModelFullIndexed(null); - m.setWidth(26547.3333333333); - m.setHeight(26547.3333333333); - m.setZoomLevels(8); - m.setTileSize(256); - CoordinationConverter converter = new CoordinationConverter(m); - Point2D p = new Point2D.Double(19920, 11040); - LatLng latLng2 = converter.toLatLng(p); - Point2D p2 = converter.toPoint(latLng2); - assertTrue(p.distance(p2) < EPSILON); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSerializable() throws Exception { - try { - CoordinationConverter converter = new CoordinationConverter(model); - SerializationUtils.serialize(converter); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - -} +package lcsb.mapviewer.services.utils.gmap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; + +import lcsb.mapviewer.model.map.layout.Layout; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelFullIndexed; +import lcsb.mapviewer.services.ServiceTestFunctions; + +import org.apache.commons.lang3.SerializationUtils; +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.primefaces.model.map.LatLng; + +public class CoordinationConverterTest extends ServiceTestFunctions { + + Logger logger = Logger.getLogger(CoordinationConverterTest.class); + LatLng latLng = new LatLng(81.49230582149616, -124.1015625); + Point2D point = new Point2D.Double(12428.0859375, 6917.519531249969); + private Model model; + + @Before + public void setUp() throws Exception { + model = new ModelFullIndexed(null); + model.setWidth(20010); + model.setHeight(20010); + model.setTileSize(256); + model.setZoomLevels(7); + model.addLayout(new Layout()); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToLatLng() { + try { + CoordinationConverter converter = new CoordinationConverter(model); + LatLng latLng2 = converter.toLatLng(point); + assertEquals(Math.abs(latLng.getLat() - latLng2.getLat()) + Math.abs(latLng.getLng() - latLng2.getLng()), 0, EPSILON); + } catch (Exception e) { + e.printStackTrace(); + fail("Unknown exception occured"); + } + } + + @Test + public void testToPoint() { + try { + CoordinationConverter converter = new CoordinationConverter(model); + Point2D point2 = converter.toPoint(latLng); + assertEquals(0, point.distance(point2), EPSILON); + } catch (Exception e) { + e.printStackTrace(); + fail("Unknown exception occured"); + } + } + + @Test + public void testConvertPolygon() throws Exception { + try { + String latLngPolgyn = "84.21868256860863,164.619140625;83.3391531415795,-152.841796875;82.38497296909799,-171.1669921875;84.29345033920028,-178.1103515625;"; + + CoordinationConverter converter = new CoordinationConverter(model); + + Path2D polygon = converter.latLngToPolygon(latLngPolgyn); + PathIterator pi = polygon.getPathIterator(null); + int counter = 0; + while (!pi.isDone()) { + double[] value = new double[6]; + int type = pi.currentSegment(value); + if (type == PathIterator.SEG_MOVETO) + counter = 1; + else if (type == PathIterator.SEG_LINETO) + counter++; + pi.next(); + } + assertEquals(4, counter); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testToLatLng2() { + try { + Model m = new ModelFullIndexed(null); + m.setWidth(26547.3333333333); + m.setHeight(26547.3333333333); + m.setZoomLevels(8); + m.setTileSize(256); + CoordinationConverter converter = new CoordinationConverter(m); + Point2D p = new Point2D.Double(19920, 11040); + LatLng latLng2 = converter.toLatLng(p); + Point2D p2 = converter.toPoint(latLng2); + assertTrue(p.distance(p2) < EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSerializable() throws Exception { + try { + CoordinationConverter converter = new CoordinationConverter(model); + SerializationUtils.serialize(converter); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + +} -- GitLab