f0126df9225bb2286b98b811c506bfe1727ea656
[jalview.git] / src / jalview / ws / params / simple / Option.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.ws.params.simple;
22
23 import jalview.ws.params.OptionI;
24
25 import java.net.URL;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29
30 public class Option implements OptionI
31 {
32   String name;
33
34   /*
35    * current value in string format, or "null" if undefined
36    */
37   String value;
38
39   /*
40    * default value in string format, or "null" if undefined
41    */
42   String defvalue;
43
44   String description;
45
46   ArrayList<String> possibleVals = new ArrayList<>();
47
48   boolean required;
49
50   URL fdetails;
51
52   @Override
53   public String getName()
54   {
55     return name;
56   }
57
58   @Override
59   public String getValue()
60   {
61     return value == null ? defvalue : value;
62   }
63
64   @Override
65   public void setValue(String selectedItem)
66   {
67     value = selectedItem;
68   }
69
70   @Override
71   public URL getFurtherDetails()
72   {
73     return fdetails;
74   }
75
76   @Override
77   public boolean isRequired()
78   {
79     return required;
80   }
81
82   @Override
83   public String getDescription()
84   {
85     return description;
86   }
87
88   @Override
89   public List<String> getPossibleValues()
90   {
91     return possibleVals;
92   }
93
94   public Option(Option opt)
95   {
96     name = new String(opt.name);
97     if (opt.value != null)
98     {
99       value = new String(opt.value);
100     }
101     if (opt.defvalue != null)
102     {
103       defvalue = new String(opt.defvalue);
104     }
105     if (opt.description != null)
106     {
107       description = new String(opt.description);
108     }
109     if (opt.possibleVals != null)
110     {
111       possibleVals = (ArrayList<String>) opt.possibleVals.clone();
112     }
113     required = opt.required;
114     // URLs are singletons - so we copy by reference. nasty but true.
115     fdetails = opt.fdetails;
116   }
117
118   public Option()
119   {
120   }
121
122   public Option(String name2, String description2, boolean isrequired,
123           String defValue, String value, Collection<String> possibleVals,
124           URL fdetails)
125   {
126     name = name2;
127     description = description2;
128     this.value = value;
129     this.required = isrequired;
130     this.defvalue = defValue;
131     if (possibleVals != null)
132     {
133       this.possibleVals = new ArrayList<>();
134       this.possibleVals.addAll(possibleVals);
135     }
136     this.fdetails = fdetails;
137   }
138
139   @Override
140   public OptionI copy()
141   {
142     Option opt = new Option(this);
143     return opt;
144   }
145
146   /**
147    * toString method to help identify options in the debugger only
148    */
149   @Override
150   public String toString()
151   {
152     return this.getClass().getName() + ":" + name;
153   }
154 }