JAL-2490 performant findFeaturesAtRes
[jalview.git] / src / jalview / datamodel / Sequence.java
index 5a3ffa4..af6592b 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.datamodel;
 import jalview.analysis.AlignSeq;
 import jalview.api.DBRefEntryI;
 import jalview.datamodel.features.SequenceFeatures;
+import jalview.datamodel.features.SequenceFeaturesI;
 import jalview.util.Comparison;
 import jalview.util.DBRefUtils;
 import jalview.util.MapList;
@@ -320,6 +321,13 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public synchronized boolean addSequenceFeature(SequenceFeature sf)
   {
+    if (sf.getType() == null)
+    {
+      System.err.println("SequenceFeature type may not be null: "
+              + sf.toString());
+      return false;
+    }
+
     if (sequenceFeatures == null && datasetSequence != null)
     {
       return datasetSequence.addSequenceFeature(sf);
@@ -359,6 +367,14 @@ public class Sequence extends ASequence implements SequenceI
       return;
     }
 
+    /*
+     * new way
+     */
+    sequenceFeatureStore.delete(sf);
+
+    /*
+     * old way - to be removed
+     */
     int index = 0;
     for (index = 0; index < sequenceFeatures.length; index++)
     {
@@ -418,6 +434,13 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   @Override
+  public SequenceFeaturesI getFeatures()
+  {
+    return datasetSequence != null ? datasetSequence.getFeatures()
+            : sequenceFeatureStore;
+  }
+
+  @Override
   public boolean addPDBId(PDBEntry entry)
   {
     if (pdbIds == null)
@@ -1162,6 +1185,8 @@ public class Sequence extends ASequence implements SequenceI
       // move features and database references onto dataset sequence
       dsseq.sequenceFeatures = sequenceFeatures;
       sequenceFeatures = null;
+      dsseq.sequenceFeatureStore = sequenceFeatureStore;
+      sequenceFeatureStore = null;
       dsseq.dbrefs = dbrefs;
       dbrefs = null;
       // TODO: search and replace any references to this sequence with
@@ -1481,13 +1506,17 @@ public class Sequence extends ASequence implements SequenceI
     }
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
-  public List<SequenceFeature> findFeatures(String type, int from, int to)
+  public List<SequenceFeature> findFeatures(int from, int to,
+          String... types)
   {
     if (datasetSequence != null)
     {
-      return datasetSequence.findFeatures(type, from, to);
+      return datasetSequence.findFeatures(from, to, types);
     }
-    return sequenceFeatureStore.findFeatures(type, from, to);
+    return sequenceFeatureStore.findFeatures(from, to, types);
   }
 }