JAL-3397 final update
[jalview.git] / src / jalview / datamodel / features / FeatureStoreImpl.java
index d1d2670..63ee678 100644 (file)
@@ -25,9 +25,7 @@ import jalview.datamodel.SequenceFeature;
 import java.util.ArrayList;
 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
@@ -42,7 +40,12 @@ public class FeatureStoreImpl extends FeatureStore
 
   public FeatureStoreImpl()
   {
-    features = new IntervalStore<>();
+    super();
+  }
+
+  public FeatureStoreImpl(int option)
+  {
+    super(option);
   }
 
   /**
@@ -67,7 +70,7 @@ public class FeatureStoreImpl extends FeatureStore
      * insert into list sorted by start (first contact position):
      * binary search the sorted list to find the insertion point
      */
-    int insertPosition = findFirstBeginStatic(contactFeatureStarts,
+    int insertPosition = findFirstBegin(contactFeatureStarts,
             feature.getBegin());
     contactFeatureStarts.add(insertPosition, feature);
 
@@ -75,7 +78,7 @@ public class FeatureStoreImpl extends FeatureStore
      * insert into list sorted by end (second contact position):
      * binary search the sorted list to find the insertion point
      */
-    insertPosition = findFirstEndStatic(contactFeatureEnds,
+    insertPosition = findFirstEnd(contactFeatureEnds,
             feature.getEnd());
     contactFeatureEnds.add(insertPosition, feature);
 
@@ -83,6 +86,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 +115,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
@@ -118,7 +138,7 @@ public class FeatureStoreImpl extends FeatureStore
      * find the first contact feature (if any) 
      * whose end point is not before the target range
      */
-    int index = findFirstEndStatic(contactFeatureEnds, from);
+    int index = findFirstEnd(contactFeatureEnds, from);
 
     int n = contactFeatureEnds.size();
     while (index < n)
@@ -228,32 +248,27 @@ public class FeatureStoreImpl extends FeatureStore
   private void findOverlaps(long start, long end,
           List<SequenceFeature> result)
   {
-    result.addAll(((IntervalStoreI<SequenceFeature>) features)
+    result.addAll(features
             .findOverlaps(start, end));
   }
 
   @Override
   protected int findFirstBegin(List<SequenceFeature> list, long pos)
   {
-    return findFirstBeginStatic(list, pos);
-  }
-
-  private static int findFirstBeginStatic(List<SequenceFeature> list,
-          long pos)
-  {
-    return BinarySearcher.findFirst(list, f -> f.getBegin() >= pos);
+    return BinarySearcher.findFirst(list, (int) pos,
+            BinarySearcher.fbegin);
   }
 
   @Override
   protected int findFirstEnd(List<SequenceFeature> list, long pos)
   {
-    return findFirstEndStatic(list, pos);
+    return BinarySearcher.findFirst(list, (int) pos, BinarySearcher.fend);
   }
 
-  private static int findFirstEndStatic(List<SequenceFeature> list,
-          long pos)
+  @Override
+  protected boolean findAndRemoveNonContactFeature(SequenceFeature sf)
   {
-    return BinarySearcher.findFirst(list, f -> f.getEnd() >= pos);
+    return features.remove(sf);
   }
 
 }