JAL-629 Change --open to --append and --opennew to --open. Make --open(new) part...
[jalview.git] / src / jalview / bin / Commands.java
index fc2ee1a..dafc342 100644 (file)
@@ -2,16 +2,15 @@ package jalview.bin;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import jalview.analysis.AlignmentUtils;
 import jalview.bin.argparser.Arg;
@@ -150,7 +149,7 @@ public class Commands
      * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null;
      * DataSourceType protocol = null;
      */
-    if (avm.containsArg(Arg.OPEN) || avm.containsArg(Arg.OPENNEW))
+    if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN))
     {
       commandArgsProvided = true;
       long progress = -1;
@@ -158,21 +157,16 @@ public class Commands
       boolean first = true;
       boolean progressBarSet = false;
       AlignFrame af;
-      // Combine the OPEN and OPENNEW files into one list, along with whether it
-      // was OPEN or OPENNEW
-      List<Entry<Arg, ArgValue>> openAvList = new ArrayList<>();
-      avm.getArgValueList(Arg.OPEN).stream()
-              .forEachOrdered(av -> openAvList.add(
-                      new AbstractMap.SimpleEntry<Arg, ArgValue>(Arg.OPEN,
-                              av)));
-      avm.getArgValueList(Arg.OPENNEW).stream()
-              .forEachOrdered(av -> openAvList
-                      .add(new AbstractMap.SimpleEntry<Arg, ArgValue>(
-                              Arg.OPENNEW, av)));
-      for (Entry<Arg, ArgValue> aav : openAvList)
+      // Combine the APPEND and OPEN files into one list, along with whether it
+      // was APPEND or OPEN
+      List<ArgValue> openAvList = new ArrayList<>();
+      openAvList.addAll(avm.getArgValueList(Arg.OPEN));
+      openAvList.addAll(avm.getArgValueList(Arg.APPEND));
+      // sort avlist based on av.getArgIndex()
+      Collections.sort(openAvList);
+      for (ArgValue av : openAvList)
       {
-        Arg a = aav.getKey();
-        ArgValue av = aav.getValue();
+        Arg a = av.getArg();
         String openFile = av.getValue();
         if (openFile == null)
           continue;
@@ -221,7 +215,7 @@ public class Commands
 
         af = afMap.get(id);
         if (af == null || "true".equals(av.getSubVal("new"))
-                || a == Arg.OPENNEW || format == FileFormat.Jalview)
+                || a == Arg.OPEN || format == FileFormat.Jalview)
         {
           /*
            * this approach isn't working yet // get default annotations before opening
@@ -340,7 +334,7 @@ public class Commands
           af.getCurrentView().addFile(new File(openFile), format, false);
         }
 
-        Console.debug("Command " + Arg.OPEN + " executed successfully!");
+        Console.debug("Command " + Arg.APPEND + " executed successfully!");
 
       }
       if (first) // first=true means nothing opened