Package org.opencastproject.util.data
Class Option<A>
java.lang.Object
org.opencastproject.util.data.Option<A>
- All Implemented Interfaces:
Iterable<A>
The option type encapsulates on optional value. It contains either some value or is empty. Please make sure to NEVER
wrap null into a some. Instead use none.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEffect match.static interface -
Method Summary
Modifier and TypeMethodDescriptionabstract <B> Option<B> Monadic bind operationm a -> (a -> m b) -> m b.Create an equals function.abstract booleanstatic <A> Function0<A> Deprecated.<B> Option<B> abstract <B> Option<B> abstract <B> Bfold(Option.Match<A, B> visitor) Safe decomposition of the option type.static <A> Option<A> fromOpt(com.entwinemedia.fn.data.Opt<A> a) Convert anOptinto anOption.abstract Aget()Get the contained value or throw an exception.abstract AGet the contained value in case of being "some" or return parameternoneotherwise.abstract AGet the contained value in case of being "some" or return the result of evaluatingnoneotherwise.abstract ATo interface with legacy applications or frameworks that still usenullvalues.abstract inthashCode()booleanisNone()abstract booleanisSome()list()Transform an option into a list, either with a single element or an empty list.<B> Option<B> static <A> Option<A> none()Create a new none.static <A> Option<A> none(A example) Create a none with the type ofexample.static <A> Option<A> Create a none with the given type.static <A> Option<A> option(A a) Wrap an arbitrary object into an option withnullbeing mapped to none.Lazy version oforElse(Option).If this is none returnnoneelse this.orError(T none) Thrownoneif none.static <A> Option<A> some(A a) Create a new some.abstract com.entwinemedia.fn.data.Opt<A> toOpt()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
fold
Safe decomposition of the option type. -
foreach
-
fmap
-
map
-
bind
Monadic bind operationm a -> (a -> m b) -> m b. -
flatMap
-
isSome
public abstract boolean isSome() -
isNone
public boolean isNone() -
orElse
If this is none returnnoneelse this. -
orElse
Lazy version oforElse(Option). -
orError
Thrownoneif none.- Throws:
T
-
and
-
get
Get the contained value or throw an exception. -
getOrElse
Get the contained value in case of being "some" or return parameternoneotherwise. -
getOrElse
Get the contained value in case of being "some" or return the result of evaluatingnoneotherwise. -
getOrElseNull
To interface with legacy applications or frameworks that still usenullvalues. -
list
Transform an option into a list, either with a single element or an empty list. -
toOpt
-
hashCode
public abstract int hashCode() -
equals
-
some
Create a new some. -
none
Create a new none. -
none
Create a none with the type ofexample. This saves some nasty typing, e.g.Option.<String>none()vs.none("").Please note that this constructor is only due to Java's insufficient type inference.
-
none
Create a none with the given type. -
option
Wrap an arbitrary object into an option withnullbeing mapped to none. -
fromOpt
Convert anOptinto anOption. -
error
Deprecated.useorError(Throwable)ororElse(Function0)instead since it saves the need for creating new objects just for the sake of type soundness. Java unfortunately lacks a bottom type.Use this function ingetOrElseif it is an error being none. -
eq
Create an equals function.some("abc").map(eq("bcd")).getOrElse(false) // false some("abc").map(eq("abc")).getOrElse(false) // true
-
orError(Throwable)ororElse(Function0)instead since it saves the need for creating new objects just for the sake of type soundness.