JAL-4090 JAL-1551 source license
[jalview.git] / src / jalview / bin / argparser / ArgValue.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin.argparser;
22
23 import jalview.bin.argparser.Arg.Opt;
24 import jalview.bin.argparser.Arg.Type;
25
26 /**
27  * A helper class to keep an index of argument position with argument values
28  */
29 public class ArgValue implements Comparable<ArgValue>
30 {
31   private Arg arg;
32
33   private int argIndex;
34
35   private String value;
36
37   /*
38    * Type type is only really used by --help-type
39    */
40   private Type type = null;
41
42   /*
43    * This id is set by a subVal id= to identify the product of this ArgValue
44    * later. Set but not currently used.
45    */
46   private String id;
47
48   private SubVals subVals;
49
50   protected ArgValue(Arg a, SubVals sv, Type type, String content,
51           int argIndex)
52   {
53     this.arg = a;
54     this.value = content;
55     this.argIndex = argIndex;
56     this.subVals = sv == null ? new SubVals("") : sv;
57     this.setType(type);
58   }
59
60   protected ArgValue(Arg a, Type type, String value, int argIndex)
61   {
62     this.arg = a;
63     this.argIndex = argIndex;
64     this.subVals = new SubVals(value);
65     this.value = getSubVals().getContent();
66     this.setType(type);
67   }
68
69   protected void setType(Type t)
70   {
71     if (this.getArg().hasOption(Opt.HASTYPE))
72       this.type = t;
73   }
74
75   public Type getType()
76   {
77     return type;
78   }
79
80   public Arg getArg()
81   {
82     return arg;
83   }
84
85   public String getValue()
86   {
87     return value;
88   }
89
90   public int getArgIndex()
91   {
92     return argIndex;
93   }
94
95   protected void setId(String i)
96   {
97     id = i;
98   }
99
100   public String getId()
101   {
102     return id;
103   }
104
105   public SubVals getSubVals()
106   {
107     return subVals;
108   }
109
110   public String getSubVal(String key)
111   {
112     if (subVals == null || !subVals.has(key))
113       return null;
114     return subVals.get(key);
115   }
116
117   protected void putSubVal(String key, String val)
118   {
119     this.subVals.put(key, val);
120   }
121
122   @Override
123   public final int compareTo(ArgValue o)
124   {
125     return this.getArgIndex() - o.getArgIndex();
126   }
127 }