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