Merge branch 'features/pca_jaxb_datasetrefs_JAL-3171_JAL-3063_JAL-1767' into develop
[jalview.git] / src / jalview / datamodel / features / FeatureStore.java
index 51bee57..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;
@@ -1027,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
@@ -1043,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;
   }