1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.metadata;
\r
21 import java.util.ArrayList;
\r
22 import java.util.List;
\r
24 import javax.xml.bind.annotation.XmlAccessType;
\r
25 import javax.xml.bind.annotation.XmlAccessorType;
\r
26 import javax.xml.bind.annotation.XmlElement;
\r
27 import javax.xml.bind.annotation.XmlElementWrapper;
\r
28 import javax.xml.bind.annotation.XmlTransient;
\r
30 import compbio.util.SysPrefs;
\r
33 * Collection of Options and Parameters with their values
\r
40 * Date December 2009
\r
44 @XmlAccessorType(XmlAccessType.FIELD)
\r
45 public class Preset<T> {
\r
48 private static final String SPACE = " ";
\r
50 @XmlElement(required = true, nillable = false)
\r
51 // @XmlID - ? require no spaces (!)
\r
56 @XmlElement(required = true, nillable = false)
\r
57 @XmlElementWrapper(name = "optlist")
\r
58 List<String> option;
\r
60 public void setOptions(List<String> option) {
\r
61 this.option = option;
\r
64 public void setName(String name) {
\r
68 public void setDescription(String description) {
\r
69 this.description = description;
\r
73 * @return a List of Options as a String
\r
75 public List<String> getOptions() {
\r
76 return new ArrayList<String>(option);
\r
81 * @return - name of the Preset
\r
83 public String getName() {
\r
89 * @return - a long description of the Preset
\r
91 public String getDescription() {
\r
96 * Converts list of options as String to type Option
\r
99 * @return List of Options
\r
100 * @throws WrongParameterException
\r
101 * if the value of the parameter is invalid @see
\r
102 * {@link Parameter}
\r
104 public List<Option<T>> getArguments(RunnerConfig<T> rconfig)
\r
105 throws WrongParameterException {
\r
106 List<Option<T>> options = new ArrayList<Option<T>>();
\r
107 for (String optionName : option) {
\r
108 optionName = optionName.trim();
\r
109 String oname = getName(optionName);
\r
110 Option<T> option = rconfig.getArgumentByOptionName(oname);
\r
111 if (option != null) {
\r
112 // Set default value to the preset value
\r
113 if (containValue(optionName)) {
\r
114 option.setDefaultValue(getValue(optionName));
\r
116 options.add(option);
\r
122 boolean containValue(String option) {
\r
123 if (option.trim().contains(SPACE)) {
\r
129 String getName(String option) {
\r
130 option = option.trim();
\r
131 if (containValue(option)) {
\r
132 return option.substring(0, option.indexOf(SPACE)).trim();
\r
137 String getValue(String option) {
\r
138 assert containValue(option);
\r
139 option = option.trim();
\r
140 return option.substring(option.indexOf(SPACE) + 1).trim();
\r
144 public String toString() {
\r
145 String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;
\r
146 value += "Description: " + description + SysPrefs.newlinechar;
\r
147 value += "Options: " + SysPrefs.newlinechar;
\r
148 for (String oname : this.option) {
\r
149 value += oname + SysPrefs.newlinechar;
\r
151 value += SysPrefs.newlinechar;
\r
156 public int hashCode() {
\r
157 final int prime = 31;
\r
159 result = prime * result
\r
160 + ((description == null) ? 0 : description.hashCode());
\r
161 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
162 result = prime * result + ((option == null) ? 0 : option.hashCode());
\r
167 public boolean equals(Object obj) {
\r
172 if (getClass() != obj.getClass())
\r
174 Preset other = (Preset) obj;
\r
175 if (description == null) {
\r
176 if (other.description != null)
\r
178 } else if (!description.equals(other.description))
\r
180 if (name == null) {
\r
181 if (other.name != null)
\r
183 } else if (!name.equals(other.name))
\r
185 if (option == null) {
\r
186 if (other.option != null)
\r
188 } else if (!option.equals(other.option))
\r