Class DoubleParameter


  • public final class DoubleParameter
    extends Object
    Represents a parameter that should have a double value.
    Author:
    Rob Spoor
    • Method Detail

      • isSet

        public boolean isSet()
        Returns whether or not the parameter is set.
        Returns:
        true if the parameter is set, or false 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 combines atLeast(double) and smallerThan(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 is null.
        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 is null.
        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.