-
- 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 boolean
all(java.util.function.Predicate<? super T> predicate)
Validate that all elements match the predicate provided.default boolean
contains(T element)
Validate if the value contains the provided item.default boolean
exists(java.util.function.Predicate<? super T> predicate)
Validate if an element is contained that matches the provided predicate.T
get()
Return the contentsT
of the wrapped value.boolean
isSingleValued()
Is this instance single-valued or not.default boolean
none(java.util.function.Predicate<? super T> predicate)
Validate that none of the elements match thepredicate
provided.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 thePredicate
is 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 thePredicate
is null
-
get
T get()
Return the contentsT
of the wrapped value.This can throw a
NoSuchElementException
if 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:
true
if single-valued, otherwisefalse
-
none
default boolean none(java.util.function.Predicate<? super T> predicate)
Validate that none of the elements match thepredicate
provided.- Parameters:
predicate
- the predicate to test with- Returns:
- true if none of the elements match, otherwise false
- Throws:
java.lang.NullPointerException
- in case thePredicate
is null- See Also:
all(Predicate)
,exists(Predicate)
-
stream
default java.util.stream.Stream<T> stream()
Create a stream of the value.- Specified by:
stream
in interfaceStreamable<T>
- Returns:
- the stream containing the value
-
-