JAL-1432 updated copyright notices
[jalview.git] / src / jalview / ws / params / simple / Option.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.ws.params.simple;
20
21 import jalview.ws.params.OptionI;
22
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27
28 public class Option implements OptionI
29 {
30
31   String name, value, defvalue, description;
32
33   ArrayList<String> possibleVals = new ArrayList<String>();
34
35   boolean required;
36
37   URL fdetails;
38
39   @Override
40   public String getName()
41   {
42     return name;
43   }
44
45   @Override
46   public String getValue()
47   {
48     return value == null ? defvalue : value;
49   }
50
51   @Override
52   public void setValue(String selectedItem)
53   {
54     value = selectedItem;
55   }
56
57   @Override
58   public URL getFurtherDetails()
59   {
60     return fdetails;
61   }
62
63   @Override
64   public boolean isRequired()
65   {
66     return required;
67   }
68
69   @Override
70   public String getDescription()
71   {
72     return description;
73   }
74
75   @Override
76   public List<String> getPossibleValues()
77   {
78     return possibleVals;
79   }
80
81   public Option(Option opt)
82   {
83     name = new String(opt.name);
84     if (opt.value != null)
85       value = new String(opt.value);
86     if (opt.defvalue != null)
87       defvalue = new String(opt.defvalue);
88     if (opt.description != null)
89       description = new String(opt.description);
90     if (opt.possibleVals != null)
91     {
92       possibleVals = (ArrayList<String>) opt.possibleVals.clone();
93     }
94     required = opt.required;
95     // URLs are singletons - so we copy by reference. nasty but true.
96     fdetails = opt.fdetails;
97   }
98
99   public Option()
100   {
101   }
102
103   public Option(String name2, String description2, boolean isrequired,
104           String defValue, String value, Collection<String> possibleVals,
105           URL fdetails)
106   {
107     name = name2;
108     description = description2;
109     this.value = value;
110     this.required = isrequired;
111     this.defvalue = defValue;
112     if (possibleVals != null)
113     {
114       this.possibleVals = new ArrayList<String>();
115       this.possibleVals.addAll(possibleVals);
116     }
117     this.fdetails = fdetails;
118   }
119
120   @Override
121   public OptionI copy()
122   {
123     Option opt = new Option(this);
124     return opt;
125   }
126 }