net.ninjacat.drama
Class Option<T>

java.lang.Object
  extended by net.ninjacat.drama.Option<T>
Type Parameters:
T - type of the value

public class Option<T>
extends Object

Optional value.


Method Summary
static
<T> Option<T>
absent()
          Creates optional value which is unset
 T get()
           
 boolean isPresent()
           
static
<T> Option<T>
of(T value)
          Creates optional value from supplied parameter
 T or(T alternative)
           
 T orNull()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

absent

public static <T> Option<T> absent()
Creates optional value which is unset

Type Parameters:
T - type of the value
Returns:
absent value

of

public static <T> Option<T> of(T value)
Creates optional value from supplied parameter

Type Parameters:
T - type of the value
Parameters:
value - value to wrap into Option. May be null
Returns:
wrapped value

isPresent

public boolean isPresent()
Returns:
true if this optional contains value

or

public T or(T alternative)
Parameters:
alternative - value to be used if this optional is absent
Returns:
value of this option or alternative value if option does not hold anything

orNull

public T orNull()
Returns:
either value of this option or null

get

public T get()
Returns:
value of this option
Throws:
IllegalStateException - if option does not hold anything


Copyright © 2014. All rights reserved.