Show / Hide Table of Contents

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.

Inheritance
object
Optional
Implements
IPortableObject
Inherited Members
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
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 null.

Returns
Type Description
bool

true if the passed object reference is of the same class and has the same state as this object.

Overrides
object.Equals(object)

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
object.GetHashCode()

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
object.ToString()
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.

Implements

IPortableObject
In this article
Back to top Copyright © 2000, 2024, Oracle and/or its affiliates.