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