* \r
* @author pvtroshin\r
* \r
- * Date December 2009\r
+ * @version 1.0 December 2009\r
* @param <T>\r
* executable type\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class Preset<T> {\r
\r
- @XmlTransient\r
- private static final String SPACE = " ";\r
-\r
- @XmlElement(required = true, nillable = false)\r
- // @XmlID - ? require no spaces (!)\r
- String name;\r
-\r
- String description;\r
-\r
- @XmlElement(required = true, nillable = false)\r
- @XmlElementWrapper(name = "optlist")\r
- List<String> option;\r
-\r
- public void setOptions(List<String> option) {\r
- this.option = option;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- /**\r
- * @return a List of Options as a String\r
- */\r
- public List<String> getOptions() {\r
- return new ArrayList<String>(option);\r
- }\r
-\r
- /**\r
- * \r
- * @return - name of the Preset\r
- */\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- /**\r
- * \r
- * @return - a long description of the Preset\r
- */\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- /**\r
- * Converts list of options as String to type Option\r
- * \r
- * @param rconfig\r
- * @return List of Options\r
- * @throws WrongParameterException\r
- * if the value of the parameter is invalid @see\r
- * {@link Parameter}\r
- */\r
- public List<Option<T>> getArguments(RunnerConfig<T> rconfig)\r
- throws WrongParameterException {\r
- List<Option<T>> options = new ArrayList<Option<T>>();\r
- for (String optionName : option) {\r
- optionName = optionName.trim();\r
- String oname = getName(optionName);\r
- Option<T> option = rconfig.getArgumentByOptionName(oname);\r
- if (option != null) {\r
- // Set default value to the preset value\r
- if (containValue(optionName)) {\r
- // extract and set value to the parameter \r
- option.setDefaultValue(getValue(optionName));\r
- } else {\r
- // set value to the option as default, as this could be a multi-option value\r
- option.setDefaultValue(oname);\r
- }\r
- options.add(option);\r
- }\r
+ @XmlTransient\r
+ private static final String SPACE = " ";\r
+\r
+ @XmlElement(required = true, nillable = false)\r
+ // @XmlID - ? require no spaces (!)\r
+ String name;\r
+\r
+ String description;\r
+\r
+ @XmlElement(required = true, nillable = false)\r
+ @XmlElementWrapper(name = "optlist")\r
+ List<String> option;\r
+\r
+ public void setOptions(List<String> option) {\r
+ this.option = option;\r
}\r
- return options;\r
- }\r
\r
- boolean containValue(String option) {\r
- if (option.trim().contains(SPACE)) {\r
- return true;\r
+ public void setName(String name) {\r
+ this.name = name;\r
}\r
- return false;\r
- }\r
\r
- String getName(String option) {\r
- option = option.trim();\r
- if (containValue(option)) {\r
- return option.substring(0, option.indexOf(SPACE)).trim();\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
}\r
- return option;\r
- }\r
-\r
- String getValue(String option) {\r
- assert containValue(option);\r
- option = option.trim();\r
- return option.substring(option.indexOf(SPACE) + 1).trim();\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;\r
- value += "Description: " + description + SysPrefs.newlinechar;\r
- value += "Options: " + SysPrefs.newlinechar;\r
- for (String oname : this.option) {\r
- value += oname + SysPrefs.newlinechar;\r
+\r
+ /**\r
+ * @return a List of Options as a String\r
+ */\r
+ public List<String> getOptions() {\r
+ return new ArrayList<String>(option);\r
}\r
- value += SysPrefs.newlinechar;\r
- return value;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((description == null) ? 0 : description.hashCode());\r
- result = prime * result + ((name == null) ? 0 : name.hashCode());\r
- result = prime * result + ((option == null) ? 0 : option.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Preset other = (Preset) obj;\r
- if (description == null) {\r
- if (other.description != null)\r
- return false;\r
- } else if (!description.equals(other.description))\r
- return false;\r
- if (name == null) {\r
- if (other.name != null)\r
- return false;\r
- } else if (!name.equals(other.name))\r
- return false;\r
- if (option == null) {\r
- if (other.option != null)\r
+\r
+ /**\r
+ * \r
+ * @return - name of the Preset\r
+ */\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return - a long description of the Preset\r
+ */\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ /**\r
+ * Converts list of options as String to type Option\r
+ * \r
+ * @param rconfig\r
+ * @return List of Options\r
+ * @throws WrongParameterException\r
+ * if the value of the parameter is invalid @see\r
+ * {@link Parameter}\r
+ */\r
+ public List<Option<T>> getArguments(RunnerConfig<T> rconfig)\r
+ throws WrongParameterException {\r
+ List<Option<T>> options = new ArrayList<Option<T>>();\r
+ for (String optionName : option) {\r
+ optionName = optionName.trim();\r
+ String oname = getName(optionName);\r
+ Option<T> option = rconfig.getArgumentByOptionName(oname);\r
+ if (option != null) {\r
+ // Set default value to the preset value\r
+ if (containValue(optionName)) {\r
+ // extract and set value to the parameter\r
+ option.setDefaultValue(getValue(optionName));\r
+ } else {\r
+ // set value to the option as default, as this could be a\r
+ // multi-option value\r
+ option.setDefaultValue(oname);\r
+ }\r
+ options.add(option);\r
+ }\r
+ }\r
+ return options;\r
+ }\r
+\r
+ boolean containValue(String option) {\r
+ if (option.trim().contains(SPACE)) {\r
+ return true;\r
+ }\r
return false;\r
- } else if (!option.equals(other.option))\r
- return false;\r
- return true;\r
- }\r
+ }\r
+\r
+ String getName(String option) {\r
+ option = option.trim();\r
+ if (containValue(option)) {\r
+ return option.substring(0, option.indexOf(SPACE)).trim();\r
+ }\r
+ return option;\r
+ }\r
+\r
+ String getValue(String option) {\r
+ assert containValue(option);\r
+ option = option.trim();\r
+ return option.substring(option.indexOf(SPACE) + 1).trim();\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;\r
+ value += "Description: " + description + SysPrefs.newlinechar;\r
+ value += "Options: " + SysPrefs.newlinechar;\r
+ for (String oname : this.option) {\r
+ value += oname + SysPrefs.newlinechar;\r
+ }\r
+ value += SysPrefs.newlinechar;\r
+ return value;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result + ((name == null) ? 0 : name.hashCode());\r
+ result = prime * result + ((option == null) ? 0 : option.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ Preset other = (Preset) obj;\r
+ if (description == null) {\r
+ if (other.description != null)\r
+ return false;\r
+ } else if (!description.equals(other.description))\r
+ return false;\r
+ if (name == null) {\r
+ if (other.name != null)\r
+ return false;\r
+ } else if (!name.equals(other.name))\r
+ return false;\r
+ if (option == null) {\r
+ if (other.option != null)\r
+ return false;\r
+ } else if (!option.equals(other.option))\r
+ return false;\r
+ return true;\r
+ }\r
\r
}\r