Package io.atlassian.fugue
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>,java.lang.Iterable<A>
- Direct Known Subclasses:
Either.LeftProjection,Either.RightProjection
abstract class Either.AbstractProjection<A,B> extends java.lang.Object implements Either.Projection<A,B,L,R>
Holds the common implementation for both projections.
-
-
Constructor Summary
Constructors Constructor Description AbstractProjection()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontains(A elem)Tests whether the option contains a given value as an element.Either<L,R>either()The either value underlying this projection.booleanexists(java.util.function.Predicate<? super A> f)Whether this isis definedand applying the predicate to the contained value returns true.booleanforall(java.util.function.Predicate<? super A> f)Returnstrueif emptyor the result of the application of the given function to the value.voidforeach(Effect<? super A> f)Deprecated.voidforEach(java.util.function.Consumer<? super A> f)AgetOr(java.util.function.Supplier<? extends A> a)Get the valueif definedor call the supplier and return its value if not.AgetOrElse(java.util.function.Supplier<? extends A> a)Deprecated.<X extends A>
AgetOrElse(X x)Get the value if defined, otherwise returnsother.AgetOrError(java.util.function.Supplier<java.lang.String> err)Get the value or throws an error with the supplied message if not defined.AgetOrNull()Get the value if defined or null if not.<X extends java.lang.Throwable>
AgetOrThrow(java.util.function.Supplier<X> ifUndefined)Get the value or throws the supplied throwable if not defined.booleanisEmpty()If the type does not contain a value return true.java.util.Iterator<A>iterator()Return an iterator for this type.Option<A>toOption()Returns this projection's value inSomeif it exists, otherwiseNone.java.util.Optional<A>toOptional()Returns this projection's value inOptional.of(T)if it exists, otherwiseOptional.empty().java.util.stream.Stream<A>toStream()Returns this projection's value inStream.of(T)if it exists, otherwiseStream.empty().-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.atlassian.fugue.Either.Projection
on
-
-
-
-
Method Detail
-
iterator
public final java.util.Iterator<A> iterator()
Description copied from interface:MaybeReturn an iterator for this type. In most cases this takes the form of an iterator returning zero or one values.- Specified by:
iteratorin interfacejava.lang.Iterable<A>- Specified by:
iteratorin interfaceMaybe<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.ProjectionThe either value underlying this projection.
-
isEmpty
public final boolean isEmpty()
Description copied from interface:MaybeIf the type does not contain a value return true.
-
toOption
public final Option<A> toOption()
Description copied from interface:Either.ProjectionReturns this projection's value inSomeif it exists, otherwiseNone.
-
toOptional
public final java.util.Optional<A> toOptional()
Description copied from interface:Either.ProjectionReturns this projection's value inOptional.of(T)if it exists, otherwiseOptional.empty().- Specified by:
toOptionalin interfaceEither.Projection<A,B,L,R>- Returns:
- This projection's value in
ofif it exists, otherwiseempty.
-
toStream
public final java.util.stream.Stream<A> toStream()
Description copied from interface:Either.ProjectionReturns this projection's value inStream.of(T)if it exists, otherwiseStream.empty().
-
exists
public final boolean exists(java.util.function.Predicate<? super A> f)
Description copied from interface:MaybeWhether this isis definedand applying the predicate to the contained value returns true.
-
getOrNull
public final A getOrNull()
Description copied from interface:MaybeGet 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.
-
forall
public final boolean forall(java.util.function.Predicate<? super A> f)
Description copied from interface:MaybeReturnstrueif emptyor the result of the application of the given function to the value.
-
contains
public boolean contains(A elem)
Description copied from interface:MaybeTests whether the option contains a given value as an element.
-
getOrError
public final A getOrError(java.util.function.Supplier<java.lang.String> err)
Description copied from interface:MaybeGet the value or throws an error with the supplied message if not defined.Used when absolutely sure this
is defined.- Specified by:
getOrErrorin interfaceMaybe<A>- Parameters:
err- the message for the error.- Returns:
- the contained value.
-
getOrThrow
public <X extends java.lang.Throwable> A getOrThrow(java.util.function.Supplier<X> ifUndefined) throws X extends java.lang.Throwable
Description copied from interface:MaybeGet the value or throws the supplied throwable if not defined.Used when absolutely sure this
is defined.- Specified by:
getOrThrowin interfaceMaybe<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.X extends java.lang.Throwable
-
getOr
public final A getOr(java.util.function.Supplier<? extends A> a)
Description copied from interface:MaybeGet the valueif definedor call the supplier and return its value if not. ReplacesMaybe.getOrElse(Supplier). Get the valueif definedor call the supplier and return its value if not.
-
getOrElse
@Deprecated public final A getOrElse(java.util.function.Supplier<? extends A> a)
Deprecated.Description copied from interface:MaybeGet the valueif definedor call the supplier and return its value if not.
-
getOrElse
public final <X extends A> A getOrElse(X x)
Description copied from interface:MaybeGet the value if defined, otherwise returnsother.- Specified by:
getOrElsein interfaceMaybe<A>- Type Parameters:
X- default value type- Parameters:
x- value to return if thisis empty- Returns:
- wrapped value if this
is defined, otherwise returnsother
-
foreach
@Deprecated public final void foreach(Effect<? super A> f)
Deprecated.Description copied from interface:Effect.ApplicantPerform the given side-effect for each contained element.- Specified by:
foreachin interfaceEffect.Applicant<A>- Parameters:
f- the input to use for performing the effect.
-
-