JAL-2446 promote Range from test to src to replace SubList
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 17 Apr 2017 14:12:29 +0000 (15:12 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 17 Apr 2017 14:12:29 +0000 (15:12 +0100)
src/jalview/datamodel/features/NCList.java
src/jalview/datamodel/features/Range.java [moved from test/jalview/datamodel/features/Range.java with 74% similarity]
src/jalview/datamodel/features/SubList.java [deleted file]
test/jalview/datamodel/features/NCListTest.java
test/jalview/datamodel/features/NCNodeTest.java

index afa31e8..6471e42 100644 (file)
@@ -63,16 +63,16 @@ public class NCList<T extends ContiguousI>
      */
     Collections.sort(ranges, intervalSorter);
 
-    List<SubList> sublists = buildSubranges(ranges);
+    List<Range> sublists = buildSubranges(ranges);
 
     /*
      * convert each subrange to an NCNode consisting of a range and
      * (possibly) its contained NCList
      */
-    for (SubList sublist : sublists)
+    for (Range sublist : sublists)
     {
-      subranges.add(new NCNode<T>(ranges.subList(sublist.startIndex,
-              sublist.endIndex + 1)));
+      subranges.add(new NCNode<T>(ranges.subList(sublist.start,
+              sublist.end + 1)));
     }
 
     size = ranges.size();
@@ -97,9 +97,9 @@ public class NCList<T extends ContiguousI>
    * @param ranges
    * @return
    */
-  protected List<SubList> buildSubranges(List<T> ranges)
+  protected List<Range> buildSubranges(List<T> ranges)
   {
-    List<SubList> sublists = new ArrayList<SubList>();
+    List<Range> sublists = new ArrayList<Range>();
     
     if (ranges.isEmpty())
     {
@@ -120,13 +120,13 @@ public class NCList<T extends ContiguousI>
          * this interval is not contained in the preceding one 
          * close off the last sublist
          */
-        sublists.add(new SubList(listStartIndex, i - 1));
+        sublists.add(new Range(listStartIndex, i - 1));
         listStartIndex = i;
       }
       lastEndPos = nextEnd;
     }
 
-    sublists.add(new SubList(listStartIndex, ranges.size() - 1));
+    sublists.add(new Range(listStartIndex, ranges.size() - 1));
     return sublists;
   }
 
similarity index 74%
rename from test/jalview/datamodel/features/Range.java
rename to src/jalview/datamodel/features/Range.java
index 701ec2a..beb2874 100644 (file)
@@ -1,10 +1,11 @@
 package jalview.datamodel.features;
 
-class Range implements ContiguousI
+
+public class Range implements ContiguousI
 {
-  int start;
+  final int start;
 
-  int end;
+  final int end;
 
   @Override
   public int getBegin()
@@ -18,7 +19,7 @@ class Range implements ContiguousI
     return end;
   }
 
-  Range(int i, int j)
+  public Range(int i, int j)
   {
     start = i;
     end = j;
diff --git a/src/jalview/datamodel/features/SubList.java b/src/jalview/datamodel/features/SubList.java
deleted file mode 100644 (file)
index ace0240..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-package jalview.datamodel.features;
-
-/**
- * SubList holds the start and end index of a run of intervals where each is
- * contained by (or the same as) the one preceding it.
- * <p>
- * SubList is used during the construction of an NCList
- */
-class SubList
-{
-  /*
-   * the index of the sublist's first interval in the 'intervals' list
-   */
-  int startIndex;
-
-  /*
-   * the index of the sublist's last interval in the 'intervals' list
-   */
-  int endIndex;
-
-  SubList(int from, int to)
-  {
-    startIndex = from;
-    endIndex = to;
-  }
-
-}
\ No newline at end of file
index 65c8c91..3561a78 100644 (file)
@@ -12,6 +12,8 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Random;
 
+import junit.extensions.PA;
+
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -212,20 +214,20 @@ public class NCListTest
       assertEquals(ncl.size(), features.size());
       int toDelete = random.nextInt(features.size());
       SequenceFeature entry = features.get(toDelete);
-      String lastDeleted = "'" + entry.toString() + "'";
       assertTrue(ncl.contains(entry), String.format(
-              "NCList doesn't contain entry [%d] %s!", deleted,
-              lastDeleted));
+              "NCList doesn't contain entry [%d] '%s'!", deleted,
+              entry.toString()));
+
       ncl.delete(entry);
       assertFalse(ncl.contains(entry), String.format(
-              "NCList still contains deleted entry [%d] %s!", deleted,
-              lastDeleted));
+              "NCList still contains deleted entry [%d] '%s'!", deleted,
+              entry.toString()));
       features.remove(toDelete);
       deleted++;
 
       assertTrue(ncl.isValid(), String.format(
-              "NCList invalid after %d deletions, last deleted was %s",
-              deleted, lastDeleted));
+              "NCList invalid after %d deletions, last deleted was '%s'",
+              deleted, entry.toString()));
 
       /*
        * brute force check that deleting one entry didn't delete any others
@@ -234,8 +236,8 @@ public class NCListTest
       {
         SequenceFeature sf = features.get(i);
         assertTrue(ncl.contains(sf), String.format(
-                "NCList doesn't contain entry [%d] %s after deleting %s!",
-                i, sf.toString(), lastDeleted));
+                        "NCList doesn't contain entry [%d] %s after deleting '%s'!",
+                        i, sf.toString(), entry.toString()));
       }
     }
     assertEquals(ncl.size(), 0); // all gone
@@ -584,22 +586,22 @@ public class NCListTest
     assertEquals(ncl.toString(), "[40-50 [42-44 [43-43], 46-48]]");
     assertTrue(ncl.isValid());
 
-    r1.start = 43;
+    PA.setValue(r1, "start", 43);
     assertFalse(ncl.isValid()); // r2 not inside r1
-    r1.start = 40;
+    PA.setValue(r1, "start", 40);
     assertTrue(ncl.isValid());
 
-    r3.start = 41;
+    PA.setValue(r3, "start", 41);
     assertFalse(ncl.isValid()); // r3 should precede r2
-    r3.start = 46;
+    PA.setValue(r3, "start", 46);
     assertTrue(ncl.isValid());
 
-    r4.start = 41;
+    PA.setValue(r4, "start", 41);
     assertFalse(ncl.isValid()); // r4 not inside r2
-    r4.start = 43;
+    PA.setValue(r4, "start", 43);
     assertTrue(ncl.isValid());
 
-    r4.start = 44;
+    PA.setValue(r4, "start", 44);
     assertFalse(ncl.isValid()); // r4 has reverse range
   }
 
index 4198fec..ca227c5 100644 (file)
@@ -9,6 +9,8 @@ import jalview.datamodel.SequenceFeature;
 import java.util.ArrayList;
 import java.util.List;
 
+import junit.extensions.PA;
+
 import org.testng.annotations.Test;
 
 public class NCNodeTest
@@ -119,16 +121,15 @@ public class NCNodeTest
      * NCList of [14-15, 16-17]
      */
     assertTrue(node.isValid());
-    r1.start = 15;
+    PA.setValue(r1, "start", 15);
     assertFalse(node.isValid()); // r2 not within r1
-    r1.start = 10;
+    PA.setValue(r1, "start", 10);
     assertTrue(node.isValid());
-    r1.end = 16;
+    PA.setValue(r1, "end", 16);
     assertFalse(node.isValid()); // r3 not within r1
-    r1.end = 20;
+    PA.setValue(r1, "end", 20);
     assertTrue(node.isValid());
-    r3.start = 12;
+    PA.setValue(r3, "start", 12);
     assertFalse(node.isValid()); // r3 should precede r2
-
   }
 }