Record Class Validated.Invalid<E,A>
java.lang.Object
java.lang.Record
dmx.fun.Validated.Invalid<E,A>
- Type Parameters:
E- the type of the errorA- the type of the value (unused here)- Record Components:
error- the non-null error; passingnullthrowsNullPointerException
- All Implemented Interfaces:
Validated<E,A>
-
Nested Class Summary
Nested classes/interfaces inherited from interface Validated
Validated.Invalid<E,A>, Validated.Valid<E, A> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.error()Returns the value of theerrorrecord component.default <R> RFolds this container to a single value by applying the appropriate function.default AReturns the success value if present, orfallbackotherwise.default AgetOrElseGet(Supplier<A> supplier) Returns the success value if present, or the value produced bysupplierotherwise.default AReturns the success value if present, ornullotherwise.default AgetOrThrow(Function<E, ? extends RuntimeException> exMapper) Returns the success value if present, or throws an exception mapped from the error.final inthashCode()Returns a hash code value for this object.default voidExecutes one of the two consumers based on the active variant.stream()Returns a single-element stream of the success value, or an empty stream on error.toOption()Converts this container to anOption.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Invalid
Compact canonical constructor — validates thaterroris non-null.
-
-
Method Details
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
error
-
getOrElse
Returns the success value if present, orfallbackotherwise.- Parameters:
fallback- the non-null fallback value- Returns:
- the success value, or
fallbackif this is the error variant - Throws:
NullPointerException- iffallbackisnull
-
getOrElseGet
Returns the success value if present, or the value produced bysupplierotherwise.- Parameters:
supplier- supplier of the fallback value; must not returnnull- Returns:
- the success value, or the value produced by
supplier - Throws:
NullPointerException- ifsupplierisnullor returnsnull
-
getOrNull
Returns the success value if present, ornullotherwise.- Returns:
- the success value or
null
-
getOrThrow
Returns the success value if present, or throws an exception mapped from the error.- Parameters:
exMapper- maps the error to aRuntimeException; must not returnnull- Returns:
- the success value
- Throws:
NullPointerException- ifexMapperisnullor returnsnullRuntimeException- the exception produced byexMapperon the error variant
-
stream
-
fold
Folds this container to a single value by applying the appropriate function.- Type Parameters:
R- the result type- Parameters:
onSuccess- applied to the success value; must not returnnullonError- applied to the error value; must not returnnull- Returns:
- the result of the applied function
- Throws:
NullPointerException- if either function isnullor returnsnull
-
match
Executes one of the two consumers based on the active variant.- Parameters:
onSuccess- called with the success valueonError- called with the error value- Throws:
NullPointerException- if either consumer isnull
-
toOption
Converts this container to anOption. The success variant maps toOption.Some; the error variant maps toOption.none().- Returns:
- an
Optioncontaining the success value, or empty
-