# Class ArgumentChecks

Object
ArgumentChecks

public final class ArgumentChecks extends Object
Static methods for performing argument checks. Every methods in this class can throw one of the following exceptions:

Exceptions thrown on illegal argument
Exception | Thrown by
--- | ---
`NullPointerException` | `ensureNonNull`, `ensureNonEmpty`.
`IllegalArgumentException` | `ensureNonEmpty`, `ensurePositive`, `ensureStrictlyPositive`, `ensureBetween`, `ensureCountBetween`, `ensureNonEmptyBounded`, `ensureCanCast`.
`MismatchedDimensionException` | `ensureDimensionMatches`.

More specialized `ensureXXX(…)` methods are provided in the following classes:

- `Units`: `ensureAngular`, `ensureLinear`, `ensureTemporal`, `ensureScale`.

## Method Arguments

By convention, the value to check is always the last parameter given to every methods in this class. The other parameters may include the programmatic name of the argument being checked. This programmatic name is used for building an error message localized in the default locale if the check failed.

Since:
  0.3

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `ensureBetween(String name, double min, double max, double value)`
  Ensures that the given floating point value is between the given bounds, inclusive.
  `static void`
  `ensureBetween(String name, float min, float max, float value)`
  Ensures that the given floating point value is between the given bounds, inclusive.
  `static void`
  `ensureBetween(String name, int min, int max, int value)`
  Ensures that the given integer value is between the given bounds, inclusive.
  `static void`
  `ensureBetween(String name, long min, long max, long value)`
  Ensures that the given long value is between the given bounds, inclusive.
  `static void`
  `ensureCanCast(String name, Class<?> expectedType, Object value)`
  Ensures that the specified value is null or an instance assignable to the given type.
  `static void`
  `ensureCountBetween(String name, boolean collection, int min, int max, int count)`
  Ensures that the given number of elements is between the given bounds, inclusive.
  `static void`
  `ensureDimensionMatches(String name, int expected, double[] vector)`
  Ensures that the given vector, if non-null, has the expected number of dimensions (taken as its length).
  `static void`
  `ensureDimensionMatches(String name, int expected, int[] indices)`
  Ensures that the given array of indices, if non-null, has the expected number of dimensions (taken as its length).
  `static void`
  `ensureDimensionMatches(String name, int expected, DirectPosition position)`
  Ensures that the given direct position, if non-null, has the expected number of dimensions.
  `static void`
  `ensureDimensionMatches(String name, int expected, Envelope envelope)`
  Ensures that the given envelope, if non-null, has the expected number of dimensions.
  `static void`
  `ensureDimensionMatches(String name, int expected, CoordinateReferenceSystem crs)`
  Ensures that the given CRS, if non-null, has the expected number of dimensions.
  `static void`
  `ensureDimensionMatches(String name, int expected, CoordinateSystem cs)`
  Ensures that the given coordinate system, if non-null, has the expected number of dimensions.
  `static void`
  `ensureDimensionsMatch(String name, int expectedSource, int expectedTarget, MathTransform transform)`
  Ensures that the given transform, if non-null, has the expected number of source and target dimensions.
  `static void`
  `ensureDivisor(String name, int number, int divisor)`
  Ensures that a given value is a divisor of specified number.
  `static void`
  `ensureFinite(String name, double value)`
  Ensures that the given floating point value is not NaN neither Double.isInfinite(double).
  `static void`
  `ensureFinite(String name, float value)`
  Ensures that the given floating point value is not NaN neither Float.isInfinite(float).
  `static void`
  `ensureMultiple(String name, int number, int multiple)`
  Ensures that a given value is a multiple of specified number.
  `static void`
  `ensureNonEmpty(String name, CharSequence text)`
  Makes sure that a character sequence is non-null and non-empty.
  `static void`
  `ensureNonEmpty(String name, Object[] array)`
  Makes sure that an array is non-null and non-empty.
  `static void`
  `ensureNonEmpty(String name, Collection<?> toCheck)`
  Makes sure that given collection is non-null and non-empty.
  `static void`
  `ensureNonEmpty(String name, Emptiable toCheck)`
  Makes sure that given object is non-null and non-empty.
  `static void`
  `ensureNonEmptyBounded(String name, boolean distinct, int min, int max, int[] values)`
  Ensures that the given `values` array contains at least one element and that all elements are within bounds.
  `static void`
  `ensureNonNull(String name, Object object)`
  Makes sure that an argument is non-null.
  `static void`
  `ensureNonNullElement(String name, int index, Object element)`
  Makes sure that an array element is non-null.
  `static void`
  `ensurePositive(String name, double value)`
  Ensures that the given floating point value is not NaN and is greater than or equals to zero.
  `static void`
  `ensurePositive(String name, float value)`
  Ensures that the given floating point value is not NaN and is greater than or equals to zero.
  `static void`
  `ensurePositive(String name, int value)`
  Ensures that the given integer value is greater than or equals to zero.
  `static void`
  `ensurePositive(String name, long value)`
  Ensures that the given long value is greater than or equals to zero.
  `static void`
  `ensureStrictlyPositive(String name, double value)`
  Ensures that the given floating point value is not NaN and is greater than zero.
  `static void`
  `ensureStrictlyPositive(String name, float value)`
  Ensures that the given floating point value is not NaN and is greater than zero.
  `static void`
  `ensureStrictlyPositive(String name, int value)`
  Ensures that the given integer value is greater than zero.
  `static void`
  `ensureStrictlyPositive(String name, long value)`
  Ensures that the given long value is greater than zero.
  `static void`
  `ensureValidUnicodeCodePoint(String name, int code)`
  Ensures that the given integer is a valid Unicode code point.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### ensureNonNull

    public static void ensureNonNull(String name, Object object) throws NullPointerException
    Makes sure that an argument is non-null. If the given `object` is null, then a `NullPointerException` is thrown with a localized message containing the given name. This method differs from `Objects​.requireNonNull(Object, String)` in that the `String` argument is only the parameter name, not the full exception message.

    #### Suggestions about when to use

    This method is helpful for validating arguments in a method receiving many arguments, when there is a potential ambiguity about which argument is `null`. This method is also useful when the validation is done in a private method invoked by a public method, because it is no longer obvious that a `NullPointerException` is caused by a null argument given to the public method.

    #### Suggestions about when to not use

    When there is no ambiguity, for example in methods receiving a single argument, the standard `Objects​.requireNonNull(Object)` method should be preferred as it is more efficient. Another situation where to not use this method is when an implicit null check would occur early because the argument is used immediately. Since Java 14, the exception thrown by implicit null checks contains sufficiently helpful message.
    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:
      `NullPointerException` - if `object` is null.
    See Also:
      - `Objects​.requireNonNull(Object)`
      - `Objects​.requireNonNull(Object, String)`

  - ### ensureNonNullElement

    public static void ensureNonNullElement(String name, int index, Object element) throws NullPointerException
    Makes sure that an array element is non-null. If `element` is null, then a `NullPointerException` 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:
      `NullPointerException` - if `element` is null.

  - ### ensureNonEmpty

    public static void ensureNonEmpty(String name, CharSequence text) throws NullPointerException, IllegalArgumentException
    Makes sure that a character sequence is non-null and non-empty. If the given `text` is null, then a `NullPointerException` is thrown. Otherwise if the given `text` has a length equals to 0, then an `IllegalArgumentException` is thrown.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `text` - the user argument to check against null value and empty sequences.
    Throws:
      `NullPointerException` - if `text` is null.
      `IllegalArgumentException` - if `text` is empty.

  - ### ensureNonEmpty

    public static void ensureNonEmpty(String name, Object[] array) throws NullPointerException, IllegalArgumentException
    Makes sure that an array is non-null and non-empty. If the given `array` is null, then a `NullPointerException` is thrown. Otherwise if the array length is equal to 0, then an `IllegalArgumentException` is thrown.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `array` - the user argument to check against null value and empty array.
    Throws:
      `NullPointerException` - if `array` is null.
      `IllegalArgumentException` - if `array` is empty.
    Since:
      1.0

  - ### ensureNonEmpty

    public static void ensureNonEmpty(String name, Collection<?> toCheck)
    Makes sure that given collection is non-null and non-empty. If it is null, then a `NullPointerException` is thrown. Otherwise if it is empty, then an `IllegalArgumentException` is thrown.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `toCheck` - the user argument to check against null value and empty collection.
    Throws:
      `NullPointerException` - if `toCheck` is null.
      `IllegalArgumentException` - if `toCheck` is empty.
    Since:
      1.1

  - ### ensureNonEmpty

    public static void ensureNonEmpty(String name, Emptiable toCheck)
    Makes sure that given object is non-null and non-empty. If it is null, then a `NullPointerException` is thrown. Otherwise if it is empty, then an `IllegalArgumentException` is thrown.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `toCheck` - the user argument to check against null value and empty object.
    Throws:
      `NullPointerException` - if `toCheck` is null.
      `IllegalArgumentException` - if `toCheck` is empty.
    Since:
      1.4

  - ### ensureNonEmptyBounded

    public static void ensureNonEmptyBounded(String name, boolean distinct, int min, int max, int[] values) throws IllegalArgumentException
    Ensures that the given `values` array contains at least one element and that all elements are within bounds. The minimum and maximum values are inclusive. Optionaly, this method can also ensure that all values are distinct.

    Note that a successful call to `ensureNonEmptyBounded(name, true, 0, max, values)` implies 1 ≤ `values​.length` ≤ `max`.

    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `distinct` - `true` if each value must be unique.
      `min` - the minimal allowed value (inclusive), or `Integer​.MIN_VALUE` if none.
      `max` - the maximal allowed value (inclusive), or `Integer​.MAX_VALUE` if none.
      `values` - integer values to validate.
    Throws:
      `NullPointerException` - if `values` is null.
      `IllegalArgumentException` - 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.4

  - ### 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 cast to the class represented by `expectedType` without throwing a `ClassCastException`.
    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.
      `expectedType` - the expected type (class or interface).
      `value` - the value to check, or `null`.
    Throws:
      `IllegalArgumentException` - if `value` is non-null and is not assignable to the given type.
    See Also:
      - `Containers​.property(Map, Object, Class)`

  - ### ensurePositive

    public static void ensurePositive(String name, int value) throws IllegalArgumentException
    Ensures that the given integer value is greater than or equals to zero. This method is used for checking values that are not index. For checking index values, use
    invalid reference

        Objects#checkIndex(int, int)

    instead.
    Parameters:
      `name` - the name of the argument to be checked, used only if an exception is thrown.
      `value` - the user argument to check.
    Throws:
      `IllegalArgumentException` - if the given value is negative.
    See Also:
      - `ensureStrictlyPositive(String, int)`

  - ### ensurePositive

    public static void ensurePositive(String name, long value) throws IllegalArgumentException
    Ensures that the given long value is greater than or equals to 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:
      `IllegalArgumentException` - if the given value is negative.
    See Also:
      - `ensureStrictlyPositive(String, long)`

  - ### ensurePositive

    public static void ensurePositive(String name, float value) throws IllegalArgumentException
    Ensures that the given floating point value is not NaN and is greater than or equals to zero. Note that positive infinity is considered a valid value.
    Parameters:
      `name` - the name of the argument to be checked, used only if an exception is thrown.
      `value` - the user argument to check.
    Throws:
      `IllegalArgumentException` - if the given value is NaN or negative.
    See Also:
      - `ensureStrictlyPositive(String, float)`

  - ### ensurePositive

    public static void ensurePositive(String name, double value) throws IllegalArgumentException
    Ensures that the given floating point value is not NaN and is greater than or equals to zero. Note that positive infinity is considered a valid value.
    Parameters:
      `name` - the name of the argument to be checked, used only if an exception is thrown.
      `value` - the user argument to check.
    Throws:
      `IllegalArgumentException` - if the given value is NaN or negative.
    See Also:
      - `ensureStrictlyPositive(String, double)`

  - ### 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:
      `IllegalArgumentException` - if the given value is negative or equals to zero.
    See Also:
      - `ensurePositive(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:
      `IllegalArgumentException` - if the given value is negative or equals to zero.
    See Also:
      - `ensurePositive(String, long)`

  - ### ensureStrictlyPositive

    public static void ensureStrictlyPositive(String name, float value) throws IllegalArgumentException
    Ensures that the given floating point value is not NaN and is greater than zero. Note that positive infinity is considered a valid value.
    Parameters:
      `name` - the name of the argument to be checked, used only if an exception is thrown.
      `value` - the user argument to check.
    Throws:
      `IllegalArgumentException` - if the given value is NaN, zero or negative.
    See Also:
      - `ensurePositive(String, float)`

  - ### ensureStrictlyPositive

    public static void ensureStrictlyPositive(String name, double value) throws IllegalArgumentException
    Ensures that the given floating point value is not NaN and is greater than zero. Note that positive infinity is considered a valid value.
    Parameters:
      `name` - the name of the argument to be checked, used only if an exception is thrown.
      `value` - the user argument to check.
    Throws:
      `IllegalArgumentException` - if the given value is NaN, zero or negative.
    See Also:
      - `ensurePositive(String, double)`

  - ### 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:
      `IllegalArgumentException` - 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:
      `IllegalArgumentException` - if the given value is NaN or infinite.

  - ### ensureBetween

    public static void ensureBetween(String name, int min, int max, int value) throws IllegalArgumentException
    Ensures that the given integer value is between the given bounds, inclusive. This is a general-purpose method for checking integer arguments. Note that the following specialized methods are provided for common kinds of integer range checks:
    - `ensureCountBetween(…)` if the `value` argument is a collection size or an array length.
    - invalid reference

          Objects#checkIndex(int, int)

      if the `value` argument is an index in a list or an array.
    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:
      `IllegalArgumentException` - if the given value is not in the given range.
    See Also:
      - `ensureCountBetween(String, boolean, int, int, int)`

  - ### 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:
      `IllegalArgumentException` - 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:
      `IllegalArgumentException` - 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:
      `IllegalArgumentException` - if the given value is NaN or not in the given range.

  - ### ensureCountBetween

    public static void ensureCountBetween(String name, boolean collection, int min, int max, int count) throws IllegalArgumentException
    Ensures that the given number of elements is between the given bounds, inclusive. This method performs the same check as `ensureBetween(…)`, but the error message is different in case of failure.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `collection` - `true` if `name` is a collection, or `false` for a variable argument list.
      `min` - the minimal size (inclusive), or 0 if none.
      `max` - the maximal size (inclusive), or `Integer​.MAX_VALUE` if none.
      `count` - the number of user-specified arguments, collection size or array length to be checked.
    Throws:
      `IllegalArgumentException` - if the given value is not in the given range.
    Since:
      1.4
    See Also:
      - `ensureBetween(String, int, int, int)`

  - ### 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:
      `IllegalArgumentException` - if the given value is not a valid Unicode code point.
    Since:
      0.4

  - ### ensureDivisor

    public static void ensureDivisor(String name, int number, int divisor)
    Ensures that a given value is a divisor of specified number. This method verifies that `(number % divisor) == 0`. If above condition is not met, the value considered to be wrong is the divisor.
    Parameters:
      `name` - name of the argument for the divisor value. Used only if an exception is thrown.
      `number` - the number to be divided.
      `divisor` - the value to verify.
    Throws:
      `IllegalArgumentException` - if `(number % divisor) != 0`.
      `ArithmeticException` - if `divisor == 0`.
    Since:
      1.1

  - ### ensureMultiple

    public static void ensureMultiple(String name, int number, int multiple)
    Ensures that a given value is a multiple of specified number. This method verifies that `(multiple % number) == 0`. If above condition is not met, the value considered to be wrong is the multiple.
    Parameters:
      `name` - name of the argument for the multiple value. Used only if an exception is thrown.
      `number` - the number to be multiplied.
      `multiple` - the value to verify.
    Throws:
      `IllegalArgumentException` - if `(multiple % number) != 0`.
      `ArithmeticException` - if `number == 0`.
    Since:
      1.1

  - ### 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:
      `MismatchedDimensionException` - 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:
      `MismatchedDimensionException` - 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:
      `MismatchedDimensionException` - 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:
      `MismatchedDimensionException` - 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:
      `MismatchedDimensionException` - 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:
      `MismatchedDimensionException` - if the given envelope is non-null and does not have the expected number of dimensions.

  - ### ensureDimensionsMatch

    public static void ensureDimensionsMatch(String name, int expectedSource, int expectedTarget, MathTransform transform) throws MismatchedDimensionException
    Ensures that the given transform, if non-null, has the expected number of source and target dimensions. This method does nothing if the given transform is null.
    Parameters:
      `name` - the name of the argument to be checked. Used only if an exception is thrown.
      `expectedSource` - the expected number of source dimensions.
      `expectedTarget` - the expected number of target dimensions.
      `transform` - the transform to check for its dimension, or `null`.
    Throws:
      `MismatchedDimensionException` - if the given transform is non-null and does not have the expected number of dimensions.
    Since:
      1.1