org.stjs.generator.utils
Class Option<T>

java.lang.Object
  extended by org.stjs.generator.utils.Option<T>
All Implemented Interfaces:
Iterable<T>

public abstract class Option<T>
extends Object
implements Iterable<T>


Constructor Summary
Option()
           
 
Method Summary
abstract  T getOrElse(T defaultValue)
          If the option is nonempty returns its value, otherwise returns defaultValue.
abstract  T getOrNull()
          If the option is nonempty returns its value, otherwise returns null.
abstract  T getOrThrow()
          Gets the value of this option.
abstract
<E extends Throwable>
T
getOrThrow(E e)
          Returns its value if not empty, otherwise throws e.
abstract  T getOrThrow(String message)
          Gets the value of this option.
 boolean isDefined()
          Returns true if the option is a Some(...).
abstract  boolean isEmpty()
          Returns true if the option is the None value.
static
<T> Option<T>
none()
          Gets the none object for the given type.
static
<T> Option<T>
of(T t)
          Wraps anything.
static
<T> Option<T>
some(T t)
          Gets the some object wrapping the given value.
abstract  String toStringOr(String defaultValue)
           
 
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

Option

public Option()
Method Detail

getOrNull

public abstract T getOrNull()
If the option is nonempty returns its value, otherwise returns null.


getOrElse

public abstract T getOrElse(T defaultValue)
If the option is nonempty returns its value, otherwise returns defaultValue. Note that defaultValue is eagerly evaluated.


getOrThrow

public abstract T getOrThrow()
Gets the value of this option. If this is a Some(T) the value is returned, otherwise an IllegalArgumentException is thrown.


getOrThrow

public abstract T getOrThrow(String message)
Gets the value of this option. If this is a Some(T) the value is returned, otherwise an IllegalArgumentException is thrown with the specifed message.


getOrThrow

public abstract <E extends Throwable> T getOrThrow(E e)
                      throws E extends Throwable
Returns its value if not empty, otherwise throws e.

Throws:
E extends Throwable

toStringOr

public abstract String toStringOr(String defaultValue)

isEmpty

public abstract boolean isEmpty()
Returns true if the option is the None value.


isDefined

public boolean isDefined()
Returns true if the option is a Some(...).


none

public static <T> Option<T> none()
Gets the none object for the given type. Note: using a freely parameterized type T with an unchecked warning allows to simulate a bottom type in Java.


some

public static <T> Option<T> some(T t)
Gets the some object wrapping the given value.


of

public static <T> Option<T> of(T t)
Wraps anything.

Type Parameters:
T -
Parameters:
t -
Returns:
if null, none(), some(t) otherwise


Copyright © 2014. All Rights Reserved.