JAL-629 Added 'Type' to args and argvalues
[jalview.git] / src / jalview / bin / argparser / ArgValue.java
1 package jalview.bin.argparser;
2
3 import jalview.bin.argparser.Arg.Opt;
4 import jalview.bin.argparser.Arg.Type;
5
6 /**
7  * A helper class to keep an index of argument position with argument values
8  */
9 public class ArgValue implements Comparable<ArgValue>
10 {
11   private Arg arg;
12
13   private int argIndex;
14
15   private String value;
16
17   /*
18    * Type type is only really used by --help-type
19    */
20   private Type type = null;
21
22   // This id is set by a subVal id= to identify the product of this ArgValue
23   // later. Set but not currently used.
24   private String id;
25
26   private SubVals subVals;
27
28   protected ArgValue(Arg a, SubVals sv, Type type, String content,
29           int argIndex)
30   {
31     this.arg = a;
32     this.value = content;
33     this.argIndex = argIndex;
34     this.subVals = sv == null ? new SubVals("") : sv;
35     this.setType(type);
36   }
37
38   protected ArgValue(Arg a, Type type, String value, int argIndex)
39   {
40     this.arg = a;
41     this.argIndex = argIndex;
42     this.subVals = new SubVals(value);
43     this.value = getSubVals().getContent();
44     this.setType(type);
45   }
46
47   protected void setType(Type t)
48   {
49     if (this.getArg().hasOption(Opt.HASTYPE))
50       this.type = t;
51   }
52
53   public Type getType()
54   {
55     return type;
56   }
57
58   public Arg getArg()
59   {
60     return arg;
61   }
62
63   public String getValue()
64   {
65     return value;
66   }
67
68   public int getArgIndex()
69   {
70     return argIndex;
71   }
72
73   protected void setId(String i)
74   {
75     id = i;
76   }
77
78   public String getId()
79   {
80     return id;
81   }
82
83   public SubVals getSubVals()
84   {
85     return subVals;
86   }
87
88   public String getSubVal(String key)
89   {
90     if (subVals == null || !subVals.has(key))
91       return null;
92     return subVals.get(key);
93   }
94
95   protected void putSubVal(String key, String val)
96   {
97     this.subVals.put(key, val);
98   }
99
100   @Override
101   public final int compareTo(ArgValue o)
102   {
103     return this.getArgIndex() - o.getArgIndex();
104   }
105 }