package jalview.ws.params.simple;
+import static java.util.Objects.requireNonNullElse;
+
import jalview.ws.params.ParameterI;
import jalview.ws.params.ValueConstrainI;
* logarithmic scale
*
* @author TZVanaalten
- *
*/
public class LogarithmicParameter extends Option implements ParameterI
{
- public static final double LOGSLIDERSCALE = 1000000D;
+ 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 max;
- final double base;
-
@Override
public ValueConstrainI getValidValue()
{
};
}
+ 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);
max = parm.max;
min = parm.min;
defval = 0D;
- base = parm.base;
}
public LogarithmicParameter(String name, String description,
- boolean required, double defValue, double min, double max,
- double base)
+ boolean required, Double defValue, double min, double max)
{
super(name, description, required, String.valueOf(defValue), null, null,
- null);
+ null);
defval = defValue;
- this.min = min;// * LOGSLIDERSCALE;
- this.max = max;// * LOGSLIDERSCALE;
- this.base = base;
+ this.min = min;
+ this.max = max;
}
public LogarithmicParameter(String name, String description,
- boolean required, double defValue, double value, double min,
- double max, double base)
+ 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;// * LOGSLIDERSCALE;
- this.max = max;// * LOGSLIDERSCALE;
- this.base = base;
+ this.min = min;
+ this.max = max;
}
@Override
{
return new LogarithmicParameter(this);
}
-
- public double getBase()
- {
- return base;
- }
}