java.lang.Object
org.cicirello.util.ArrayLengthEnforcer
Utility class for checking and enforcing that an array has a length equal to a target length.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean[]enforce(boolean[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static byte[]enforce(byte[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static char[]enforce(char[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static double[]enforce(double[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static float[]enforce(float[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static int[]enforce(int[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static long[]enforce(long[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.static short[]enforce(short[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.
-
Method Details
-
enforce
public static int[] enforce(int[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static long[] enforce(long[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static short[] enforce(short[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static byte[] enforce(byte[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static double[] enforce(double[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static float[] enforce(float[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static char[] enforce(char[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-
enforce
public static boolean[] enforce(boolean[] array, int targetLength) Validates the length of an array and that it is non-null, checking that it is equal to a specified target length.- Parameters:
array- The array to check.targetLength- The target length.- Returns:
- The original array if it is non-null and length equal to the targetLength, and otherwise returns a new array of the targetLength.
-