JAL-2321 isParseImmediately() allows the parse() method to determine if it was called...
[jalview.git] / src / jalview / io / AlignFile.java
index 7333075..7b1e84a 100755 (executable)
@@ -40,8 +40,8 @@ import java.util.Vector;
  * @author $author$
  * @version $Revision$
  */
-public abstract class AlignFile extends FileParse implements
-        AlignmentFileReaderI, AlignmentFileWriterI
+public abstract class AlignFile extends FileParse
+        implements AlignmentFileReaderI, AlignmentFileWriterI
 {
   int noSeqs = 0;
 
@@ -72,8 +72,21 @@ public abstract class AlignFile extends FileParse implements
 
   long end;
 
+  /**
+   * true if parse() has been called
+   */
   private boolean parseCalled;
 
+  private boolean parseImmediately;
+
+  /**
+   * @return if doParse() was called at construction time
+   */
+  protected boolean isParseImmediately()
+  {
+    return parseImmediately;
+  }
+
   /**
    * Creates a new AlignFile object.
    */
@@ -118,8 +131,7 @@ public abstract class AlignFile extends FileParse implements
    * @throws IOException
    */
   public AlignFile(boolean parseImmediately, String dataObject,
-          DataSourceType sourceType)
-          throws IOException
+          DataSourceType sourceType) throws IOException
   {
     super(dataObject, sourceType);
     initData();
@@ -154,6 +166,11 @@ public abstract class AlignFile extends FileParse implements
   {
     super(source);
     initData();
+
+    // stash flag in case parse needs to know if it has to autoconfigure or was
+    // configured after construction
+    this.parseImmediately = parseImmediately;
+
     if (parseImmediately)
     {
       doParse();
@@ -175,11 +192,6 @@ public abstract class AlignFile extends FileParse implements
     }
     parseCalled = true;
     parse();
-    // sets the index of each sequence in the alignment
-    for (int i = 0, c = seqs.size(); i < c; i++)
-    {
-      seqs.get(i).setIndex(i);
-    }
   }
 
   /**
@@ -282,9 +294,8 @@ public abstract class AlignFile extends FileParse implements
   {
     if (key == null)
     {
-      throw new Error(
-              MessageManager
-                      .getString("error.implementation_error_cannot_have_null_alignment"));
+      throw new Error(MessageManager.getString(
+              "error.implementation_error_cannot_have_null_alignment"));
     }
     if (value == null)
     {