JAL-2446 added delete/contains to pseudo-random tests, fail fixes
[jalview.git] / src / jalview / datamodel / features / NCList.java
index 17e08eb..9906884 100644 (file)
@@ -99,6 +99,11 @@ public class NCList<T extends ContiguousI>
   {
     List<SubList> sublists = new ArrayList<SubList>();
     
+    if (ranges.isEmpty())
+    {
+      return sublists;
+    }
+
     int listStartIndex = 0;
     long lastEndPos = Long.MAX_VALUE;
 
@@ -188,7 +193,7 @@ public class NCList<T extends ContiguousI>
     {
       NCNode<T> subrange = subranges.get(j);
 
-      if (end < subrange.getStart() && !overlapping && !enclosing)
+      if (end < subrange.getBegin() && !overlapping && !enclosing)
       {
         /*
          * new entry lies between subranges j-1 j
@@ -197,7 +202,7 @@ public class NCList<T extends ContiguousI>
         return true;
       }
 
-      if (subrange.getStart() <= start && subrange.getEnd() >= end)
+      if (subrange.getBegin() <= start && subrange.getEnd() >= end)
       {
         /*
          * push new entry inside this subrange as it encloses it
@@ -206,7 +211,7 @@ public class NCList<T extends ContiguousI>
         return true;
       }
       
-      if (start <= subrange.getStart())
+      if (start <= subrange.getBegin())
       {
         if (end >= subrange.getEnd())
         {
@@ -293,7 +298,7 @@ public class NCList<T extends ContiguousI>
     for (int i = candidateIndex; i < subranges.size(); i++)
     {
       NCNode<T> candidate = subranges.get(i);
-      if (candidate.getStart() > to)
+      if (candidate.getBegin() > to)
       {
         /*
          * we are past the end of our target range
@@ -373,7 +378,7 @@ public class NCList<T extends ContiguousI>
     for (int i = candidateIndex; i < subranges.size(); i++)
     {
       NCNode<T> candidate = subranges.get(i);
-      if (candidate.getStart() > to)
+      if (candidate.getBegin() > to)
       {
         /*
          * we are past the end of our target range
@@ -427,7 +432,7 @@ public class NCList<T extends ContiguousI>
   }
 
   /**
-   * Returns a string representation of the data where containment is shown bgy
+   * Returns a string representation of the data where containment is shown by
    * indentation on new lines
    * 
    * @return
@@ -438,6 +443,7 @@ public class NCList<T extends ContiguousI>
     int offset = 0;
     int indent = 2;
     prettyPrint(sb, offset, indent);
+    sb.append(System.lineSeparator());
     return sb.toString();
   }
 
@@ -488,7 +494,7 @@ public class NCList<T extends ContiguousI>
     int lastStart = start;
     for (NCNode<T> subrange : subranges)
     {
-      if (subrange.getStart() < lastStart)
+      if (subrange.getBegin() < lastStart)
       {
         System.err.println("error in NCList: range " + subrange.toString()
                 + " starts before " + lastStart);
@@ -500,7 +506,7 @@ public class NCList<T extends ContiguousI>
                 + " ends after " + end);
         return false;
       }
-      lastStart = subrange.getStart();
+      lastStart = subrange.getBegin();
 
       if (!subrange.isValid())
       {
@@ -517,7 +523,7 @@ public class NCList<T extends ContiguousI>
    */
   public int getStart()
   {
-    return subranges.isEmpty() ? 0 : subranges.get(0).getStart();
+    return subranges.isEmpty() ? 0 : subranges.get(0).getBegin();
   }
 
   /**
@@ -579,12 +585,17 @@ public class NCList<T extends ContiguousI>
       {
         /*
          * if the subrange is rooted on this entry, promote its
-         * subregions (if any) to replace the subrange here 
+         * subregions (if any) to replace the subrange here;
+         * NB have to resort subranges after doing this since e.g.
+         * [10-30 [12-20 [16-18], 13-19]]
+         * after deleting 12-20, 16-18 is promoted to sibling of 13-19
+         * but should follow it in the list of subranges of 10-30 
          */
         subranges.remove(i);
         if (subRegions != null)
         {
           subranges.addAll(i, subRegions.subranges);
+          Collections.sort(subranges, intervalSorter);
         }
         size--;
         return true;
@@ -600,24 +611,4 @@ public class NCList<T extends ContiguousI>
     }
     return false;
   }
-
-  /**
-   * Answers true if this contains no ranges
-   * 
-   * @return
-   */
-  public boolean isEmpty()
-  {
-    return getSize() == 0;
-  }
-
-  /**
-   * Answer the list of subranges held in this NCList
-   * 
-   * @return
-   */
-  List<NCNode<T>> getSubregions()
-  {
-    return subranges;
-  }
 }