JAL-3383 JAL-3397 JAL-3253-applet IntervalStore options
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index 8a6cb61..a71c7b1 100755 (executable)
@@ -27,12 +27,16 @@ import jalview.datamodel.features.FeatureSourceI;
 import jalview.datamodel.features.FeatureSources;
 import jalview.util.StringUtils;
 
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
 
+import intervalstore.api.IntervalI;
+
 /**
  * A class that models a single contiguous feature on a sequence. If flag
  * 'contactFeature' is true, the start and end positions are interpreted instead
@@ -98,6 +102,16 @@ public class SequenceFeature implements FeatureLocationI
   private String source;
 
   /**
+   * 1-based index into the featureList used by FeatureStoreJS
+   */
+  public int index1;
+
+  /**
+   * containment nesting link used by FeatureStoreJS to track starting points
+   */
+  public SequenceFeature containedBy;
+
+  /**
    * Constructs a duplicate feature. Note: Uses makes a shallow copy of the
    * otherDetails map, so the new and original SequenceFeature may reference the
    * same objects in the map.
@@ -643,9 +657,13 @@ public class SequenceFeature implements FeatureLocationI
         {
           /*
            * expand values in a Map attribute across separate lines
+           * copy to a TreeMap for alphabetical ordering
            */
-          Map<?, ?> values = (Map<?, ?>) value;
-          for (Entry<?, ?> e : values.entrySet())
+          Map<String, Object> values = (Map<String, Object>) value;
+          SortedMap<String, Object> sm = new TreeMap<>(
+                  String.CASE_INSENSITIVE_ORDER);
+          sm.putAll(values);
+          for (Entry<?, ?> e : sm.entrySet())
           {
             sb.append(String.format(ROW_DATA, key, e.getKey().toString(), e
                     .getValue().toString()));
@@ -730,4 +748,36 @@ public class SequenceFeature implements FeatureLocationI
   {
     source = theSource;
   }
+
+  @Override
+  public IntervalI getContainedBy()
+  {
+    return containedBy;
+  }
+
+  @Override
+  public void setContainedBy(IntervalI containedBy)
+  {
+    this.containedBy = (SequenceFeature) containedBy;
+
+  }
+
+}
+
+class SFSortByEnd implements Comparator<SequenceFeature>
+{
+  @Override
+  public int compare(SequenceFeature a, SequenceFeature b)
+  {
+    return a.getEnd() - b.getEnd();
+  }
+}
+
+class SFSortByBegin implements Comparator<SequenceFeature>
+{
+  @Override
+  public int compare(SequenceFeature a, SequenceFeature b)
+  {
+    return a.getBegin() - b.getBegin();
+  }
 }