play.libs
Class F.Option<T>

java.lang.Object
  extended by play.libs.F.Option<T>
All Implemented Interfaces:
java.lang.Iterable<T>
Direct Known Subclasses:
F.None, F.Some
Enclosing class:
F

public abstract static class F.Option<T>
extends java.lang.Object
implements java.lang.Iterable<T>

Represents optional values. Instances of Option are either an instance of Some or the object None.


Constructor Summary
F.Option()
           
 
Method Summary
abstract  T get()
          Returns the value if defined.
 T getOrElse(T defaultValue)
          Get the value if defined, otherwise return the supplied defaultValue.
abstract  boolean isDefined()
          Is the value of this option defined?
<A> F.Option<A>
map(F.Function<T,A> function)
          Map this option to another value.
static
<T> F.None<T>
None()
          Constructs a None value.
static
<T> F.Some<T>
Some(T value)
          Construct a Some value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

F.Option

public F.Option()
Method Detail

isDefined

public abstract boolean isDefined()
Is the value of this option defined?

Returns:
true if the value is defined, otherwise false.

get

public abstract T get()
Returns the value if defined.

Returns:
The value if defined, otherwise null.

None

public static <T> F.None<T> None()
Constructs a None value.

Returns:
None

Some

public static <T> F.Some<T> Some(T value)
Construct a Some value.

Parameters:
value - The value to make optional
Returns:
Some T.

getOrElse

public T getOrElse(T defaultValue)
Get the value if defined, otherwise return the supplied defaultValue.

Parameters:
defaultValue - The value to return if the value of this option is not defined
Returns:
The value of this option, or defaultValue.

map

public <A> F.Option<A> map(F.Function<T,A> function)
Map this option to another value.

Parameters:
function - The function to map the option using.
Returns:
The mapped option.
Throws:
java.lang.RuntimeException - if function threw an Exception. If the exception is a RuntimeException, it will be rethrown as is, otherwise it will be wrapped in a RuntimeException.