Module com.github.robtimus.servlet
Class DoubleParameter
- java.lang.Object
-
- com.github.robtimus.servlet.parameters.DoubleParameter
-
public final class DoubleParameter extends Object
Represents a parameter that should have a double value.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleParameter
atLeast(double minValue)
Validates that the parameter value is not too small.DoubleParameter
atMost(double maxValue)
Validates that the parameter value is not too large.DoubleParameter
between(double minValue, double maxValue)
Validates that the parameter value is not too small or large.DoubleParameter
greaterThan(double minValue)
Validates that the parameter value is not too small.boolean
isSet()
Returns whether or not the parameter is set.static DoubleParameter
of(FilterConfig config, String name)
Returns a double init parameter for a filter.static DoubleParameter
of(ServletConfig config, String name)
Returns a double init parameter for a servlet.static DoubleParameter
of(ServletContext context, String name)
Returns a double init parameter for a servlet context.static DoubleParameter
of(ServletRequest request, String name)
Returns a double parameter for a servlet request.double
requiredValue()
Returns the parameter value.DoubleParameter
smallerThan(double maxValue)
Validates that the parameter value is not too large.String
toString()
double
valueWithDefault(double defaultValue)
Returns the parameter if it is set.
-
-
-
Method Detail
-
isSet
public boolean isSet()
Returns whether or not the parameter is set.- Returns:
true
if the parameter is set, orfalse
otherwise.
-
requiredValue
public double requiredValue()
Returns the parameter value.- Returns:
- The parameter value.
- Throws:
IllegalStateException
- If the parameter is not set.
-
valueWithDefault
public double valueWithDefault(double defaultValue)
Returns the parameter if it is set.- Parameters:
defaultValue
- The value to return if the parameter is not set.- Returns:
- The parameter value, or the given default value if the parameter is not set.
-
atLeast
public DoubleParameter atLeast(double minValue)
Validates that the parameter value is not too small.- Parameters:
minValue
- The minimum value for the parameter, inclusive.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value is smaller than the given minimum.
-
atMost
public DoubleParameter atMost(double maxValue)
Validates that the parameter value is not too large.- Parameters:
maxValue
- The maximum value for the parameter, inclusive.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value is larger than the given maximum.
-
greaterThan
public DoubleParameter greaterThan(double minValue)
Validates that the parameter value is not too small.- Parameters:
minValue
- The minimum value for the parameter, exclusive.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value is smaller than or equal to the given minimum.
-
smallerThan
public DoubleParameter smallerThan(double maxValue)
Validates that the parameter value is not too large.- Parameters:
maxValue
- The maximum value for the parameter, exclusive.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value is larger than or equal to the given maximum.
-
between
public DoubleParameter between(double minValue, double maxValue)
Validates that the parameter value is not too small or large. This method combinesatLeast(double)
andsmallerThan(double)
.- Parameters:
minValue
- The minimum value for the parameter, inclusive.maxValue
- The maximum value for the parameter, exclusive.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value is not between the given minimum and maximum.
-
of
public static DoubleParameter of(FilterConfig config, String name)
Returns a double init parameter for a filter.- Parameters:
config
- The filter config to read the init parameter from.name
- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given filter config. It may or may not be set.
- Throws:
NullPointerException
- If the given filter config or name isnull
.IllegalStateException
- If the init parameter is set but does not have a double value.
-
of
public static DoubleParameter of(ServletConfig config, String name)
Returns a double init parameter for a servlet.- Parameters:
config
- The servlet config to read the init parameter from.name
- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given servlet config. It may or may not be set.
- Throws:
NullPointerException
- If the given servlet config or name isnull
.IllegalStateException
- If the init parameter is set but does not have a double value.
-
of
public static DoubleParameter of(ServletContext context, String name)
Returns a double init parameter for a servlet context.- Parameters:
context
- The servlet context config to read the init parameter from.name
- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given servlet context. It may or may not be set.
- Throws:
IllegalStateException
- If the init parameter is set but does not have a double value.
-
of
public static DoubleParameter of(ServletRequest request, String name)
Returns a double parameter for a servlet request.- Parameters:
request
- The servlet request to read the parameter from.name
- The name of the parameter.- Returns:
- An object representing the parameter with the given name from the given servlet request. It may or may not be set.
- Throws:
IllegalStateException
- If the parameter is set but does not have a double value.
-
-