-
- Type Parameters:
T- the type of object being wrapped
- All Superinterfaces:
java.lang.Iterable<T>,java.io.Serializable,Streamable<T>
- All Known Subinterfaces:
Collection<T>,Iterator<T>,List<T>,Map<K,T>,Optional<T>,Sequence<T>,Set<T>,Traversable<T>,Tree<T>,Tree.NodeCollection<T>
- All Known Implementing Classes:
ValueType
public interface Value<T> extends Streamable<T>, java.io.Serializable
The Value interface represents a simple wrapped value. This interface can contain exactly one entity inside, or None in case of an empty value.- Since:
- 0.0.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleanall(java.util.function.Predicate<? super T> predicate)Validate that all elements match the predicate provided.default booleancontains(T element)Validate if the value contains the provided item.default booleanexists(java.util.function.Predicate<? super T> predicate)Validate if an element is contained that matches the provided predicate.Tget()Return the contentsTof the wrapped value.booleanisSingleValued()Is this instance single-valued or not.default booleannone(java.util.function.Predicate<? super T> predicate)Validate that none of the elements match thepredicateprovided.default java.util.stream.Stream<T>stream()Create a stream of the value.-
Methods inherited from interface com.jongsoft.lang.Streamable
filter, map
-
-
-
-
Method Detail
-
all
default boolean all(java.util.function.Predicate<? super T> predicate)
Validate that all elements match the predicate provided. This can be useful to quickly look over the elements to verify that they all meet a pre-specified criteria.Example:
// result will be true List("a", "b").all(x -> x.length() == 1);- Parameters:
predicate- the predicate to test with- Returns:
- true if all elements match the predicate, otherwise false
- Throws:
java.lang.NullPointerException- in case thePredicateis null- See Also:
none(Predicate),exists(Predicate)
-
contains
default boolean contains(T element)
Validate if the value contains the provided item.- Parameters:
element- an element of type T, can benull- Returns:
- true, if the element is contained within
-
exists
default boolean exists(java.util.function.Predicate<? super T> predicate)
Validate if an element is contained that matches the provided predicate.- Parameters:
predicate- the predicate to validate with- Returns:
- true, if any element is contained within that matches the predicate
- Throws:
java.lang.NullPointerException- in case thePredicateis null
-
get
T get()
Return the contentsTof the wrapped value.This can throw a
NoSuchElementExceptionif no value is present.- Returns:
- returns the object wrapped in this value
- Throws:
java.util.NoSuchElementException- if no element is present
-
isSingleValued
boolean isSingleValued()
Is this instance single-valued or not.- Returns:
trueif single-valued, otherwisefalse
-
none
default boolean none(java.util.function.Predicate<? super T> predicate)
Validate that none of the elements match thepredicateprovided.- Parameters:
predicate- the predicate to test with- Returns:
- true if none of the elements match, otherwise false
- Throws:
java.lang.NullPointerException- in case thePredicateis null- See Also:
all(Predicate),exists(Predicate)
-
stream
default java.util.stream.Stream<T> stream()
Create a stream of the value.- Specified by:
streamin interfaceStreamable<T>- Returns:
- the stream containing the value
-
-