Package com.terheyden.value
Class Value1<C>
java.lang.Object
com.terheyden.value.Value1<C>
A stack with a single value.
Create via static methods in the
ValueStack class.-
Method Summary
Modifier and TypeMethodDescriptionandOf(D value) Adds an additional Value to track, resulting in a newValue2.Uses the existing value, if present, to create a new value to track.Adds an additional Value to track, resulting in a newValue2.andOfNullable(D value) Returns anValue1describing the given value, if non-null, otherwise returns an emptyValue1.andOfNullable(io.vavr.CheckedFunction1<? super C, ? extends D> valueFunction) Uses the existing value, if present, to create a new value to track.static <X> Value1<X>empty()Returns an emptyValue1instance.booleanIndicates whether some other object is "equal to" thisValue1.If a value is present, and the value matches the given predicate, returns anValue1describing the value, otherwise returns an emptyValue1.<U> Value1<U>If a value is present, returns the result of applying the givenValue1-bearing mapping function to the value, otherwise returns an emptyValue1.get()If a value is present, returns the value, otherwise throwsNoSuchElementException.inthashCode()Returns the hash code of the value, if present, otherwise0(zero) if no value is present.ifEmpty(io.vavr.CheckedRunnable emptyAction) Performs the empty-based action if no value is present, otherwise does nothing.If a value is present, performs the given action with the value, otherwise does nothing.ifPresentOrElse(io.vavr.CheckedConsumer<? super C> action, io.vavr.CheckedRunnable emptyAction) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.booleanisEmpty()If a value is not present, returnstrue, otherwisefalse.booleanIf a value is present, returnstrue, otherwisefalse.<U> Value1<U>If a value is present, returns anValue1describing (as if by#ofNullable) the result of applying the given mapping function to the value, otherwise returns an emptyValue1.If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.If a value is present, returns the value, otherwise returnsother.If a value is present, returns the value, otherwise returns the result produced by the supplying function.If a value is present, returns the value, otherwise throwsNoSuchElementException.orElseThrow(io.vavr.CheckedFunction0<? extends X> exceptionSupplier) If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.stream()If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.Converts the last value to a JavaOptional.toString()Returns a non-empty string representation of thisValue1suitable for debugging.
-
Method Details
-
empty
Returns an emptyValue1instance. No value is present for thisValue1.- Type Parameters:
X- The type of the non-existent value- Returns:
- an empty
Value1
-
andOf
Adds an additional Value to track, resulting in a newValue2. -
andOf
Adds an additional Value to track, resulting in a newValue2. -
andOf
Uses the existing value, if present, to create a new value to track. If the existing value is empty, then an emptyValue2is returned. -
andOfNullable
Returns anValue1describing the given value, if non-null, otherwise returns an emptyValue1.- Type Parameters:
D- the type of the value- Parameters:
value- the possibly-nullvalue to describe- Returns:
- an
Value1with a present value if the specified value is non-null, otherwise an emptyValue1
-
andOfNullable
Uses the existing value, if present, to create a new value to track. If the existing value is empty, then an emptyValue2is returned. -
get
If a value is present, returns the value, otherwise throwsNoSuchElementException.- Returns:
- the non-
nullvalue described by thisValue1 - Throws:
NoSuchElementException- if no value is present
-
isPresent
public boolean isPresent()If a value is present, returnstrue, otherwisefalse.- Returns:
trueif a value is present, otherwisefalse
-
isEmpty
public boolean isEmpty()If a value is not present, returnstrue, otherwisefalse.- Returns:
trueif a value is not present, otherwisefalse- Since:
- 11
-
ifPresent
If a value is present, performs the given action with the value, otherwise does nothing.- Parameters:
action- the action to be performed, if a value is present- Returns:
- this, for chaining
- Throws:
NullPointerException- if value is present and the given action isnull
-
ifPresentOrElse
public Value1<C> ifPresentOrElse(io.vavr.CheckedConsumer<? super C> action, io.vavr.CheckedRunnable emptyAction) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.- Parameters:
action- the action to be performed, if a value is presentemptyAction- the empty-based action to be performed, if no value is present- Returns:
- this, for chaining
- Throws:
NullPointerException- if a value is present and the given action isnull, or no value is present and the given empty-based action isnull.- Since:
- 9
-
ifEmpty
Performs the empty-based action if no value is present, otherwise does nothing.- Parameters:
action- the action to be performed, if a value is presentemptyAction- the empty-based action to be performed, if no value is present- Returns:
- this, for chaining
- Throws:
NullPointerException- if a value is present and the given action isnull, or no value is present and the given empty-based action isnull.- Since:
- 9
-
filter
If a value is present, and the value matches the given predicate, returns anValue1describing the value, otherwise returns an emptyValue1.- Parameters:
predicate- the predicate to apply to a value, if present- Returns:
- an
Value1describing the value of thisValue1, if a value is present and the value matches the given predicate, otherwise an emptyValue1 - Throws:
NullPointerException- if the predicate isnull
-
map
If a value is present, returns anValue1describing (as if by#ofNullable) the result of applying the given mapping function to the value, otherwise returns an emptyValue1.If the mapping function returns a
nullresult then this method returns an emptyValue1.- Type Parameters:
U- The type of the value returned from the mapping function- Parameters:
mapper- the mapping function to apply to a value, if present- Returns:
- an
Value1describing the result of applying a mapping function to the value of thisValue1, if a value is present, otherwise an emptyValue1 - Throws:
NullPointerException- if the mapping function isnull
-
flatMap
public <U> Value1<U> flatMap(io.vavr.CheckedFunction1<? super C, ? extends Optional<? extends U>> mapper) If a value is present, returns the result of applying the givenValue1-bearing mapping function to the value, otherwise returns an emptyValue1.This method is similar to
#map(Function), but the mapping function is one whose result is already anValue1, and if invoked,flatMapdoes not wrap it within an additionalValue1.- Type Parameters:
U- The type of value of theValue1returned by the mapping function- Parameters:
mapper- the mapping function to apply to a value, if present- Returns:
- the result of applying an
Value1-bearing mapping function to the value of thisValue1, if a value is present, otherwise an emptyValue1 - Throws:
NullPointerException- if the mapping function isnullor returns anullresult
-
or
If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.- Parameters:
supplier- the supplying function that produces anValue1to be returned- Returns:
- returns an
Value1describing the value of thisValue1, if a value is present, otherwise anValue1produced by the supplying function. - Throws:
NullPointerException- if the supplying function isnullor produces anullresult- Since:
- 9
-
or
If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.- Parameters:
supplier- the supplying function that produces anValue1to be returned- Returns:
- returns an
Value1describing the value of thisValue1, if a value is present, otherwise anValue1produced by the supplying function. - Throws:
NullPointerException- if the supplying function isnullor produces anullresult- Since:
- 9
-
or
If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.- Parameters:
supplier- the supplying function that produces anValue1to be returned- Returns:
- returns an
Value1describing the value of thisValue1, if a value is present, otherwise anValue1produced by the supplying function. - Throws:
NullPointerException- if the supplying function isnullor produces anullresult- Since:
- 9
-
or
If a value is present, returns anValue1describing the value, otherwise returns anValue1produced by the supplying function.- Parameters:
supplier- the supplying function that produces anValue1to be returned- Returns:
- returns an
Value1describing the value of thisValue1, if a value is present, otherwise anValue1produced by the supplying function. - Throws:
NullPointerException- if the supplying function isnullor produces anullresult- Since:
- 9
-
stream
If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.- Returns:
- the optional value as a
Stream - Since:
- 9
-
orElse
If a value is present, returns the value, otherwise returnsother.- Parameters:
other- the value to be returned, if no value is present. May benull.- Returns:
- the value, if present, otherwise
other
-
orElseGet
If a value is present, returns the value, otherwise returns the result produced by the supplying function.- Parameters:
supplier- the supplying function that produces a value to be returned- Returns:
- the value, if present, otherwise the result produced by the supplying function
- Throws:
NullPointerException- if no value is present and the supplying function isnull
-
orElseThrow
If a value is present, returns the value, otherwise throwsNoSuchElementException.- Returns:
- the non-
nullvalue described by thisValue1 - Throws:
NoSuchElementException- if no value is present- Since:
- 10
-
orElseThrow
public <X extends Throwable> C orElseThrow(io.vavr.CheckedFunction0<? extends X> exceptionSupplier) throws X If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.- Type Parameters:
X- Type of the exception to be thrown- Parameters:
exceptionSupplier- the supplying function that produces an exception to be thrown- Returns:
- the value, if present
- Throws:
X- if no value is presentNullPointerException- if no value is present and the exception supplying function isnull
-
toOptional
Converts the last value to a JavaOptional. -
equals
Indicates whether some other object is "equal to" thisValue1. The other object is considered equal if:- it is also an
Value1and; - both instances have no value present or;
- the present values are "equal to" each other via
equals().
- it is also an
-
hashCode
public int hashCode()Returns the hash code of the value, if present, otherwise0(zero) if no value is present. -
toString
Returns a non-empty string representation of thisValue1suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
-