org.littleshoot.util
Interface OptionalUtils

All Known Implementing Classes:
OptionalUtilsImpl

public interface OptionalUtils

Utilities for working with Optional objects.


Method Summary
<T> void
executeOnSome(Optional<T> optional, Closure<T> closure)
          Executes a given closure on an optional object.
<T> Collection<T>
filterNones(Collection<Optional<T>> c)
          Filters out the None elements in a collection and returns a collection of the objects inside the remaining Some elements.
<T> boolean
isNone(Optional<T> optional)
          Returns whether an optional object is a None object.
 boolean isSome(Optional optional)
          Returns whether an optional object is a Some object.
 Optional optionalOf(Object object)
          Returns an Optional from a possible null object.
<T> T
someObject(Optional<T> optional)
          Returns the object stored in an optional object if one exists.
<T1,T2> Optional<T2>
transformSome(Optional<T1> optional, Transformer<T1,T2> transformer)
          Returns an Optional object created by transforming the contents of another Optional object.
 

Method Detail

optionalOf

Optional optionalOf(Object object)
Returns an Optional from a possible null object. If the object is null, None is returned. Otherwise, a Some object containing the given object is returned.

Parameters:
object - The object, possible null.
Returns:
If object is null, then None is returned, otherwise a Some containing object is returned.

transformSome

<T1,T2> Optional<T2> transformSome(Optional<T1> optional,
                                   Transformer<T1,T2> transformer)
Returns an Optional object created by transforming the contents of another Optional object. If the given Optional is a None, then None is returned. If the given Optional is a Some, then the contents of the Some are transformed and the result wrapped in a Some is returned.

Parameters:
optional - The Optional object to be transformed.
transformer - The transformer used to transform the contents of a Some object.
Returns:
An Optional object whose contents, if they exists, have been transformed by the given transformer.

isNone

<T> boolean isNone(Optional<T> optional)
Returns whether an optional object is a None object.

Parameters:
optional - The optional object.
Returns:
True if optional is a None, false otherwise.

isSome

boolean isSome(Optional optional)
Returns whether an optional object is a Some object.

Parameters:
optional - The optional object.
Returns:
True if optional is a Some, false otherwise.

someObject

<T> T someObject(Optional<T> optional)
             throws IllegalArgumentException
Returns the object stored in an optional object if one exists. Otherwise, an exception is thrown.

Parameters:
optional - The optional object.
Returns:
The object stored in the optional object, if it exists.
Throws:
IllegalArgumentException - If the optional object is not a Some object.

executeOnSome

<T> void executeOnSome(Optional<T> optional,
                       Closure<T> closure)
Executes a given closure on an optional object.

Type Parameters:
T - The type of object held by the optional object.
Parameters:
optional - The optional object.
closure - The closure to execute on the object held by the optional object, if it exists.

filterNones

<T> Collection<T> filterNones(Collection<Optional<T>> c)
Filters out the None elements in a collection and returns a collection of the objects inside the remaining Some elements.

Type Parameters:
T - The type of the objects inside the some objects.
Parameters:
c - The collection to filter.
Returns:
A collection of type T elements.


Copyright © 2011-2013 LittleShoot. All Rights Reserved.