1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* Copyright (c) 2009 Peter Troshin
*
* JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* Apache License version 2 as published by the Apache Software Foundation
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
* License for more details.
*
* A copy of the license is in apache_license.txt. It is also available here:
* @see: http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Any republication or derived work distributed in source code form
* must include this copyright and license notice.
*/
package compbio.metadata;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlTransient;
import compbio.util.SysPrefs;
/**
* Collection of Options and Parameters with their values
*
* @see Option
* @see Parameter
*
* @author pvtroshin
*
* @version 1.0 December 2009
* @param <T>
* executable type
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Preset<T> {
@XmlTransient
private static final String SPACE = " ";
@XmlElement(required = true, nillable = false)
// @XmlID - ? require no spaces (!)
String name;
String description;
@XmlElement(required = true, nillable = false)
@XmlElementWrapper(name = "optlist")
List<String> option;
public void setOptions(List<String> option) {
this.option = option;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
/**
* @return a List of Options as a String
*/
public List<String> getOptions() {
return new ArrayList<String>(option);
}
/**
*
* @return - name of the Preset
*/
public String getName() {
return name;
}
/**
*
* @return - a long description of the Preset
*/
public String getDescription() {
return description;
}
/**
* Converts list of options as String to type Option
*
* @param rconfig
* @return List of Options
* @throws WrongParameterException
* if the value of the parameter is invalid @see
* {@link Parameter}
*/
public List<Option<T>> getArguments(RunnerConfig<T> rconfig)
throws WrongParameterException {
List<Option<T>> options = new ArrayList<Option<T>>();
for (String optionName : option) {
optionName = optionName.trim();
String oname = getName(optionName);
Option<T> option = rconfig.getArgumentByOptionName(oname);
if (option != null) {
// Set default value to the preset value
if (containValue(optionName)) {
// extract and set value to the parameter
option.setDefaultValue(getValue(optionName));
} else {
// set value to the option as default, as this could be a
// multi-option value
option.setDefaultValue(oname);
}
options.add(option);
}
}
return options;
}
boolean containValue(String option) {
if (option.trim().contains(SPACE)) {
return true;
}
return false;
}
String getName(String option) {
option = option.trim();
if (containValue(option)) {
return option.substring(0, option.indexOf(SPACE)).trim();
}
return option;
}
String getValue(String option) {
assert containValue(option);
option = option.trim();
return option.substring(option.indexOf(SPACE) + 1).trim();
}
@Override
public String toString() {
String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;
value += "Description: " + description + SysPrefs.newlinechar;
value += "Options: " + SysPrefs.newlinechar;
for (String oname : this.option) {
value += oname + SysPrefs.newlinechar;
}
value += SysPrefs.newlinechar;
return value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((option == null) ? 0 : option.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Preset other = (Preset) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (option == null) {
if (other.option != null)
return false;
} else if (!option.equals(other.option))
return false;
return true;
}
}
|