From 86f5f5c9315a7261cfb7efd33f6372ec53e1a382 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 30 Nov 2015 09:27:47 +0000 Subject: [PATCH] JAL-653 getStrand javadoc/refactor/test --- src/jalview/datamodel/SequenceFeature.java | 31 +++++++++++++---------- test/jalview/datamodel/SequenceFeatureTest.java | 17 +++++++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 5fadb6f..e60e0c8 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -318,23 +318,28 @@ public class SequenceFeature return begin; } + /** + * Return 1 for forward strand ('+' in GFF), -1 for reverse strand ('-' in + * GFF), and 0 for unknown or not (validly) specified + * + * @return + */ public int getStrand() { - String str; - if (otherDetails == null - || (str = otherDetails.get("STRAND").toString()) == null) - { - return 0; - } - if (str.equals("-")) - { - return -1; - } - if (str.equals("+")) + int strand = 0; + if (otherDetails != null) { - return 1; + Object str = otherDetails.get("STRAND"); + if ("-".equals(str)) + { + strand = -1; + } + else if ("+".equals(str)) + { + strand = 1; + } } - return 0; + return strand; } } diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java index 7debb0b..d488a76 100644 --- a/test/jalview/datamodel/SequenceFeatureTest.java +++ b/test/jalview/datamodel/SequenceFeatureTest.java @@ -45,4 +45,21 @@ public class SequenceFeatureTest Integer i = new Integer(27); assertSame(i, sf1.getValue("Unknown", i)); } + + /** + * Tests the method that returns 1 / -1 / 0 for strand "+" / "-" / other + */ + @Test(groups = { "Functional" }) + public void testGetStrand() + { + SequenceFeature sf = new SequenceFeature("type", "desc", 22, 33, 12.5f, + "group"); + assertEquals(0, sf.getStrand()); + sf.setValue("STRAND", "+"); + assertEquals(1, sf.getStrand()); + sf.setValue("STRAND", "-"); + assertEquals(-1, sf.getStrand()); + sf.setValue("STRAND", "."); + assertEquals(0, sf.getStrand()); + } } -- 1.7.10.2