JAL-653 getStrand javadoc/refactor/test
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 30 Nov 2015 09:27:47 +0000 (09:27 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 30 Nov 2015 09:27:47 +0000 (09:27 +0000)
src/jalview/datamodel/SequenceFeature.java
test/jalview/datamodel/SequenceFeatureTest.java

index 5fadb6f..e60e0c8 100755 (executable)
@@ -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;
   }
 
 }
index 7debb0b..d488a76 100644 (file)
@@ -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());
+  }
 }