Package pcap.common.util
Class Validate
java.lang.Object
pcap.common.util.Validate
@Inclubating public final class Validate extends Object
- Author:
- Ardika Rommy Sanjaya
-
Constructor Summary
Constructors Constructor Description Validate()
-
Method Summary
Modifier and Type Method Description static void
notIllegalArgument(boolean expression)
Ensures the truth of an expression involving one or more parameters to the calling method.static void
notIllegalArgument(boolean expression, String message)
Ensures the truth of an expression involving one or more parameters to the calling method.static <T> T
notIllegalArgumentThenReturns(boolean expression, T reference, T newVal)
Ensures the truth of an expression involving one or more parameters to the calling method.static void
notInBounds(byte[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(char[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(double[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(float[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(int[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(int size, int offset, int length)
Ensures that given parameter is valid bound.static void
notInBounds(long[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notInBounds(short[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static <T> void
notInBounds(T[] array, int offset, int length)
Ensures that given parameter is valid bound in an array.static void
notNumeric(String text)
Deprecated.static <T> void
nullPointer(T reference)
Ensures that given object $reference
is not null.static <T> void
nullPointer(T reference, String message)
Ensures that given object $reference
is not null.static <T> T
nullPointerThenReturns(T reference, T newVal)
Ensures that given object $reference
is not null.
-
Constructor Details
-
Validate
public Validate()
-
-
Method Details
-
nullPointer
Ensures that given object $reference
is not null.- Type Parameters:
T
- object reference type.- Parameters:
reference
- object reference.message
- exceptions message to be given.- Throws:
NullPointerException
- ifreference
is null.- Since:
- 1.0.0
-
nullPointer
Ensures that given object $reference
is not null.- Type Parameters:
T
- object reference type.- Parameters:
reference
- object reference.- Throws:
NullPointerException
- ifreference
is null.- Since:
- 1.0.0
-
nullPointerThenReturns
public static <T> T nullPointerThenReturns(T reference, T newVal)Ensures that given object $reference
is not null.- Type Parameters:
T
- object reference and new value type.- Parameters:
reference
- object reference.newVal
- new value.- Returns:
- returns given $
newVal
ifreference
is null,reference
otherwise. - Since:
- 1.0.0
-
notIllegalArgumentThenReturns
public static <T> T notIllegalArgumentThenReturns(boolean expression, T reference, T newVal)Ensures the truth of an expression involving one or more parameters to the calling method. Returns given $newVal
ifexpression
is false,reference
otherwise.- Type Parameters:
T
- type of reference and new value.- Parameters:
expression
- a boolean expression.reference
- reference.newVal
- new value.- Returns:
- returns given $
newVal
ifexpression
is false,reference
otherwise. - Since:
- 1.0.0
-
notIllegalArgument
public static void notIllegalArgument(boolean expression, String message) throws IllegalArgumentExceptionEnsures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression
- a boolean expression.message
- exceptions message to be given- Throws:
IllegalArgumentException
- ifexpression
is false- Since:
- 1.0.0
-
notIllegalArgument
Ensures the truth of an expression involving one or more parameters to the calling method.- Parameters:
expression
- a boolean expression.- Throws:
IllegalArgumentException
- ifexpression
is false- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(byte[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(char[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(short[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(int[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(float[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(long[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static void notInBounds(double[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
public static <T> void notInBounds(T[] array, int offset, int length) throws NullPointerException, IllegalArgumentException, ArrayIndexOutOfBoundsExceptionEnsures that given parameter is valid bound in an array.- Type Parameters:
T
- array type.- Parameters:
array
- array.offset
- offset.length
- length.- Throws:
NullPointerException
- ifarray
is null.IllegalArgumentException
- invalid parameters.ArrayIndexOutOfBoundsException
- invalid parameters.- Since:
- 1.0.0
-
notInBounds
Ensures that given parameter is valid bound.- Parameters:
size
- size.offset
- offset.length
- length.- Throws:
IllegalArgumentException
- illegal argement exception.- Since:
- 1.1.0
-
notNumeric
Deprecated.Ensures that given parameter is not contains non numeric character.- Parameters:
text
- test.- Throws:
IllegalArgumentException
- illegal argument exception.
-