JAL-3253-applet no-NCList IntervalStore fixes
[jalview.git] / src / jalview / datamodel / features / FeatureStoreJS.java
index dbf1413..4f49360 100644 (file)
@@ -244,8 +244,8 @@ public class FeatureStoreJS extends FeatureStore
     {
       if (start == end)
       {
-        getContactPoints(contactFeatureStarts, start, result, true);
-        getContactPoints(contactFeatureEnds, start, result, false);
+        getContactPointStarts(contactFeatureStarts, start, result);
+        getContactPointEnds(contactFeatureEnds, end, result);
       }
       else
       {
@@ -309,8 +309,8 @@ public class FeatureStoreJS extends FeatureStore
    * 
    * @author Bob Hanson 2019.07.30
    */
-  private void getContactPoints(List<SequenceFeature> l, long pos,
-          List<SequenceFeature> result, boolean isStart)
+  private void getContactPointStarts(List<SequenceFeature> l, long pos,
+          List<SequenceFeature> result)
   {
     int low = 0;
     int high = l.size() - 1;
@@ -318,7 +318,7 @@ public class FeatureStoreJS extends FeatureStore
     {
       int mid = (low + high) >>> 1;
       SequenceFeature f = l.get(mid);
-      switch (Long.signum((isStart ? f.begin : f.end) - pos))
+      switch (Long.signum(f.begin - pos))
       {
       case -1:
         low = mid + 1;
@@ -330,13 +330,11 @@ public class FeatureStoreJS extends FeatureStore
         int m = mid;
         result.add(f);
         // could be "5" in 12345556788 ?
-        while (++mid <= high && (f = l.get(mid)) != null
-                && (isStart ? f.begin : f.end) == pos)
+        while (++mid <= high && (f = l.get(mid)) != null && f.begin == pos)
         {
           result.add(f);
         }
-        while (--m >= low && (f = l.get(m)) != null
-                && (isStart ? f.begin : f.end) == pos)
+        while (--m >= low && (f = l.get(m)) != null && f.begin == pos)
         {
           result.add(f);
         }
@@ -345,6 +343,51 @@ public class FeatureStoreJS extends FeatureStore
     }
   }
 
+  private void getContactPointEnds(List<SequenceFeature> l, long pos,
+          List<SequenceFeature> result)
+  {
+    int low = 0;
+    int high = l.size() - 1;
+    while (low <= high)
+    {
+      int mid = (low + high) >>> 1;
+      SequenceFeature f = l.get(mid);
+      switch (Long.signum(f.end - pos))
+      {
+      case -1:
+        low = mid + 1;
+        continue;
+      case 1:
+        high = mid - 1;
+        continue;
+      case 0:
+        int m = mid;
+        if (f.begin != f.end)
+        {
+          result.add(f);
+        }
+        // could be "5" in 12345556788 ?
+        while (++mid <= high && (f = l.get(mid)) != null
+                && f.end == pos)
+        {
+          if (f.begin != f.end)
+          {
+            result.add(f);
+          }
+        }
+        while (--m >= low && (f = l.get(m)) != null
+                && f.end == pos)
+        {
+          if (f.begin != f.end)
+          {
+            result.add(f);
+          }
+        }
+        return;
+      }
+    }
+  }
+
   /**
    * Adds contact features whose start position lies in the from-to range to the
    * result list