Class Optional
.NET port of java.util.Optional, a container object which may or may not contain a non-null value. If a value is present, IsPresent() will return true and Get() will return the value.
Implements
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public class Optional : IPortableObject
Constructors
Optional()
Default constructor.
Declaration
public Optional()
Properties
IsPresent
Whether there is a value present.
Declaration
public bool IsPresent { get; }
Property Value
Type | Description |
---|---|
bool | True if there is a value present, otherwise false. |
Value
The value of the Optional object; can be null.
Declaration
public object Value { get; }
Property Value
Type | Description |
---|---|
object | The value of the Optional object. |
Methods
Empty()
Returns a Optional instance with null object value.
Declaration
public static Optional Empty()
Returns
Type | Description |
---|---|
Optional | An instance of Optional object with null value. |
Equals(object)
Compares this object with another object for equality.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | An object reference or |
Returns
Type | Description |
---|---|
bool | true if the passed object reference is of the same class and has the same state as this object. |
Overrides
GetHashCode()
Returns a hash code value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code value for this object. |
Overrides
Of(object)
Returns an Optional instance with the given object value.
Declaration
public static Optional Of(object value)
Parameters
Type | Name | Description |
---|---|---|
object | value | Object to wrap. |
Returns
Type | Description |
---|---|
Optional | An instance of Optional with the given object value. |
OfNullable(object)
Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
Declaration
public static Optional OfNullable(object value)
Parameters
Type | Name | Description |
---|---|---|
object | value | The possibly-null value to describe. |
Returns
Type | Description |
---|---|
Optional | An Optional with a present value if the specified value is non-null, otherwise an empty Optional. |
OrElse(object)
Returns value if present, otherwise, return the given object.
Declaration
public object OrElse(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o | The default object to return. |
Returns
Type | Description |
---|---|
object | Returns value if present, otherwise, return the given object. |
ReadExternal(IPofReader)
Restore the contents of a user type instance by reading its state using the specified IPofReader object.
Declaration
public void ReadExternal(IPofReader reader)
Parameters
Type | Name | Description |
---|---|---|
IPofReader | reader | The IPofReader from which to read the object's state. |
ToString()
Returns a non-empty string representation of this Optional suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The string representation of this instance. |
Overrides
Remarks
If a value is present the result must include its string representation in the result. Empty and present Optionals must be unambiguously differentiable.
WriteExternal(IPofWriter)
Save the contents of a POF user type instance by writing its state using the specified IPofWriter object.
Declaration
public void WriteExternal(IPofWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IPofWriter | writer | The IPofWriter to which to write the object's state. |