Package htsjdk.utils
Class ValidationUtils
- java.lang.Object
-
- htsjdk.utils.ValidationUtils
-
public class ValidationUtils extends Object
Simple functions that streamline the checking of values.
-
-
Constructor Summary
Constructors Constructor Description ValidationUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isNonEmpty(Collection<?> collection)
Checks that aCollection
is notnull
and that it is not empty.static String
nonEmpty(String string)
Checks that aString
is notnull
and that it is not empty.static String
nonEmpty(String string, String nameOfObject)
Checks that aString
is notnull
and that it is not empty.static <I,T extends Collection<I>>
TnonEmpty(T collection)
Checks that aCollection
is notnull
and that it is not empty.static <T extends Collection<?>>
TnonEmpty(T collection, String nameOfObject)
Checks that aCollection
is notnull
and that it is not empty.static <T> T
nonNull(T object)
Checks that an Objectobject
is not null and returns the same object or throws anIllegalArgumentException
static <T> T
nonNull(T object, String nameOfObject)
static <T> T
nonNull(T object, Supplier<String> message)
static void
validateArg(boolean condition, String msg)
static void
validateArg(boolean condition, Supplier<String> msg)
-
-
-
Method Detail
-
nonNull
public static <T> T nonNull(T object)
Checks that an Objectobject
is not null and returns the same object or throws anIllegalArgumentException
- Parameters:
object
- any Object- Returns:
- the same object
- Throws:
IllegalArgumentException
- if ao == null
-
nonNull
public static <T> T nonNull(T object, String nameOfObject)
- Parameters:
object
- any ObjectnameOfObject
- the name of the object that is being checked for null. ( is used in the exception thrown wheno == null
.)- Returns:
- the same object
- Throws:
IllegalArgumentException
- if ao == null
-
nonNull
public static <T> T nonNull(T object, Supplier<String> message)
- Parameters:
object
- any Objectmessage
- the text message that would be passed to the exception thrown wheno == null
.- Returns:
- the same object
- Throws:
IllegalArgumentException
- if ao == null
-
nonEmpty
public static <T extends Collection<?>> T nonEmpty(T collection, String nameOfObject)
Checks that aCollection
is notnull
and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws anIllegalArgumentException
- Parameters:
collection
- any CollectionnameOfObject
- the name of the object that is being checked for non-emptiness. ( is used in the exception thrown wheno.isEmpty()
.)- Returns:
- the original collection
- Throws:
IllegalArgumentException
- if collection is null or empty
-
isNonEmpty
public static boolean isNonEmpty(Collection<?> collection)
Checks that aCollection
is notnull
and that it is not empty. If it's non-null and non-empty it returns the true- Parameters:
collection
- any Collection- Returns:
- true if the collection exists and has elements
-
nonEmpty
public static String nonEmpty(String string, String nameOfObject)
Checks that aString
is notnull
and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws anIllegalArgumentException
- Parameters:
string
- any StringnameOfObject
- a message to include in the output- Returns:
- the original string
- Throws:
IllegalArgumentException
- if string is null or empty
-
nonEmpty
public static String nonEmpty(String string)
Checks that aString
is notnull
and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws anIllegalArgumentException
- Parameters:
string
- any String- Returns:
- the original string
- Throws:
IllegalArgumentException
- if string is null or empty
-
nonEmpty
public static <I,T extends Collection<I>> T nonEmpty(T collection)
Checks that aCollection
is notnull
and that it is not empty. If it's non-null and non-empty it returns the input, otherwise it throws anIllegalArgumentException
- Parameters:
collection
- any Collection- Returns:
- the original collection
- Throws:
IllegalArgumentException
- if collection is null or empty
-
validateArg
public static void validateArg(boolean condition, String msg)
-
-