Class Preconditions
- java.lang.Object
- 
- de.rwth.swc.coffee4j.algorithmic.util.Preconditions
 
- 
 public final class Preconditions extends Object Preconditions which can be used to validate the argument passed to methods.
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheck(boolean expression)Checks whether the given expression evaluates totrue.static voidcheck(boolean expression, String message)Checks whether the given expression evaluates totrue.static voidcheck(boolean expression, Supplier<String> messageSupplier)Checks whether the given expression evaluates totrue.static <T> Collection<T>doesNotContainNull(Collection<T> collection)Checks if the givenCollectioncontains anynullelement.static <T> Collection<T>doesNotContainNull(Collection<T> collection, String message)Checks if the givenCollectioncontains anynullelement.static <T> Collection<T>doesNotContainNull(Collection<T> collection, Supplier<String> messageSupplier)Checks if the givenCollectioncontains anynullelement.static <T> TnotNull(T object)Checks if the given object isnull.static <T> TnotNull(T object, String message)Checks if the given object ifnull.static <T> TnotNull(T object, Supplier<String> messageSupplier)Checks if the given object isnull.
 
- 
- 
- 
Method Detail- 
notNullpublic static <T> T notNull(T object) Checks if the given object isnull. If this is the case, aNullPointerExceptionis thrown.- Type Parameters:
- T- the type of the object. This is needed to return the correct type again
- Parameters:
- object- the object to be checked
- Returns:
- the object which was passed if it is not null
- Throws:
- NullPointerException- if the passed object is- null
 
 - 
notNullpublic static <T> T notNull(T object, String message)Checks if the given object ifnull. If this is the case, aNullPointerExceptionwith the given message is thrown.- Type Parameters:
- T- the type of the object. This is needed to returned the correct type again
- Parameters:
- object- the object to be checked
- message- the message for the exception if the object is- null
- Returns:
- the object which was passed if it is not null
- Throws:
- NullPointerException- if the passed object is- null
 
 - 
notNullpublic static <T> T notNull(T object, Supplier<String> messageSupplier)Checks if the given object isnull. If this is the case, aNullPointerExceptionwith the message provided by theSupplieris thrown.- Type Parameters:
- T- the type of the object. This is needed to returned the correct * type again
- Parameters:
- object- the object to be checked
- messageSupplier- a supplier for the message of the exception which will be thrown if object is- null
- Returns:
- the object which was passed if it is not null
- Throws:
- NullPointerException- if the passed object is- null
 
 - 
doesNotContainNullpublic static <T> Collection<T> doesNotContainNull(Collection<T> collection) Checks if the givenCollectioncontains anynullelement. If this is the case, aIllegalArgumentExceptionis thrown.- Type Parameters:
- T- the type of the collection
- Parameters:
- collection- to be examined for a- nullelement. Must not be- null
- Returns:
- the same collection which was initially given to this method
- Throws:
- IllegalArgumentException- if collection contains- null
- NullPointerException- if the collection it was- nullitself. Note that some- Collectionimplementations may throw a- NullPointerExceptionduring the check if they do not permit the- nulltype
 
 - 
doesNotContainNullpublic static <T> Collection<T> doesNotContainNull(Collection<T> collection, String message) Checks if the givenCollectioncontains anynullelement. If this is the case, aIllegalArgumentExceptionwith the given message is thrown.- Type Parameters:
- T- the type of the collection
- Parameters:
- collection- to be examined for a- nullelement. Must not be- null
- message- for the exception if it is thrown
- Returns:
- the same collection which was initially given to this method
- Throws:
- IllegalArgumentException- if collection contains- null
- NullPointerException- if the collection it was- nullitself. Note that some- Collectionimplementations may throw a- NullPointerExceptionduring the check if they do not permit the- nulltype
 
 - 
doesNotContainNullpublic static <T> Collection<T> doesNotContainNull(Collection<T> collection, Supplier<String> messageSupplier) Checks if the givenCollectioncontains anynullelement. If this is the case, aIllegalArgumentExceptionwith the message given by the supplier.- Type Parameters:
- T- the type of the collection
- Parameters:
- collection- to be examined for a- nullelement. Must not be- null
- messageSupplier- for the exception message if it is thrown
- Returns:
- the same collection which was initially given to this method
- Throws:
- IllegalArgumentException- if collection contains- null
- NullPointerException- if the collection it was- nullitself. Note that some- Collectionimplementations may throw a- NullPointerExceptionduring the check if they do not permit the- nulltype
 
 - 
checkpublic static void check(boolean expression) Checks whether the given expression evaluates totrue. If this is not the case, anIllegalArgumentExceptionis thrown.- Parameters:
- expression- the expression to be evaluated
- Throws:
- IllegalArgumentException- if the expression evaluates to- false
 
 - 
checkpublic static void check(boolean expression, String message)Checks whether the given expression evaluates totrue. If this is not the case, anIllegalArgumentExceptionwith the given message is thrown.- Parameters:
- expression- the expression to be evaluated
- message- the message for the exception
- Throws:
- IllegalArgumentException- if the expression evaluates to- false
 
 - 
checkpublic static void check(boolean expression, Supplier<String> messageSupplier)Checks whether the given expression evaluates totrue. If this is not the case, anIllegalArgumentExceptionwith the message given by theSupplieris thrown.- Parameters:
- expression- the expression to be evaluated
- messageSupplier- the supplier for the exception message
- Throws:
- IllegalArgumentException- if the expression evaluates to- false
 
 
- 
 
-