JAL-3253-applet JAL-3397 JAL-3383 fast IntervalStore for JavaScript
[jalview.git] / src / jalview / datamodel / features / FeatureStoreImpl.java
index a41633a..a90755d 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 
 import intervalstore.api.IntervalStoreI;
 import intervalstore.impl.BinarySearcher;
-import intervalstore.impl.IntervalStore;
 
 /**
  * A data store for a set of sequence features that supports efficient lookup of
@@ -40,9 +39,18 @@ import intervalstore.impl.IntervalStore;
 public class FeatureStoreImpl extends FeatureStore
 {
 
+  /**
+   * Default constructor uses NCList
+   */
   public FeatureStoreImpl()
   {
-    features = new IntervalStore<>();
+    this(true);
+  }
+
+  public FeatureStoreImpl(boolean useNCList)
+  {
+    features = (useNCList ? new intervalstore.impl.IntervalStore<>()
+            : new intervalstore.nonc.IntervalStore<>(false));
   }
 
   /**
@@ -83,6 +91,17 @@ public class FeatureStoreImpl extends FeatureStore
   }
 
   /**
+   * Adds one feature to the IntervalStore that can manage nested features
+   * (creating the IntervalStore if necessary)
+   */
+  @Override
+  protected synchronized boolean addPositionalFeature(
+          SequenceFeature feature)
+  {
+    return features.add(feature);
+  }
+
+  /**
    * Adds contact features to the result list where either the second or the
    * first contact position lies within the target range
    * 
@@ -101,6 +120,12 @@ public class FeatureStoreImpl extends FeatureStore
     }
   }
 
+  @Override
+  protected boolean containsFeature(SequenceFeature feature)
+  {
+    return features.contains(feature);
+  }
+
   /**
    * Adds to the result list any contact features whose end (second contact
    * point), but not start (first contact point), lies in the query from-to
@@ -270,4 +295,10 @@ public class FeatureStoreImpl extends FeatureStore
     return BinarySearcher.findFirst(list, f -> f.getEnd() >= pos);
   }
 
+  @Override
+  protected boolean findAndRemoveNonContactFeature(SequenceFeature sf)
+  {
+    return features.remove(sf);
+  }
+
 }