public enum Ensures extends Enum<Ensures>
A class that offers entry-points for checking "postconditions" with a normal
conditional statement of Java language.
That is, if
or ternary operator, not an assert
statement.
This means, the user of your product is not able to disable the checks you
write at runtime, unlike ones written using assert
statements.
The author of library thinks these methods should be used in "public facing" methods, when you should claim that the "external" party introduced the bug.
The author of library thinks these methods should be used in "public facing"
context when the provider of the value to be examined introduced
a bug, which makes the condition false
.
For instance, it is an intended use-case, where you call ensure
at the end of
your method in order to express a condition to be satisfied by the value returned
from your method.
Modifier and Type | Method and Description |
---|---|
static <T> T |
ensure(T value,
Predicate<? super T> cond)
Checks if a given
value satisfies a postcondition cond . |
static <T> T |
ensureNonNull(T value)
Checks if a given value is not
null . |
static <T> T |
ensureState(T value,
Predicate<? super T> cond)
Checks if a given state
value`satisfies a postcondition `cond . |
static Ensures |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static Ensures[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static Ensures[] values()
for (Ensures c : Ensures.values()) System.out.println(c);
public static Ensures valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static <T> T ensureNonNull(T value)
Checks if a given value is not null
.
If not an exception will be thrown.
T
- The type of the value
.value
- A value to be checked.public static <T> T ensureState(T value, Predicate<? super T> cond)
Checks if a given state value`satisfies a postcondition `cond
.
If not an exception will be thrown.
T
- The type of the value
.value
- A value to be checked.cond
- A condition that checks value
.value
itselfpublic static <T> T ensure(T value, Predicate<? super T> cond)
Checks if a given value
satisfies a postcondition cond
.
If not an exception will be thrown.
T
- The type of the value
.value
- A value to be checked.cond
- A condition that checks value
.value
itself.Copyright © 2024. All rights reserved.