formatting
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index 3d8744f..14ce0ff 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -18,7 +18,9 @@
  */\r
 package jalview.datamodel;\r
 \r
+import java.util.Enumeration;\r
 import java.util.Hashtable;\r
+import java.util.Vector;\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -33,7 +35,7 @@ public class SequenceFeature
     public float score;\r
     public String type;\r
     public String description;\r
-    Hashtable otherDetails;\r
+    public Hashtable otherDetails;\r
     public java.util.Vector links;\r
 \r
     // Feature group can be set from a features file\r
@@ -42,7 +44,39 @@ public class SequenceFeature
 \r
     public SequenceFeature()\r
     {}\r
-\r
+    /**\r
+     * Constructs a duplicate feature.\r
+     * Note: Uses clone on the otherDetails so only shallow copies are made\r
+     * of additional properties and method will silently fail if unclonable\r
+     * objects are found in the hash.\r
+     * @param cpy\r
+     */\r
+    public SequenceFeature(SequenceFeature cpy) {\r
+        if (cpy!=null) {\r
+            begin = cpy.begin;\r
+            end = cpy.end;\r
+            score = cpy.score;\r
+            if (cpy.type != null)\r
+              type = new String(cpy.type);\r
+            if (cpy.description != null)\r
+              description = new String(cpy.description);\r
+            if (cpy.featureGroup != null)\r
+              featureGroup = new String(cpy.featureGroup);\r
+            if (cpy.otherDetails!=null) {\r
+                try {\r
+                    otherDetails = (Hashtable) cpy.otherDetails.clone();\r
+                } catch (Exception e) {\r
+                    // Uncloneable objects in the otherDetails - don't complain\r
+                }\r
+            }\r
+            if (cpy.links!=null && cpy.links.size()>0) {\r
+                links=new Vector();\r
+                for (int i=0,iSize=cpy.links.size(); i<iSize; i++) {\r
+                    links.setElementAt(cpy.links.elementAt(i), i);\r
+                }\r
+            }\r
+        }\r
+    }\r
     public SequenceFeature(String type,\r
                            String desc,\r
                            String status,\r
@@ -51,9 +85,7 @@ public class SequenceFeature
     {\r
       this.type = type;\r
       this.description = desc;\r
-      if(status!=null)\r
-        setValue("status", status);\r
-\r
+      setValue("status", status);\r
       this.begin = begin;\r
       this.end = end;\r
       this.featureGroup = featureGroup;\r
@@ -75,13 +107,13 @@ public class SequenceFeature
 \r
     public boolean equals(SequenceFeature sf)\r
     {\r
-      if(begin != sf.begin\r
-      || end != sf.end)\r
-     return false;\r
-\r
+      if (begin != sf.begin\r
+          || end != sf.end\r
+          || score != sf.score)\r
+        return false;\r
 \r
-      if(!(type+description).equals\r
-         (sf.type+sf.description))\r
+      if(!(type+description+featureGroup).equals\r
+         (sf.type+sf.description+sf.featureGroup))\r
         return false;\r
 \r
       return true;\r
@@ -197,11 +229,42 @@ public class SequenceFeature
      */\r
     public void setValue(String key, Object value)\r
     {\r
-      if(otherDetails == null)\r
-        otherDetails = new Hashtable();\r
+      if(value!=null)\r
+      {\r
+        if (otherDetails == null)\r
+          otherDetails = new Hashtable();\r
+\r
+        otherDetails.put(key, value);\r
+      }\r
+    }\r
+\r
+\r
+    /*\r
+     * The following methods are added to maintain\r
+     * the castor Uniprot mapping file for the moment.\r
+     */\r
+    public void setStatus(String status)\r
+    {\r
+      setValue("status", status);\r
+    }\r
 \r
-      otherDetails.put(key, value);\r
+    public String getStatus()\r
+    {\r
+      if (otherDetails != null)\r
+        return otherDetails.get("status").toString();\r
+      else\r
+        return null;\r
     }\r
 \r
+    public void setPosition(int pos)\r
+    {\r
+      begin = pos;\r
+      end = pos;\r
+    }\r
+\r
+    public int getPosition()\r
+    {\r
+      return begin;\r
+    }\r
 \r
 }\r