org.javimmutable.collections
Interface Holder<T>

Type Parameters:
T -
All Known Implementing Classes:
Holders, LeafNode, LeafTrieNode

@Immutable
public interface Holder<T>

Instances are immutable containers for at most a single object. A Holder is either empty or filled and always remain in the same state once created, i.e. value returned by isEmpty() and isFilled() and getValue() must not change over time for a single instance. null is a legitimate value for a Holder and a filled Holder could return null from getValue().


Method Summary
 T getValue()
          Retrieve the value of a filled Holder.
 T getValueOr(T defaultValue)
          Retrieve the value of a filled Holder or the defaultValue if Holder is empty
 T getValueOrNull()
          Retrieve the value of a filled Holder or null if Holder is empty.
 boolean isEmpty()
           
 boolean isFilled()
           
 

Method Detail

isEmpty

boolean isEmpty()
Returns:
true iff this Holder has no value to return

isFilled

boolean isFilled()
Returns:
true iff this Holder has a value to return

getValue

T getValue()
Retrieve the value of a filled Holder. Must throw if Holder is empty.

Returns:
the (possibly null) value
Throws:
UnsupportedOperationException - if Holder is empty

getValueOrNull

T getValueOrNull()
Retrieve the value of a filled Holder or null if Holder is empty.

Returns:
null (empty) or value (filled)

getValueOr

T getValueOr(T defaultValue)
Retrieve the value of a filled Holder or the defaultValue if Holder is empty

Parameters:
defaultValue - value to return if Holder is empty
Returns:
value or defaultValue


Copyright © 2014 Burton Computer Corporation. All rights reserved.