JAL-1499 patch from Mungo Carstairs
[jalview.git] / src / jalview / io / AlignFile.java
old mode 100755 (executable)
new mode 100644 (file)
index c0f8531..977cb25
@@ -1,19 +1,22 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.io;
 
@@ -25,17 +28,10 @@ import jalview.datamodel.SequenceI;
 import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
 import java.util.Vector;
 
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.xml.sax.SAXException;
-
-import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
-import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
-import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
-import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
-
 /**
  * DOCUMENT ME!
  * 
@@ -61,7 +57,7 @@ public abstract class AlignFile extends FileParse
   /**
    * Properties to be added to generated alignment object
    */
-  protected Hashtable properties;
+  protected Hashtable<Object, Object> properties;
 
   long start;
 
@@ -74,8 +70,10 @@ public abstract class AlignFile extends FileParse
    */
   public AlignFile()
   {
-         // Shouldn't we init data structures (JBPNote: not sure - initData is for initialising the structures used for reading from a datasource, and the bare constructor hasn't got any datasource)
-         initData();
+    // Shouldn't we init data structures (JBPNote: not sure - initData is for
+    // initialising the structures used for reading from a datasource, and the
+    // bare constructor hasn't got any datasource)
+    initData();
   }
 
   /**
@@ -85,9 +83,8 @@ public abstract class AlignFile extends FileParse
    *          Filename to read from.
    * @param type
    *          What type of file to read from (File, URL)
- * @throws Exception 
    */
-  public AlignFile(String inFile, String type) throws Exception
+  public AlignFile(String inFile, String type) throws IOException
   {
     super(inFile, type);
     initData();
@@ -104,9 +101,9 @@ public abstract class AlignFile extends FileParse
    * off.
    * 
    * @param source
- * @throws Exception 
+   * @throws IOException
    */
-  public AlignFile(FileParse source) throws Exception
+  public AlignFile(FileParse source) throws IOException
   {
     super(source);
     initData();
@@ -135,7 +132,7 @@ public abstract class AlignFile extends FileParse
 
     for (int i = 0; i < seqs.size(); i++)
     {
-      s[i] = (SequenceI) seqs.elementAt(i);
+      s[i] = seqs.elementAt(i);
     }
 
     return s;
@@ -178,8 +175,8 @@ public abstract class AlignFile extends FileParse
   {
     if (properties != null && properties.size() > 0)
     {
-      Enumeration keys = properties.keys();
-      Enumeration vals = properties.elements();
+      Enumeration<Object> keys = properties.keys();
+      Enumeration<Object> vals = properties.elements();
       while (keys.hasMoreElements())
       {
         al.setProperty(keys.nextElement(), vals.nextElement());
@@ -210,7 +207,7 @@ public abstract class AlignFile extends FileParse
     }
     if (properties == null)
     {
-      properties = new Hashtable();
+      properties = new Hashtable<Object, Object>();
     }
     properties.put(key, value);
   }
@@ -229,11 +226,20 @@ public abstract class AlignFile extends FileParse
    */
   protected void initData()
   {
-    seqs = new Vector();
+    seqs = new Vector<SequenceI>();
     annotations = new Vector();
   }
 
   /**
+   * Return the alignment properties (or null if none set)
+   * 
+   * @return
+   */
+  protected Set<Map.Entry<Object, Object>> getAlignmentProperties()
+  {
+    return (this.properties == null ? null : this.properties.entrySet());
+  }
+  /**
    * DOCUMENT ME!
    * 
    * @param s
@@ -241,7 +247,7 @@ public abstract class AlignFile extends FileParse
    */
   protected void setSeqs(SequenceI[] s)
   {
-    seqs = new Vector();
+    seqs = new Vector<SequenceI>();
 
     for (int i = 0; i < s.length; i++)
     {
@@ -251,9 +257,8 @@ public abstract class AlignFile extends FileParse
 
   /**
    * This method must be implemented to parse the contents of the file.
-
    */
-  public abstract void parse() throws Exception;
+  public abstract void parse() throws IOException;
 
   /**
    * Print out in alignment file format the Sequences in the seqs Vector.
@@ -302,13 +307,13 @@ public abstract class AlignFile extends FileParse
   /**
    * vector of String[] treeName, newickString pairs
    */
-  Vector newickStrings = null;
+  Vector<String[]> newickStrings = null;
 
   protected void addNewickTree(String treeName, String newickString)
   {
     if (newickStrings == null)
     {
-      newickStrings = new Vector();
+      newickStrings = new Vector<String[]>();
     }
     newickStrings.addElement(new String[]
     { treeName, newickString });