import java.net.URL;
import java.util.Arrays;
+import java.util.List;
+
+import static java.util.Objects.requireNonNullElse;
public class BooleanOption extends Option
{
+ public static class Builder extends Option.Builder
+ {
+ private boolean defaultValue = false;
+
+ private boolean value = false;
+
+ private String reprValue = null;
+
+ public void setDefaultValue(Boolean defaultValue)
+ {
+ this.defaultValue = requireNonNullElse(defaultValue, false);
+ }
+
+ public void setValue(Boolean value)
+ {
+ this.value = requireNonNullElse(value, false);
+ }
+
+ public void setReprValue(String reprValue)
+ {
+ this.reprValue = reprValue;
+ }
+
+ @Override
+ public void setPossibleValues(List<String> possibleValues)
+ {
+ throw new UnsupportedOperationException("cannot set possible values for boolean");
+ }
+
+ @Override
+ public BooleanOption build()
+ {
+ return new BooleanOption(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
+ protected BooleanOption(Builder builder)
+ {
+ super(builder);
+ String reprValue = requireNonNullElse(builder.reprValue, name);
+ defvalue = builder.defaultValue ? reprValue : null;
+ value = builder.value ? reprValue : null;
+ possibleVals = List.of(reprValue);
+ displayVals = List.of(label);
+ }
public BooleanOption(String name, String descr, boolean required,
Boolean defVal, Boolean val, URL link)
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
+import static java.util.Objects.requireNonNullElse;
/**
*
*/
public class DoubleParameter extends Option implements ParameterI
{
+ public static class Builder extends Option.Builder
+ {
+ // setting them the opposite way disables limits until both are set.
+ protected double min = Double.POSITIVE_INFINITY;
+
+ protected double max = Double.NEGATIVE_INFINITY;
+
+ /**
+ * Setting string on double parameter is not allowed, use
+ * {@link #setValue(Double)} instead.
+ */
+ @Override
+ public void setValue(String value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setValue(Double value)
+ {
+ if (value != null)
+ super.setValue(value.toString());
+ else
+ super.setValue(null);
+ }
+
+ /**
+ * Setting string on double parameter is not allowed, use
+ * {@link #setDefaultValue(Double)} instead.
+ */
+ @Override
+ public void setDefaultValue(String defaultValue)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefaultValue(Double defaultValue)
+ {
+ if (defaultValue != null)
+ super.setDefaultValue(defaultValue.toString());
+ else
+ super.setDefaultValue(null);
+ }
+
+ public void setMin(Double min)
+ {
+ this.min = requireNonNullElse(min, Double.POSITIVE_INFINITY);
+ }
+
+ public void setMax(Double max)
+ {
+ this.max = requireNonNullElse(max, Double.NEGATIVE_INFINITY);
+ }
+
+ public void setBounds(Double min, Double max)
+ {
+ setMin(min);
+ setMax(max);
+ }
+
+ public DoubleParameter build()
+ {
+ return new DoubleParameter(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
double defval;
double min;
};
}
+ protected DoubleParameter(Builder builder)
+ {
+ super(builder);
+ this.min = builder.min;
+ this.max = builder.max;
+ if (defvalue != null)
+ defval = Double.parseDouble(defvalue);
+ }
+
public DoubleParameter(DoubleParameter parm)
{
super(parm);
}
public DoubleParameter(String name, String description, boolean required,
- Double defValue, double min, double max)
+ Double defValue, double min, double max)
{
super(name, description, required, String.valueOf(defValue), null, null,
- null);
+ null);
defval = defValue;
this.min = min;
this.max = max;
}
public DoubleParameter(String name, String description, boolean required,
- Double defValue, Double value, double min, double max)
+ Double defValue, Double value, double min, double max)
{
super(name, description, required, String.valueOf(defValue),
- String.valueOf(value), null, null);
+ String.valueOf(value), null, null);
defval = defValue;
this.min = min;
this.max = max;
*/
public class FileParameter extends StringParameter
{
+ public static class Builder extends StringParameter.Builder
+ {
+ @Override
+ public FileParameter build()
+ {
+ return new FileParameter(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
+ public FileParameter(Builder builder)
+ {
+ super(builder);
+ }
public FileParameter(String name, String description, boolean required,
- String defValue, String value)
+ String defValue, String value)
{
super(name, description, required, defValue, value);
}
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
+import static java.util.Objects.requireNonNullElse;
/**
* @author jimp
*/
public class IntegerParameter extends Option implements ParameterI
{
+ public static class Builder extends Option.Builder
+ {
+ // assigning them the opposite way results in no limits unless both are set
+ protected int min = Integer.MAX_VALUE;
+
+ protected int max = Integer.MIN_VALUE;
+
+ @Override
+ public void setDefaultValue(String defaultValue)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefaultValue(Integer defaultValue)
+ {
+ if (defaultValue != null)
+ super.setDefaultValue(defaultValue.toString());
+ else
+ super.setDefaultValue(null);
+ }
+
+ @Override
+ public void setValue(String value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setValue(Integer value)
+ {
+ if (value != null)
+ super.setValue(value.toString());
+ else
+ super.setValue(null);
+ }
+
+ public void setMin(Integer min)
+ {
+ this.min = requireNonNullElse(min, Integer.MAX_VALUE);
+ }
+
+ public void setMax(Integer max)
+ {
+ this.max = requireNonNullElse(max, Integer.MIN_VALUE);
+ }
+
+ public void setBounds(Integer min, Integer max)
+ {
+ setMin(min);
+ setMax(max);
+ }
+
+ public IntegerParameter build()
+ {
+ return new IntegerParameter(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
int defval;
int min;
};
}
+ protected IntegerParameter(Builder builder)
+ {
+ super(builder);
+ min = builder.min;
+ max = builder.max;
+ if (defvalue != null)
+ defval = Integer.parseInt(defvalue);
+ }
+
public IntegerParameter(IntegerParameter parm)
{
super(parm);
}
public IntegerParameter(String name, String description, boolean required,
- int defValue, int min, int max)
+ int defValue, int min, int max)
{
super(name, description, required, String.valueOf(defValue), null, null,
- null);
+ null);
defval = defValue;
this.min = min;
this.max = max;
}
public IntegerParameter(String name, String description, boolean required,
- int defValue, int value, int min, int max)
+ int defValue, int value, int min, int max)
{
super(name, description, required, String.valueOf(defValue),
- String.valueOf(value), null, null);
+ String.valueOf(value), null, null);
defval = defValue;
this.min = min;
this.max = max;
package jalview.ws.params.simple;
+import static java.util.Objects.requireNonNullElse;
+
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
*/
public class LogarithmicParameter extends Option implements ParameterI
{
+ public static class Builder extends Option.Builder
+ {
+ // setting them the opposite way disables limits until both are set.
+ protected double min = Double.POSITIVE_INFINITY;
+
+ protected double max = Double.NEGATIVE_INFINITY;
+
+ /**
+ * Setting string on double parameter is not allowed, use
+ * {@link #setValue(Double)} instead.
+ */
+ @Override
+ public void setValue(String value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setValue(Double value)
+ {
+ if (value != null)
+ super.setValue(value.toString());
+ else
+ super.setValue(null);
+ }
+
+ /**
+ * Setting string on double parameter is not allowed, use
+ * {@link #setDefaultValue(Double)} instead.
+ */
+ @Override
+ public void setDefaultValue(String defaultValue)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDefaultValue(Double defaultValue)
+ {
+ if (defaultValue != null)
+ super.setDefaultValue(defaultValue.toString());
+ else
+ super.setDefaultValue(null);
+ }
+
+ public void setMin(Double min)
+ {
+ this.min = requireNonNullElse(min, Double.POSITIVE_INFINITY);
+ }
+
+ public void setMax(Double max)
+ {
+ this.max = requireNonNullElse(max, Double.NEGATIVE_INFINITY);
+ }
+
+ public void setBounds(Double min, Double max)
+ {
+ setMin(min);
+ setMax(max);
+ }
+
+ @Override
+ public LogarithmicParameter build()
+ {
+ return new LogarithmicParameter(this);
+ }
+ }
+
final double defval;
final double min;
};
}
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
+ public LogarithmicParameter(Builder builder)
+ {
+ super(builder);
+ this.min = builder.min;
+ this.max = builder.max;
+ if (defvalue != null)
+ defval = Double.parseDouble(defvalue);
+ else
+ defval = 0.0;
+ }
+
public LogarithmicParameter(LogarithmicParameter parm)
{
super(parm);
}
public LogarithmicParameter(String name, String description,
- boolean required, Double defValue, double min, double max)
+ boolean required, Double defValue, double min, double max)
{
super(name, description, required, String.valueOf(defValue), null, null,
- null);
+ null);
defval = defValue;
this.min = min;
this.max = max;
}
public LogarithmicParameter(String name, String description,
- boolean required, Double defValue, double value, double min,
- double max)
+ boolean required, Double defValue, double value, double min,
+ double max)
{
super(name, description, required, String.valueOf(defValue),
- String.valueOf(value), null, null);
+ String.valueOf(value), null, null);
defval = defValue;
this.min = min;
this.max = max;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import static java.util.Objects.requireNonNull;
+import static java.util.Objects.requireNonNullElse;
public class Option implements OptionI
{
+ /**
+ * A builder class which avoids multiple telescoping parameters nightmare.
+ *
+ * @author mmwarowny
+ *
+ */
+ public static class Builder
+ {
+ protected String name = null;
+
+ protected String label = null;
+
+ protected String description = "";
+
+ protected boolean required = false;
+
+ protected String defaultValue = null;
+
+ protected String value = null;
+
+ protected List<String> possibleValues = null;
+
+ protected List<String> displayValues = null;
+
+ protected URL detailsUrl = null;
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setLabel(String label)
+ {
+ this.label = label;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+
+ public void setRequired(boolean required)
+ {
+ this.required = required;
+ }
+
+ public void setDefaultValue(String defaultValue)
+ {
+ this.defaultValue = defaultValue;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+
+ public void setPossibleValues(List<String> possibleValues)
+ {
+ this.possibleValues = possibleValues;
+ }
+
+ public void setDisplayValues(List<String> displayValues)
+ {
+ this.displayValues = displayValues;
+ }
+
+ public void setDetailsUrl(URL detailsUrl)
+ {
+ this.detailsUrl = detailsUrl;
+ }
+
+ public Option build()
+ {
+ return new Option(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
String name;
String label;
URL fdetails;
+ protected Option(Builder builder)
+ {
+ requireNonNull(builder.name);
+ name = builder.name;
+ label = requireNonNullElse(builder.label, name);
+ description = builder.description;
+ required = builder.required;
+ defvalue = builder.defaultValue;
+ value = builder.value;
+ possibleVals = new ArrayList<>(builder.possibleValues);
+ displayVals = new ArrayList<>(
+ requireNonNullElse(builder.displayValues, possibleVals));
+ fdetails = builder.detailsUrl;
+ }
+
/**
* Copy constructor
*
* @param fdetails
*/
public Option(String name2, String description2, boolean isrequired,
- String defValue, String val, List<String> possibleVals,
- List<String> displayNames, URL fdetails)
+ String defValue, String val, List<String> possibleVals,
+ List<String> displayNames, URL fdetails)
{
name = name2;
description = description2;
* @param fdetails
*/
public Option(String name2, String description2, boolean isrequired,
- String defValue, String val, List<String> possibleVals,
- URL fdetails)
+ String defValue, String val, List<String> possibleVals,
+ URL fdetails)
{
this(name2, description2, isrequired, defValue, val, possibleVals, null,
- fdetails);
+ fdetails);
}
@Override
*/
public class RadioChoiceParameter extends StringParameter
{
+ public static class Builder extends StringParameter.Builder
+ {
+ @Override
+ public RadioChoiceParameter build()
+ {
+ return new RadioChoiceParameter(this);
+ }
+ }
+
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
+ public RadioChoiceParameter(Builder builder)
+ {
+ super(builder);
+ }
/**
* Constructor
* @param def
*/
public RadioChoiceParameter(String name, String description,
- List<String> options, String def)
+ List<String> options, String def)
{
super(name, description, true, def, def, options, null);
}
public class StringParameter extends Option implements ParameterI
{
+ public static class Builder extends Option.Builder
+ {
+ @Override
+ public StringParameter build()
+ {
+ return new StringParameter(this);
+ }
+ }
+
@Override
public ValueConstrainI getValidValue()
{
}
+ public static Builder newBuilder()
+ {
+ return new Builder();
+ }
+
+ protected StringParameter(Builder builder)
+ {
+ super(builder);
+ }
+
public StringParameter(StringParameter parm)
{
this.name = parm.name;
}
public StringParameter(String name, String description, boolean required,
- String defValue)
+ String defValue)
{
super(name, description, required, String.valueOf(defValue), null, null,
- null);
+ null);
this.defvalue = defValue;
}
public StringParameter(String name, String description, boolean required,
- String defValue, String value)
+ String defValue, String value)
{
super(name, description, required, String.valueOf(defValue),
- String.valueOf(value), null, null);
+ String.valueOf(value), null, null);
this.defvalue = defValue;
}
* @param displayNames
*/
public StringParameter(String name2, String description2,
- boolean isrequired, String defValue, String value,
- List<String> possibleVals, List<String> displayNames)
+ boolean isrequired, String defValue, String value,
+ List<String> possibleVals, List<String> displayNames)
{
super(name2, description2, isrequired, defValue, value, possibleVals,
- displayNames, null);
+ displayNames, null);
}
}