3467f61bccd106b048f112ea6413af0a276626f9
[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   /*
23    * This id is set by a subVal id= to identify the product of this ArgValue
24    * later. Set but not currently used.
25    */
26   private String id;
27
28   private SubVals subVals;
29
30   protected ArgValue(Arg a, SubVals sv, Type type, String content,
31           int argIndex)
32   {
33     this.arg = a;
34     this.value = content;
35     this.argIndex = argIndex;
36     this.subVals = sv == null ? new SubVals("") : sv;
37     this.setType(type);
38   }
39
40   protected ArgValue(Arg a, Type type, String value, int argIndex)
41   {
42     this.arg = a;
43     this.argIndex = argIndex;
44     this.subVals = new SubVals(value);
45     this.value = getSubVals().getContent();
46     this.setType(type);
47   }
48
49   protected void setType(Type t)
50   {
51     if (this.getArg().hasOption(Opt.HASTYPE))
52       this.type = t;
53   }
54
55   public Type getType()
56   {
57     return type;
58   }
59
60   public Arg getArg()
61   {
62     return arg;
63   }
64
65   public String getValue()
66   {
67     return value;
68   }
69
70   public int getArgIndex()
71   {
72     return argIndex;
73   }
74
75   protected void setId(String i)
76   {
77     id = i;
78   }
79
80   public String getId()
81   {
82     return id;
83   }
84
85   public SubVals getSubVals()
86   {
87     return subVals;
88   }
89
90   public String getSubVal(String key)
91   {
92     if (subVals == null || !subVals.has(key))
93       return null;
94     return subVals.get(key);
95   }
96
97   protected void putSubVal(String key, String val)
98   {
99     this.subVals.put(key, val);
100   }
101
102   @Override
103   public final int compareTo(ArgValue o)
104   {
105     return this.getArgIndex() - o.getArgIndex();
106   }
107 }