play.libs
Class F.Option<T>

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

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

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


Constructor Summary
F.Option()
           
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection<? extends T> c)
           
 void clear()
           
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?
 boolean isEmpty()
           
<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.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection<?> c)
           
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.util.Collection
contains, containsAll, equals, hashCode, iterator, size, toArray, toArray
 

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.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<T>

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.

clear

public void clear()
Specified by:
clear in interface java.util.Collection<T>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<T>

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection<T>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<T>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<T>

addAll

public boolean addAll(java.util.Collection<? extends T> c)
Specified by:
addAll in interface java.util.Collection<T>