Record Class Either.Right<L,R>
- Type Parameters:
L- The left typeR- The right type
- All Implemented Interfaces:
Either<L,R>
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.camunda.zeebe.util.Either
Either.EitherOptional<R>, Either.Left<L,R>, Either.Right<L, R> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.Flatmaps the right value into a new Either, if this is aEither.Right.<T> TMaps the right or left value into a new type using the provided functions, depending on whether this is aEither.LeftorEither.Right.get()Returns the right value, if this is aEither.Right.getLeft()Returns the left value, if this is aEither.Left.Returns the right value, or a default value if this is aEither.Left.final inthashCode()Returns a hash code value for this object.voidPerforms the given action with the value if this is aEither.Left, otherwise does nothing.voidPerforms the given action with the value if this is aEither.Right, otherwise does nothing.voidifRightOrLeft(Consumer<R> rightAction, Consumer<L> leftAction) Performs the given right action with the value if this is aEither.Right, otherwise performs the given left action with the value.booleanisLeft()Returns true if this Either is aEither.Left.booleanisRight()Returns true if this Either is aEither.Right.Maps the right value, if this is aEither.Right.Maps the left value, if this is aEither.Left.Executes the given action with the right value if this is aEither.Right, otherwise does nothing.final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
Right
Creates an instance of aRightrecord class.- Parameters:
value- the value for thevaluerecord component
-
-
Method Details
-
isRight
public boolean isRight()Description copied from interface:EitherReturns true if this Either is aEither.Right. -
isLeft
public boolean isLeft()Description copied from interface:EitherReturns true if this Either is aEither.Left. -
get
Description copied from interface:EitherReturns the right value, if this is aEither.Right. -
getOrElse
Description copied from interface:EitherReturns the right value, or a default value if this is aEither.Left.- Specified by:
getOrElsein interfaceEither<L,R> - Parameters:
defaultValue- the default value- Returns:
- the right value, or the default value if this is a
Either.Left
-
getLeft
Description copied from interface:EitherReturns the left value, if this is aEither.Left. -
map
Description copied from interface:EitherMaps the right value, if this is aEither.Right.- Specified by:
mapin interfaceEither<L,R> - Type Parameters:
T- the type of the resulting right value- Parameters:
right- the mapping function for the right value- Returns:
- a mapped
Either.Rightor the sameEither.Left
-
mapLeft
Description copied from interface:EitherMaps the left value, if this is aEither.Left.- Specified by:
mapLeftin interfaceEither<L,R> - Type Parameters:
T- the type of the resulting left value- Parameters:
left- the mapping function for the left value- Returns:
- a mapped
Either.Leftor the sameEither.Right
-
flatMap
Description copied from interface:EitherFlatmaps the right value into a new Either, if this is aEither.Right.A common use case is to map a right value to a new right, unless some error occurs in which case the value can be mapped to a new left. Note that this flatMap does not allow to alter the type of the left side. Example:
Either.<String, Integer>right(0) // => Right(0) .flatMap(x -> Either.right(x + 1)) // => Right(1) .flatMap(x -> Either.left("an error occurred")) // => Left("an error occurred") .getLeft(); // => "an error occurred"- Specified by:
flatMapin interfaceEither<L,R> - Type Parameters:
T- the type of the right side of the resulting either- Parameters:
right- the flatmapping function for the right value- Returns:
- either a mapped
Either.Rightor a newEither.Leftif this is a right; otherwise the same left, but cast to consider the new type of the right.
-
thenDo
Description copied from interface:EitherExecutes the given action with the right value if this is aEither.Right, otherwise does nothing. This method facilitates side-effect operations on the right value without altering the state or the type of theEither. After executing the action, the originalEither<L, R>is returned, allowing for further chaining of operations in a fluent API style.When the instance is a
Either.Right, the action is executed, and the originalEither<L, R>is returned. This maintains the right value's type and allows the action to be performed as a side-effect without changing the outcome. When the instance is aEither.Left, no action is performed, and theLeftinstance is returned unchanged, preserving the error information.Usage example when
Eitheris aEither.Right:Either<Exception, String> rightEither = Either.right("Success"); Either<Exception, String> result = rightEither.thenDo(value -> System.out.println("Processed value: " + value)); // Output: Processed value: Success // result remains a Right<Exception, String>, with the value "Success"Usage example when
Eitheris aEither.Left:Either<String, Integer> leftEither = Either.left("Error occurred"); Either<String, Integer> result = leftEither.thenDo(value -> System.out.println("This will not be printed")); // No output as the action is not executed // result remains an unchanged Left<String, Integer>, containing the original error message -
ifRight
Description copied from interface:EitherPerforms the given action with the value if this is aEither.Right, otherwise does nothing. -
ifLeft
Description copied from interface:EitherPerforms the given action with the value if this is aEither.Left, otherwise does nothing. -
ifRightOrLeft
Description copied from interface:EitherPerforms the given right action with the value if this is aEither.Right, otherwise performs the given left action with the value.- Specified by:
ifRightOrLeftin interfaceEither<L,R> - Parameters:
rightAction- the consuming function for the right valueleftAction- the consuming function for the left value
-
fold
Description copied from interface:EitherMaps the right or left value into a new type using the provided functions, depending on whether this is aEither.LeftorEither.Right.A common use case is to map to a new common value in success and error cases. Example:
Either<String, Integer> success = Either.right(42); // => Right(42) Either<String, Integer> failure = Either.left("Error occurred"); // => Left("Error occurred") var rightFn = result -> "Success: " + result; var leftFn = error -> "Failure: " + error; success.fold(leftFn, rightFn); // => "Success: 42" failure.fold(leftFn, rightFn); // => "Failure: Error occurred"- Specified by:
foldin interfaceEither<L,R> - Type Parameters:
T- the type of the resulting value- Parameters:
leftFn- the mapping function for the left valuerightFn- the mapping function for the right value- Returns:
- either a mapped
Either.LeftorEither.Right, folded to the new type
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
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). -
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-