Class ArgChecks
java.lang.Object
org.hansken.plugin.extraction.util.ArgChecks
A collection of methods for defensively checking arguments passed to methods.
- 
Method SummaryModifier and TypeMethodDescriptionstatic Object[]argNotAllNull(String name, Object... values) Check that not all values with given name arenull, otherwise throw an exception.static StringargNotEmpty(String name, String value) Check that the string with given name is notnullor empty, otherwise throw an exception.static <T> Collection<T> argNotEmpty(String name, Collection<T> value) Check that the collection value with given name is not empty, otherwise throw an exception.static <T> T[]argNotEmpty(String name, T[] value) Check that the array value with given name is not empty, otherwise throw an exception.static floatargNotNegative(String name, float value) Check that the float with given name is not negative, otherwise throw an exception.static intargNotNegative(String name, int value) Check that the int with given name is not negative, otherwise throw an exception.static longargNotNegative(String name, long value) Check that the long with given name is not negative, otherwise throw an exception.static <T> TargNotNull(String name, T value) Check that the value with given name is notnull, otherwise throw an exception.static <T> List<T> argsIsType(String name, List<T> value, Class<?> type) Check that the value with given name is of typetype, otherwise throw an exception.
- 
Method Details- 
argNotNullCheck that the value with given name is notnull, otherwise throw an exception.Example usage: private final Author author; public Book(final Author author) { // this throws a NullPointerException when the author is null this.author = argNotNull("author", author); }- Type Parameters:
- T- the type of the value
- Parameters:
- name- a descriptive name for the value (most likely the argument name)
- value- the value itself
- Returns:
- the value, so it can be used to inline in an assignment
- Throws:
- NullPointerException- if- value == null
 
- 
argsIsTypeCheck that the value with given name is of typetype, otherwise throw an exception.Example usage: public Book(final List<Object> authors) { // this throws a ClassCastException when authors contains a type other than Author.class argsIsType("author", authors, Author.class); }- Type Parameters:
- T- the type of the value
- Parameters:
- name- a descriptive name for the value (most likely the argument name)
- value- the value itself
- type- the class type we want to check against- value
- Returns:
- the value, so it can be used to inline in an assignment
- Throws:
- ClassCastException- if- value.allMatch(type::isInstance)is false
 
- 
argNotAllNullCheck that not all values with given name arenull, otherwise throw an exception.Example usage: private final Author author; public Book(final Author... authors) { // this throws a NullPointerException when the author is null this.author = argNotAllNull("authors", authors); }- Parameters:
- name- a descriptive name for the values (most likely the argument name)
- values- the values, which can be different types
- Returns:
- the values, so it can be used to inline in an assignment
- Throws:
- NullPointerException- if- values.allMatch(Objects::isNull)
 
- 
argNotEmptyCheck that the array value with given name is not empty, otherwise throw an exception.Example usage: private final Author[] author; public Book(final Author[] author) { // this throws a NullPointerException when the author array is empty this.author = argNotEmpty("author", author); }- Type Parameters:
- T- the type of the value
- Parameters:
- name- a descriptive name for the value (most likely the argument name)
- value- the value itself
- Returns:
- the value, so it can be used to inline in an assignment
- Throws:
- IllegalArgumentException- if- value == null || value.length == 0
 
- 
argNotEmptyCheck that the collection value with given name is not empty, otherwise throw an exception.Example usage: private final Collection<Author> author; public Book(final Collection<Author> author) { // this throws a NullPointerException when the author collection is empty this.author = argNotEmpty("author", author); }- Type Parameters:
- T- the type of the value
- Parameters:
- name- a descriptive name for the value (most likely the argument name)
- value- the value itself
- Returns:
- the value, so it can be used to inline in an assignment
- Throws:
- IllegalArgumentException- if- value == null || value.isEmpty()
 
- 
argNotEmptyCheck that the string with given name is notnullor empty, otherwise throw an exception.Example usage: private final String title; public Book(final String title) { // this throws a NullPointerException when the author is null // or an IllegalArgumentException when author is an empty String this.title = argNotEmpty("title", title); }- Parameters:
- name- a descriptive name for the string (most likely the argument name)
- value- the string itself
- Returns:
- the string, so it can be used to inline in an assignment
- Throws:
- NullPointerException- if- value == null
- IllegalArgumentException- if- value.isEmpty()
 
- 
argNotNegativeCheck that the int with given name is not negative, otherwise throw an exception. Example usage:private final int pageCount; public Book(final int pageCount) { // this throws an IllegalArgumentException when pageCount is negative this.pageCount = argNotNegative("pageCount", pageCount); }- Parameters:
- name- a descriptive name for the int (most likely the argument name)
- value- the int itself
- Returns:
- the int, so it can be used in an inline assignment
- Throws:
- IllegalArgumentException- if- value < 0
 
- 
argNotNegativeCheck that the long with given name is not negative, otherwise throw an exception. Example usage:private final long pageCount; public Book(final long pageCount) { // this throws an IllegalArgumentException when pageCount is negative this.pageCount = argNotNegative("pageCount", pageCount); }- Parameters:
- name- a descriptive name for the long (most likely the argument name)
- value- the long itself
- Returns:
- the long, so it can be used in an inline assignment
- Throws:
- IllegalArgumentException- if- value < 0
 
- 
argNotNegativeCheck that the float with given name is not negative, otherwise throw an exception. Example usage:private final float pageCount; public Book(final float pageCount) { // this throws an IllegalArgumentException when pageCount is negative this.pageCount = argNotNegative("pageCount", pageCount); }- Parameters:
- name- a descriptive name for the float (most likely the argument name)
- value- the float itself
- Returns:
- the float, so it can be used in an inline assignment
- Throws:
- IllegalArgumentException- if- value < 0
 
 
-