JAL-2505 make SequenceFeature type, begin, end, featureGroup final
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index 719cf52..627e1ae 100755 (executable)
@@ -50,13 +50,20 @@ public class SequenceFeature implements FeatureLocationI
    */
   private static final String ATTRIBUTES = "ATTRIBUTES";
 
-  public int begin;
+  /*
+   * type, begin, end, featureGroup are final to ensure that
+   * the integrity of SequenceFeatures data store can't be
+   * broken by direct update of these fields
+   */
+  public final String type;
 
-  public int end;
+  public final int begin;
 
-  public float score;
+  public final int end;
 
-  public String type;
+  public final String featureGroup;
+
+  public float score;
 
   public String description;
 
@@ -68,14 +75,6 @@ public class SequenceFeature implements FeatureLocationI
 
   public Vector<String> links;
 
-  // Feature group can be set from a features file
-  // as a group of features between STARTGROUP and ENDGROUP markers
-  public String featureGroup;
-
-  public SequenceFeature()
-  {
-  }
-
   /**
    * Constructs a duplicate feature. Note: Uses makes a shallow copy of the
    * otherDetails map, so the new and original SequenceFeature may reference the
@@ -85,41 +84,27 @@ public class SequenceFeature implements FeatureLocationI
    */
   public SequenceFeature(SequenceFeature cpy)
   {
-    if (cpy != null)
+    this(cpy, cpy.getBegin(), cpy.getEnd(), cpy.getFeatureGroup());
+
+    score = cpy.score;
+    description = cpy.description;
+    if (cpy.otherDetails != null)
     {
-      begin = cpy.begin;
-      end = cpy.end;
-      score = cpy.score;
-      if (cpy.type != null)
+      try
       {
-        type = new String(cpy.type);
-      }
-      if (cpy.description != null)
+        otherDetails = (Map<String, Object>) ((HashMap<String, Object>) cpy.otherDetails)
+                .clone();
+      } catch (Exception e)
       {
-        description = new String(cpy.description);
+        // ignore
       }
-      if (cpy.featureGroup != null)
-      {
-        featureGroup = new String(cpy.featureGroup);
-      }
-      if (cpy.otherDetails != null)
-      {
-        try
-        {
-          otherDetails = (Map<String, Object>) ((HashMap<String, Object>) cpy.otherDetails)
-                  .clone();
-        } catch (Exception e)
-        {
-          // ignore
-        }
-      }
-      if (cpy.links != null && cpy.links.size() > 0)
+    }
+    if (cpy.links != null && cpy.links.size() > 0)
+    {
+      links = new Vector<String>();
+      for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)
       {
-        links = new Vector<String>();
-        for (int i = 0, iSize = cpy.links.size(); i < iSize; i++)
-        {
-          links.addElement(cpy.links.elementAt(i));
-        }
+        links.addElement(cpy.links.elementAt(i));
       }
     }
   }
@@ -189,10 +174,24 @@ public class SequenceFeature implements FeatureLocationI
   public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd,
           String newGroup)
   {
-    this(sf);
-    begin = newBegin;
-    end = newEnd;
-    featureGroup = newGroup;
+    this(sf.getType(), newBegin, newEnd, newGroup);
+  }
+
+  /**
+   * Constructor that sets the final fields type, begin, end, group
+   * 
+   * @param theType
+   * @param theBegin
+   * @param theEnd
+   * @param theGroup
+   */
+  private SequenceFeature(String theType, int theBegin, int theEnd,
+          String theGroup)
+  {
+    type = theType;
+    begin = theBegin;
+    end = theEnd;
+    featureGroup = theGroup;
   }
 
   /**
@@ -294,11 +293,6 @@ public class SequenceFeature implements FeatureLocationI
     return begin;
   }
 
-  public void setBegin(int start)
-  {
-    this.begin = start;
-  }
-
   /**
    * DOCUMENT ME!
    * 
@@ -310,11 +304,6 @@ public class SequenceFeature implements FeatureLocationI
     return end;
   }
 
-  public void setEnd(int end)
-  {
-    this.end = end;
-  }
-
   /**
    * DOCUMENT ME!
    * 
@@ -325,11 +314,6 @@ public class SequenceFeature implements FeatureLocationI
     return type;
   }
 
-  public void setType(String type)
-  {
-    this.type = type;
-  }
-
   /**
    * DOCUMENT ME!
    * 
@@ -350,11 +334,6 @@ public class SequenceFeature implements FeatureLocationI
     return featureGroup;
   }
 
-  public void setFeatureGroup(String featureGroup)
-  {
-    this.featureGroup = featureGroup;
-  }
-
   public void addLink(String labelLink)
   {
     if (links == null)
@@ -457,17 +436,6 @@ public class SequenceFeature implements FeatureLocationI
     return (String) getValue(ATTRIBUTES);
   }
 
-  public void setPosition(int pos)
-  {
-    begin = pos;
-    end = pos;
-  }
-
-  public int getPosition()
-  {
-    return begin;
-  }
-
   /**
    * Return 1 for forward strand ('+' in GFF), -1 for reverse strand ('-' in
    * GFF), and 0 for unknown or not (validly) specified