Class ArgumentChecks

    • Method Detail

      • ensureNonNull

        public static void ensureNonNull​(String name,
                                         Object object)
                                  throws NullArgumentException
        Makes sure that an argument is non-null. If the given object is null, then a Null­Argument­Exception is thrown with a localized message containing the given name.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        object - the user argument to check against null value.
        Throws:
        Null­Argument­Exception - if object is null.
      • ensureNonNullElement

        public static void ensureNonNullElement​(String name,
                                                int index,
                                                Object element)
                                         throws NullArgumentException
        Makes sure that an array element is non-null. If element is null, then a Null­Argument­Exception is thrown with a localized message containing the given name and index. The name and index are formatted as below:
        • If the name contains the "[#]" sequence of characters, then the '#' character is replaced by the index value. For example if name is "axes[#].unit" and the index is 2, then the formatted message will contain "axes[2].unit".
        • If the name does not contain the "[#]" sequence of characters, then index value is appended between square brackets. For example if name is "axes" and the index is 2, then the formatted message will contain "axes[2]".
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        index - the Index of the element to check in an array or a list. Used only if an exception is thrown.
        element - the array or list element to check against null value.
        Throws:
        Null­Argument­Exception - if element is null.
      • ensureNonEmpty

        public static void ensureNonEmpty​(String name,
                                          int[] values,
                                          int min,
                                          int max,
                                          boolean distinct)
                                   throws IllegalArgumentException
        Ensures that the given values array is non-null and non-empty. This method can also ensures that all values are between the given bounds (inclusive) and are distinct. The distinct values requirement is useful for validating arrays of spatiotemporal dimension indices, where dimensions can not be repeated.

        Note that a successful call to ensure­Non­Empty(name, values, 0, max, true) implies 1 ≦ values​.lengthmax.

        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        values - integer values to validate.
        min - the minimal allowed value (inclusive), or Integer​.MIN_VALUE if none.
        max - the maximal allowed value (inclusive), or Integer​.MAX_VALUE if none.
        distinct - true if each value must be unique.
        Throws:
        Null­Argument­Exception - if values is null.
        Illegal­Argument­Exception - if values is empty, contains a value lower than min, contains a value greater than max, or contains duplicated values while distinct is true.
        Since:
        1.0
      • ensureExpectedCount

        public static void ensureExpectedCount​(String name,
                                               int expected,
                                               int actual)
        Ensures that a method receiving a variable number of arguments got the expected count. If actual = expected, then this method does nothing. Otherwise a message saying "Too few" or "Too many arguments" is thrown.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - expected number of arguments.
        actual - actual number of arguments.
        Since:
        1.0
      • ensureCanCast

        public static void ensureCanCast​(String name,
                                         Class<?> expectedType,
                                         Object value)
                                  throws IllegalArgumentException
        Ensures that the specified value is null or an instance assignable to the given type. If this method does not thrown an exception, then the value can be casted to the class represented by expected­Type without throwing a Class­Cast­Exception.
        Parameters:
        name - the name of the argument to be checked, used only if an exception is thrown. Can be null if the name is unknown.
        expected­Type - the expected type (class or interface).
        value - the value to check, or null.
        Throws:
        Illegal­Argument­Exception - if value is non-null and is not assignable to the given type.
        See Also:
        Containers​.property(Map, Object, Class)
      • ensureValidIndex

        public static void ensureValidIndex​(int upper,
                                            int index)
                                     throws IndexOutOfBoundsException
        Ensures that the given index is equals or greater than zero and lower than the given upper value. This method is designed for methods that expect an index value as the only argument. For this reason, this method does not take the argument name.
        Parameters:
        upper - the maximal index value, exclusive.
        index - the index to check.
        Throws:
        Index­Out­Of­Bounds­Exception - if the given index is negative or not lower than the given upper value.
        See Also:
        ensure­Positive(String, int)
      • ensureValidIndexRange

        public static void ensureValidIndexRange​(int length,
                                                 int lower,
                                                 int upper)
                                          throws IndexOutOfBoundsException
        Ensures that the given index range is valid for a sequence of the given length. This method is designed for methods that expect an index range as their only arguments. For this reason, this method does not take argument names.

        This method verifies only the lower and upper argument values. It does not not verify the validity of the length argument, because this information is assumed to be provided by the implementation rather than the user.

        Parameters:
        length - the length of the sequence (array, Char­Sequence, etc.).
        lower - the user-specified lower index, inclusive.
        upper - the user-specified upper index, exclusive.
        Throws:
        Index­Out­Of­Bounds­Exception - if the given [lowerupper] range is out of the sequence index range.
        See Also:
        ensure­Size­Between(String, int, int, int)
      • ensureStrictlyPositive

        public static void ensureStrictlyPositive​(String name,
                                                  int value)
                                           throws IllegalArgumentException
        Ensures that the given integer value is greater than zero.
        Parameters:
        name - the name of the argument to be checked, used only if an exception is thrown.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is negative or equals to zero.
        See Also:
        ensure­Positive(String, int)
      • ensureStrictlyPositive

        public static void ensureStrictlyPositive​(String name,
                                                  long value)
                                           throws IllegalArgumentException
        Ensures that the given long value is greater than zero.
        Parameters:
        name - the name of the argument to be checked, used only if an exception is thrown.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is negative or equals to zero.
        See Also:
        ensure­Positive(String, long)
      • ensureFinite

        public static void ensureFinite​(String name,
                                        float value)
        Ensures that the given floating point value is not NaN neither Float.isInfinite(float). The value can be negative, zero or positive.
        Parameters:
        name - the name of the argument to be checked, used only if an exception is thrown.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is NaN or infinite.
      • ensureFinite

        public static void ensureFinite​(String name,
                                        double value)
        Ensures that the given floating point value is not NaN neither Double.isInfinite(double). The value can be negative, zero or positive.
        Parameters:
        name - the name of the argument to be checked, used only if an exception is thrown.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is NaN or infinite.
      • ensureBetween

        public static void ensureBetween​(String name,
                                         long min,
                                         long max,
                                         long value)
                                  throws IllegalArgumentException
        Ensures that the given long value is between the given bounds, inclusive.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        min - the minimal value, inclusive.
        max - the maximal value, inclusive.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is not in the given range.
      • ensureBetween

        public static void ensureBetween​(String name,
                                         float min,
                                         float max,
                                         float value)
                                  throws IllegalArgumentException
        Ensures that the given floating point value is between the given bounds, inclusive.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        min - the minimal value, inclusive.
        max - the maximal value, inclusive.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is NaN or not in the given range.
      • ensureBetween

        public static void ensureBetween​(String name,
                                         double min,
                                         double max,
                                         double value)
                                  throws IllegalArgumentException
        Ensures that the given floating point value is between the given bounds, inclusive.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        min - the minimal value, inclusive.
        max - the maximal value, inclusive.
        value - the user argument to check.
        Throws:
        Illegal­Argument­Exception - if the given value is NaN or not in the given range.
      • ensureValidUnicodeCodePoint

        public static void ensureValidUnicodeCodePoint​(String name,
                                                       int code)
                                                throws IllegalArgumentException
        Ensures that the given integer is a valid Unicode code point. The range of valid code points goes from U+0000 to U+10FFFF inclusive.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        code - the Unicode code point to verify.
        Throws:
        Illegal­Argument­Exception - if the given value is not a valid Unicode code point.
        Since:
        0.4
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  CoordinateReferenceSystem crs)
                                           throws MismatchedDimensionException
        Ensures that the given CRS, if non-null, has the expected number of dimensions. This method does nothing if the given coordinate reference system is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        crs - the coordinate reference system to check for its dimension, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given coordinate reference system is non-null and does not have the expected number of dimensions.
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  CoordinateSystem cs)
                                           throws MismatchedDimensionException
        Ensures that the given coordinate system, if non-null, has the expected number of dimensions. This method does nothing if the given coordinate system is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        cs - the coordinate system to check for its dimension, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given coordinate system is non-null and does not have the expected number of dimensions.
        Since:
        0.6
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  int[] indices)
                                           throws MismatchedDimensionException
        Ensures that the given array of indices, if non-null, has the expected number of dimensions (taken as its length). This method does nothing if the given array is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        indices - the array of indices to check for its number of dimensions, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given array of indices is non-null and does not have the expected number of dimensions (taken as its length).
        Since:
        1.0
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  double[] vector)
                                           throws MismatchedDimensionException
        Ensures that the given vector, if non-null, has the expected number of dimensions (taken as its length). This method does nothing if the given vector is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        vector - the vector to check for its number of dimensions, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given vector is non-null and does not have the expected number of dimensions (taken as its length).
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  DirectPosition position)
                                           throws MismatchedDimensionException
        Ensures that the given direct position, if non-null, has the expected number of dimensions. This method does nothing if the given direct position is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        position - the direct position to check for its dimension, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given direct position is non-null and does not have the expected number of dimensions.
      • ensureDimensionMatches

        public static void ensureDimensionMatches​(String name,
                                                  int expected,
                                                  Envelope envelope)
                                           throws MismatchedDimensionException
        Ensures that the given envelope, if non-null, has the expected number of dimensions. This method does nothing if the given envelope is null.
        Parameters:
        name - the name of the argument to be checked. Used only if an exception is thrown.
        expected - the expected number of dimensions.
        envelope - the envelope to check for its dimension, or null.
        Throws:
        Mismatched­Dimension­Exception - if the given envelope is non-null and does not have the expected number of dimensions.