JAL-629 Firm up bootstrapArgs. Correct '-colour' in test. Separate --headless and...
[jalview.git] / src / jalview / bin / ArgParser.java
index 2290182..be2c07f 100644 (file)
@@ -121,8 +121,6 @@ public class ArgParser
 
     private boolean defaultBoolValue = false;
 
-    private int argIndex = -1;
-
     public String toLongString()
     {
       StringBuilder sb = new StringBuilder();
@@ -205,16 +203,6 @@ public class ArgParser
     {
       return defaultBoolValue;
     }
-
-    private void setArgIndex(int i)
-    {
-      this.argIndex = i;
-    }
-
-    protected int getArgIndex()
-    {
-      return this.argIndex;
-    }
   }
 
   public static class ArgValues
@@ -869,16 +857,35 @@ public class ArgParser
       ArgValues av = getArgValues(a);
       return av == null ? false : av.getBoolean();
     }
+
+    protected ArgValue getClosestPreviousArgValueOfArg(ArgValue thisAv,
+            Arg a)
+    {
+      ArgValue closestAv = null;
+      int thisArgIndex = thisAv.getArgIndex();
+      ArgValues compareAvs = this.getArgValues(a);
+      int closestPreviousIndex = -1;
+      for (ArgValue av : compareAvs.getArgValueList())
+      {
+        int argIndex = av.getArgIndex();
+        if (argIndex < thisArgIndex && argIndex > closestPreviousIndex)
+        {
+          closestPreviousIndex = argIndex;
+          closestAv = av;
+        }
+      }
+      return closestAv;
+    }
   }
 
-  private static final Collection<String> bootstrapArgs = new ArrayList(
-          Arrays.asList("props", "debug"));
+  private static final Collection<Arg> bootstrapArgs = new ArrayList(
+          Arrays.asList(Arg.PROPS, Arg.DEBUG));
 
-  public static Map<String, String> bootstrapArgs(String[] args)
+  public static Map<Arg, String> bootstrapArgs(String[] args)
   {
-    Map<String, String> argMap = new HashMap<>();
+    Map<Arg, String> bootstrapArgMap = new HashMap<>();
     if (args == null)
-      return argMap;
+      return bootstrapArgMap;
     Enumeration<String> argE = Collections.enumeration(Arrays.asList(args));
     while (argE.hasMoreElements())
     {
@@ -897,10 +904,11 @@ public class ArgParser
         {
           argName = arg.substring(2);
         }
-        if (bootstrapArgs.contains(argName))
-          argMap.put(argName, val);
+        Arg a = argMap.get(argName);
+        if (a != null && bootstrapArgs.contains(a))
+          bootstrapArgMap.put(a, val);
       }
     }
-    return argMap;
+    return bootstrapArgMap;
   }
 }
\ No newline at end of file