Merge branch 'features/pca_jaxb_datasetrefs_JAL-3171_JAL-3063_JAL-1767' into develop
[jalview.git] / src / jalview / datamodel / features / FeatureStore.java
index b082b56..951b7a5 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.datamodel.features;
 
 import jalview.datamodel.ContiguousI;
@@ -54,7 +74,7 @@ public class FeatureStore
 
     /**
      * serves a search condition for finding the first feature whose end
-     * position follows a given target location
+     * position is at or follows a given target location
      * 
      * @param target
      * @return
@@ -596,28 +616,15 @@ public class FeatureStore
   protected void findNonNestedFeatures(long from, long to,
           List<SequenceFeature> result)
   {
+    /*
+     * find the first feature whose end position is
+     * after the target range start
+     */
     int startIndex = binarySearch(nonNestedFeatures,
             SearchCriterion.byEnd(from));
 
-    findNonNestedFeatures(startIndex, from, to, result);
-  }
-
-  /**
-   * Scans the list of non-nested features, starting from startIndex, to find
-   * those that overlap the from-to range, and adds them to the result list.
-   * Returns the index of the first feature whose start position is after the
-   * target range (or the length of the whole list if no such feature exists).
-   * 
-   * @param startIndex
-   * @param from
-   * @param to
-   * @param result
-   * @return
-   */
-  protected int findNonNestedFeatures(final int startIndex, long from,
-          long to, List<SequenceFeature> result)
-  {
-    int i = startIndex;
+    final int startIndex1 = startIndex;
+    int i = startIndex1;
     while (i < nonNestedFeatures.size())
     {
       SequenceFeature sf = nonNestedFeatures.get(i);
@@ -631,7 +638,6 @@ public class FeatureStore
       }
       i++;
     }
-    return i;
   }
 
   /**
@@ -1041,13 +1047,15 @@ public class FeatureStore
   }
 
   /**
-   * Adds the shift value to the start and end of all positional features.
-   * Returns true if at least one feature was updated, else false.
+   * Adds the shift amount to the start and end of all positional features whose
+   * start position is at or after fromPosition. Returns true if at least one
+   * feature was shifted, else false.
    * 
-   * @param shift
+   * @param fromPosition
+   * @param shiftBy
    * @return
    */
-  public synchronized boolean shiftFeatures(int shift)
+  public synchronized boolean shiftFeatures(int fromPosition, int shiftBy)
   {
     /*
      * Because begin and end are final fields (to ensure the data store's
@@ -1057,21 +1065,24 @@ public class FeatureStore
     boolean modified = false;
     for (SequenceFeature sf : getPositionalFeatures())
     {
-      modified = true;
-      int newBegin = sf.getBegin() + shift;
-      int newEnd = sf.getEnd() + shift;
-
-      /*
-       * sanity check: don't shift left of the first residue
-       */
-      if (newEnd > 0)
+      if (sf.getBegin() >= fromPosition)
       {
-        newBegin = Math.max(1, newBegin);
-        SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
-                sf.getFeatureGroup(), sf.getScore());
-        addFeature(sf2);
+        modified = true;
+        int newBegin = sf.getBegin() + shiftBy;
+        int newEnd = sf.getEnd() + shiftBy;
+
+        /*
+         * sanity check: don't shift left of the first residue
+         */
+        if (newEnd > 0)
+        {
+          newBegin = Math.max(1, newBegin);
+          SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd,
+                  sf.getFeatureGroup(), sf.getScore());
+          addFeature(sf2);
+        }
+        delete(sf);
       }
-      delete(sf);
     }
     return modified;
   }