Package com.yahoo.protect
Class Validator
- java.lang.Object
-
- com.yahoo.protect.Validator
-
public abstract class Validator extends java.lang.Object
Static utility methods for validating input.
- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description Validator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
ensure(boolean condition, java.lang.Object... description)
Ensure the given argument is true, if not throw IllegalArgumentException concatenating the String representation of the description arguments.static void
ensure(java.lang.String description, boolean condition)
Ensures that the given argument is truestatic void
ensureInRange(java.lang.String argumentDescription, int from, int to, int argument)
Throws an IllegalArgumentException if the given argument is not in the given rangestatic void
ensureInstanceOf(java.lang.String description, java.lang.Object item, java.lang.Class<?> type)
Ensures that an item is of a particular classstatic void
ensureNonEmpty(java.lang.String argumentDescription, java.lang.String argument)
Throws NullPointerException if the argument is nullstatic void
ensureNotInitialized(java.lang.String fieldDescription, java.lang.Object fieldOwner, java.lang.Object fieldValue)
Throws an IllegalStateException if the given field value is initialized (not null)static void
ensureNotNull(java.lang.String argumentDescription, java.lang.Object argument)
Throws NullPointerException if the argument is nullstatic void
ensureSmaller(java.lang.String smallDescription, int small, java.lang.String largeDescription, int large)
Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argumentstatic void
ensureSmaller(java.lang.String smallDescription, java.lang.Comparable small, java.lang.String largeDescription, java.lang.Comparable large)
Throws an IllegalArgumentException if the first argument is not strictly smaller than the second argument
-
-
-
Method Detail
-
ensureNotNull
public static void ensureNotNull(java.lang.String argumentDescription, java.lang.Object argument)
Throws NullPointerException if the argument is null
-
ensureNonEmpty
public static void ensureNonEmpty(java.lang.String argumentDescription, java.lang.String argument)
Throws NullPointerException if the argument is null
-
ensureNotInitialized
public static void ensureNotInitialized(java.lang.String fieldDescription, java.lang.Object fieldOwner, java.lang.Object fieldValue)
Throws an IllegalStateException if the given field value is initialized (not null)
-
ensureInRange
public static void ensureInRange(java.lang.String argumentDescription, int from, int to, int argument)
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(java.lang.String smallDescription, int small, java.lang.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(java.lang.String smallDescription, java.lang.Comparable small, java.lang.String largeDescription, java.lang.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
public static void ensure(java.lang.String description, boolean condition)
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:
java.lang.IllegalArgumentException
- if the given condition was false
-
ensure
public static void ensure(boolean condition, java.lang.Object... description)
Ensure the given argument is true, if not throw IllegalArgumentException concatenating the String representation of the description arguments.
-
ensureInstanceOf
public static void ensureInstanceOf(java.lang.String description, java.lang.Object item, java.lang.Class<?> type)
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:
java.lang.IllegalArgumentException
- if the given item is not of the correct type
-
-