Module com.github.robtimus.servlet
Class IntParameter
- java.lang.Object
-
- com.github.robtimus.servlet.parameters.IntParameter
-
public final class IntParameter extends Object
Represents a parameter that should have an int value.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IntParameter
atLeast(int minValue)
Validates that the parameter value is not too small.IntParameter
atMost(int maxValue)
Validates that the parameter value is not too large.IntParameter
between(int minValue, int maxValue)
Validates that the parameter value is not too small or large.IntParameter
greaterThan(int minValue)
Validates that the parameter value is not too small.boolean
isSet()
Returns whether or not the parameter is set.static IntParameter
of(FilterConfig config, String name)
Returns an int init parameter for a filter.static IntParameter
of(ServletConfig config, String name)
Returns an int init parameter for a servlet.static IntParameter
of(ServletContext context, String name)
Returns an int init parameter for a servlet context.static IntParameter
of(ServletRequest request, String name)
Returns an int parameter for a servlet request.int
requiredValue()
Returns the parameter value.IntParameter
smallerThan(int maxValue)
Validates that the parameter value is not too large.String
toString()
int
valueWithDefault(int 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 int requiredValue()
Returns the parameter value.- Returns:
- The parameter value.
- Throws:
IllegalStateException
- If the parameter is not set.
-
valueWithDefault
public int valueWithDefault(int 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 IntParameter atLeast(int 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 IntParameter atMost(int 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 IntParameter greaterThan(int 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 IntParameter smallerThan(int 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 IntParameter between(int minValue, int maxValue)
Validates that the parameter value is not too small or large. This method combinesatLeast(int)
andsmallerThan(int)
.- 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 IntParameter of(FilterConfig config, String name)
Returns an int 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 an int value.
-
of
public static IntParameter of(ServletConfig config, String name)
Returns an int 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 an int value.
-
of
public static IntParameter of(ServletContext context, String name)
Returns an int 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 an int value.
-
of
public static IntParameter of(ServletRequest request, String name)
Returns an int 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 an int value.
-
-