Package com.yahoo.protect
Class Validator
java.lang.Object
com.yahoo.protect.Validator
Static utility methods for validating input.
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Ensure the given argument is true, if not throw IllegalArgumentException concatenating the String representation of the description arguments.static void
Ensures that the given argument is truestatic void
ensureInRange
(String argumentDescription, int from, int to, int argument) Throws an IllegalArgumentException if the given argument is not in the given rangestatic void
ensureInstanceOf
(String description, Object item, Class<?> type) Ensures that an item is of a particular classstatic void
ensureNonEmpty
(String argumentDescription, String argument) Throws NullPointerException if the argument is nullstatic void
ensureNotInitialized
(String fieldDescription, Object fieldOwner, Object fieldValue) Throws an IllegalStateException if the given field value is initialized (not null)static void
ensureNotInstanceOf
(String description, Object item, Class<?> type) Ensures that an item is not of a particular classstatic void
ensureNotNull
(String argumentDescription, Object argument) Throws NullPointerException if the argument is nullstatic void
ensureSmaller
(String smallDescription, int small, String largeDescription, int large) Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argumentstatic void
ensureSmaller
(String smallDescription, Comparable small, String largeDescription, Comparable large) Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argument
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
ensureNotNull
Throws NullPointerException if the argument is null -
ensureNonEmpty
Throws NullPointerException if the argument is null -
ensureNotInitialized
public static void ensureNotInitialized(String fieldDescription, Object fieldOwner, Object fieldValue) Throws an IllegalStateException if the given field value is initialized (not null) -
ensureInRange
Throws an IllegalArgumentException if the given argument is not in the given range- Parameters:
argumentDescription
- a description of the argumentfrom
- the range start, inclusiveto
- the range end, inclusiveargument
- the argument value to check
-
ensureSmaller
public static void ensureSmaller(String smallDescription, int small, String largeDescription, int large) Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argument- Parameters:
smallDescription
- description of the smallest argumentsmall
- the smallest argumentlargeDescription
- description of the lergest argumentlarge
- the largest argument
-
ensureSmaller
public static void ensureSmaller(String smallDescription, Comparable small, String largeDescription, Comparable large) Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argument- Parameters:
smallDescription
- description of the smallest argumentsmall
- the smallest argumentlargeDescription
- description of the largest argumentlarge
- the largest argument
-
ensure
Ensures that the given argument is true- Parameters:
description
- of what is the case if the condition is falsecondition
- the condition to ensure is true- Throws:
IllegalArgumentException
- if the given condition was false
-
ensure
Ensure the given argument is true, if not throw IllegalArgumentException concatenating the String representation of the description arguments. -
ensureInstanceOf
Ensures that an item is of a particular class- Parameters:
description
- a description of the item to be checkeditem
- the item to check the type oftype
- the type the given item should be instanceof- Throws:
IllegalArgumentException
- if the given item is not of the correct type
-
ensureNotInstanceOf
Ensures that an item is not of a particular class- Parameters:
description
- a description of the item to be checkeditem
- the item to check the type oftype
- the type the given item should NOT be instanceof- Throws:
IllegalArgumentException
- if the given item is of the wrong type
-