JAL-3383 JAL-3253-applet
[jalview.git] / src / jalview / datamodel / features / FeatureStoreJS.java
index 295d7a0..3afbfb2 100644 (file)
@@ -48,6 +48,30 @@ public class FeatureStoreJS extends FeatureStore
   }
 
   /**
+   * Add a contact feature to the lists that hold them ordered by start (first
+   * contact) and by end (second contact) position, ensuring the lists remain
+   * ordered, and returns true. This method allows duplicate features to be
+   * added, so test before calling to avoid this.
+   * 
+   * @param feature
+   * @return
+   */
+  @Override
+  protected synchronized boolean addContactFeature(SequenceFeature feature)
+  {
+    if (contactFeatureStarts == null)
+    {
+      contactFeatureStarts = new ArrayList<>();
+      contactFeatureEnds = new ArrayList<>();
+    }
+    contactFeatureStarts.add(
+            findFirstBegin(contactFeatureStarts, feature.begin), feature);
+    contactFeatureEnds.add(findFirstEnd(contactFeatureEnds, feature.end),
+            feature);
+    return true;
+  }
+
+  /**
    * Returns a (possibly empty) list of features whose extent overlaps the given
    * range. The returned list is not ordered. Contact features are included if
    * either of the contact points lies within the range.
@@ -451,7 +475,8 @@ public class FeatureStoreJS extends FeatureStore
     }
   }
 
-  public static int findFirstBegin(List<SequenceFeature> list, long pos)
+  @Override
+  protected int findFirstBegin(List<SequenceFeature> list, long pos)
   {
     int start = 0;
     int end = list.size() - 1;
@@ -473,7 +498,8 @@ public class FeatureStoreJS extends FeatureStore
     return matched;
   }
 
-  public static int findFirstEnd(List<SequenceFeature> list, long pos)
+  @Override
+  protected int findFirstEnd(List<SequenceFeature> list, long pos)
   {
     int start = 0;
     int end = list.size() - 1;