Class Either.Right<L,R>

java.lang.Object
net.luis.utils.util.Either<L,R>
net.luis.utils.util.Either.Right<L,R>
Type Parameters:
L - The type of the left value
R - The type of the right value
Enclosing class:
Either<L,R>

static final class Either.Right<L,R> extends Either<L,R>
Right implementation of the either.
  • Nested Class Summary

    Nested classes/interfaces inherited from class net.luis.utils.util.Either

    Either.Left<L,R>, Either.Right<L,R>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final R
    The value of the right either.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Right(R value)
    Constructs a new right either instance with the given value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
     
    void
    ifLeft(@Nullable Consumer<? super L> action)
    Performs the given action if this either instance is a left instance.
    void
    ifRight(@NotNull Consumer<? super R> action)
    Performs the given action if this either instance is a right instance.
    boolean
    Checks if this either instance is a left instance.
    boolean
    Checks if this either instance is a right instance.
    @NotNull Optional<L>
    Returns the left value as an Optional.
    Returns the left value or throws an exception if it is a right either.
    <C, D> @NotNull Either<C,D>
    mapBoth(@NotNull Function<? super L,? extends C> leftMapper, @NotNull Function<? super R,? extends D> rightMapper)
    Maps the left and right values of this either instance to new values.
    <T> T
    mapTo(@NotNull Function<? super L,? extends T> leftMapper, @NotNull Function<? super R,? extends T> rightMapper)
    Maps the left and right values of this either instance to a new value.
    @NotNull Optional<R>
    Returns the right value as an Optional.
    @UnknownNullability R
    Returns the right value or throws an exception if it is a left either.
     

    Methods inherited from class net.luis.utils.util.Either

    left, mapLeft, mapRight, right, swap

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • value

      private final R value
      The value of the right either.
  • Constructor Details

    • Right

      private Right(@Nullable R value)
      Constructs a new right either instance with the given value.
      Parameters:
      value - The value of the right either
  • Method Details

    • isLeft

      public boolean isLeft()
      Description copied from class: Either
      Checks if this either instance is a left instance.
      Specified by:
      isLeft in class Either<L,R>
      Returns:
      True if this either instance is a left instance, false otherwise
    • isRight

      public boolean isRight()
      Description copied from class: Either
      Checks if this either instance is a right instance.
      Specified by:
      isRight in class Either<L,R>
      Returns:
      True if this either instance is a right instance, false otherwise
    • ifLeft

      public void ifLeft(@Nullable @Nullable Consumer<? super L> action)
      Description copied from class: Either
      Performs the given action if this either instance is a left instance.
      Specified by:
      ifLeft in class Either<L,R>
      Parameters:
      action - The action to perform
    • ifRight

      public void ifRight(@NotNull @NotNull Consumer<? super R> action)
      Description copied from class: Either
      Performs the given action if this either instance is a right instance.
      Specified by:
      ifRight in class Either<L,R>
      Parameters:
      action - The action to perform
    • left

      @NotNull public @NotNull Optional<L> left()
      Description copied from class: Either
      Returns the left value as an Optional.
      Specified by:
      left in class Either<L,R>
      Returns:
      The left value
    • right

      @NotNull public @NotNull Optional<R> right()
      Description copied from class: Either
      Returns the right value as an Optional.
      Specified by:
      right in class Either<L,R>
      Returns:
      The right value
    • leftOrThrow

      @NotNull public L leftOrThrow()
      Description copied from class: Either
      Returns the left value or throws an exception if it is a right either.
      Specified by:
      leftOrThrow in class Either<L,R>
      Returns:
      The left value
    • rightOrThrow

      public @UnknownNullability R rightOrThrow()
      Description copied from class: Either
      Returns the right value or throws an exception if it is a left either.
      Specified by:
      rightOrThrow in class Either<L,R>
      Returns:
      The right value
    • mapBoth

      @NotNull public <C, D> @NotNull Either<C,D> mapBoth(@NotNull @NotNull Function<? super L,? extends C> leftMapper, @NotNull @NotNull Function<? super R,? extends D> rightMapper)
      Description copied from class: Either
      Maps the left and right values of this either instance to new values.
      Specified by:
      mapBoth in class Either<L,R>
      Type Parameters:
      C - The new type of the left value
      D - The new type of the right value
      Parameters:
      leftMapper - The mapper for the left value
      rightMapper - The mapper for the right value
      Returns:
      A new either instance with the mapped values
    • mapTo

      public <T> T mapTo(@NotNull @NotNull Function<? super L,? extends T> leftMapper, @NotNull @NotNull Function<? super R,? extends T> rightMapper)
      Description copied from class: Either
      Maps the left and right values of this either instance to a new value.
      Specified by:
      mapTo in class Either<L,R>
      Type Parameters:
      T - The type of the mapped value
      Parameters:
      leftMapper - The mapper for the left value
      rightMapper - The mapper for the right value
      Returns:
      The mapped value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object