Class Either.AbstractProjection<A,B>

java.lang.Object
io.atlassian.fugue.Either.AbstractProjection<A,B>
All Implemented Interfaces:
Effect.Applicant<A>, Either.Projection<A,B,L,R>, Maybe<A>, Iterable<A>
Direct Known Subclasses:
Either.LeftProjection, Either.RightProjection
Enclosing class:
Either<L,R>

abstract class Either.AbstractProjection<A,B> extends Object implements Either.Projection<A,B,L,R>
Holds the common implementation for both projections.
  • Constructor Details

    • AbstractProjection

      AbstractProjection()
  • Method Details

    • iterator

      public final Iterator<A> iterator()
      Description copied from interface: Maybe
      Return an iterator for this type. In most cases this takes the form of an iterator returning zero or one values.
      Specified by:
      iterator in interface Iterable<A>
      Specified by:
      iterator in interface Maybe<A>
      Returns:
      an iterator over the contained value if defined, or an empty one otherwise.
    • either

      public final Either<L,R> either()
      Description copied from interface: Either.Projection
      The either value underlying this projection.
      Specified by:
      either in interface Either.Projection<A,B,L,R>
      Returns:
      The either value underlying this projection.
    • isEmpty

      public final boolean isEmpty()
      Description copied from interface: Maybe
      If the type does not contain a value return true.
      Specified by:
      isEmpty in interface Maybe<A>
      Returns:
      true if this does not hold a value, false otherwise.
    • toOption

      public final Option<A> toOption()
      Description copied from interface: Either.Projection
      Returns this projection's value in Some if it exists, otherwise None.
      Specified by:
      toOption in interface Either.Projection<A,B,L,R>
      Returns:
      This projection's value in Some if it exists, otherwise None.
    • toOptional

      public final Optional<A> toOptional()
      Description copied from interface: Either.Projection
      Returns this projection's value in Optional.of(T) if it exists, otherwise Optional.empty().
      Specified by:
      toOptional in interface Either.Projection<A,B,L,R>
      Returns:
      This projection's value in of if it exists, otherwise empty.
    • toStream

      public final Stream<A> toStream()
      Description copied from interface: Either.Projection
      Returns this projection's value in Stream.of(T) if it exists, otherwise Stream.empty().
      Specified by:
      toStream in interface Either.Projection<A,B,L,R>
      Returns:
      This projection's value in of if it exists, otherwise empty.
    • exists

      public final boolean exists(Predicate<? super A> f)
      Description copied from interface: Maybe
      Whether this is is defined and applying the predicate to the contained value returns true.
      Specified by:
      exists in interface Maybe<A>
      Parameters:
      f - the predicate to test, must not be null
      Returns:
      true if defined and the predicate returns true for the contained value, false otherwise.
    • getOrNull

      public final A getOrNull()
      Description copied from interface: Maybe
      Get the value if defined or null if not.

      Although the use of null is discouraged, code written to use these must often interface with code that expects and returns nulls.

      Specified by:
      getOrNull in interface Maybe<A>
      Returns:
      the value or null if not defined
    • forall

      public final boolean forall(Predicate<? super A> f)
      Description copied from interface: Maybe
      Returns true if empty or the result of the application of the given function to the value.
      Specified by:
      forall in interface Maybe<A>
      Parameters:
      f - The predicate function to test on the contained value, must not be null
      Returns:
      true if no value or returns the result of the application of the given function to the value.
    • contains

      public boolean contains(A elem)
      Description copied from interface: Maybe
      Tests whether the option contains a given value as an element.
      Specified by:
      contains in interface Maybe<A>
      Parameters:
      elem - the element to test
      Returns:
      true if the option has an element that is equal to elem, false otherwise
    • getOrError

      public final A getOrError(Supplier<String> err)
      Description copied from interface: Maybe
      Get the value or throws an error with the supplied message if not defined.

      Used when absolutely sure this is defined.

      Specified by:
      getOrError in interface Maybe<A>
      Parameters:
      err - the message for the error.
      Returns:
      the contained value.
    • getOrThrow

      public <X extends Throwable> A getOrThrow(Supplier<X> ifUndefined) throws X
      Description copied from interface: Maybe
      Get the value or throws the supplied throwable if not defined.

      Used when absolutely sure this is defined.

      Specified by:
      getOrThrow in interface Maybe<A>
      Type Parameters:
      X - exception type
      Parameters:
      ifUndefined - the supplier of the throwable.
      Returns:
      the contained value.
      Throws:
      X - the throwable the supplier creates if there is no value.
    • getOr

      public final A getOr(Supplier<? extends A> a)
      Description copied from interface: Maybe
      Get the value if defined or call the supplier and return its value if not. Replaces Maybe.getOrElse(Supplier). Get the value if defined or call the supplier and return its value if not.
      Specified by:
      getOr in interface Maybe<A>
      Parameters:
      a - called if this is empty
      Returns:
      the wrapped value or the value from the Supplier
    • getOrElse

      @Deprecated public final A getOrElse(Supplier<? extends A> a)
      Deprecated.
      Description copied from interface: Maybe
      Get the value if defined or call the supplier and return its value if not.
      Specified by:
      getOrElse in interface Maybe<A>
      Parameters:
      a - called if this is empty
      Returns:
      the wrapped value or the value from the Supplier
    • getOrElse

      public final <X extends A> A getOrElse(X x)
      Description copied from interface: Maybe
      Get the value if defined, otherwise returns other.
      Specified by:
      getOrElse in interface Maybe<A>
      Type Parameters:
      X - default value type
      Parameters:
      x - value to return if this is empty
      Returns:
      wrapped value if this is defined, otherwise returns other
    • foreach

      @Deprecated public final void foreach(Effect<? super A> f)
      Deprecated.
      Description copied from interface: Effect.Applicant
      Perform the given side-effect for each contained element.
      Specified by:
      foreach in interface Effect.Applicant<A>
      Parameters:
      f - the input to use for performing the effect.
    • forEach

      public final void forEach(Consumer<? super A> f)
      Specified by:
      forEach in interface Iterable<A>