Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.4.0)

E90870-01

Optional Class Reference

#include <coherence/util/Optional.hpp>

Inherits Object, and PortableObject.

List of all members.


Detailed Description

C++ 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.

Author:
as,lh 2015.06.09
Since:
Coherence 12.2.1

Public Types

typedef spec::Handle Handle
 Optional Handle definition.
typedef spec::View View
 Optional View definition.
typedef spec::Holder Holder
 Optional Holder definition.

Public Member Functions

virtual Object::Holder get () const
 Return the object value.
virtual bool isPresent () const
 Return true if there is a value present, otherwise false.
virtual Object::Holder orElse (Object::Holder oh) const
 Return value if present, otherwise, the given object.
virtual void readExternal (PofReader::Handle hIn)
 
virtual void writeExternal (PofWriter::Handle hOut) const
 
virtual bool equals (Object::View v) const
 
virtual size32_t hashCode () const
 Return a hash code value for the Object.

This method is supported for the benefit of hash-based containers.

The general contract of hashCode is:

  • Whenever it is invoked on the same Object more than once during an execution of an application, the hashCode method must consistently return the same value, provided no information used in equals comparisons on the object is modified. This value need not remain consistent from one execution of an application to another execution of the same application.
  • If two Objects are equal according to the equals method, then calling the hashCode method on each of the two Objects must produce the same value.
  • It is not required that if two Objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct results. However, the programmer should be aware that producing distinct results for unequal objects may improve the performance of hash-based containers.

The default implementation is identity based.

Returns:
a hash code value for this Object

virtual TypedHandle
< const String
toString () const
 Output a human-readable description of this Object to the given stream.

Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.

 Object::View vKey   = ...
 Object::View vValue = ...
 std::cout << vKey << " = " << vValue << std::endl;

 String::View vs = COH_TO_STRING(vKey << " = " << vValue);

The COH_TO_STRING macro is also the most common way to implement the toString method. For example:

 virtual TypedHandle<const String> Person::toString() const
     {
     return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN);
     }

Returns:
a string representation of this object


Static Public Member Functions

static Optional::View empty ()
 Return an Optional instance with NULL object value.
static Optional::View of (Object::Holder oh)
 Return an Optional instance with the given object value.
static Optional::View ofNullable (Object::Holder oh)
 Return an Optional instance with the given value, if non-NULL.
static Optional::View emptyInstance ()
 Return an empty Optional instance.

Protected Member Functions

 Optional ()
 Default constructor.

Member Function Documentation

static Optional::View empty (  )  [static]

Return an Optional instance with NULL object value.

Returns:
an Optional instance with NULL object value

static Optional::View of ( Object::Holder  oh  )  [static]

Return an Optional instance with the given object value.

Parameters:
voValue the object value it wraps
Returns:
an Optional instance with the given object value

static Optional::View ofNullable ( Object::Holder  oh  )  [static]

Return an Optional instance with the given value, if non-NULL.

Otherwise, return an empty Optional.

Parameters:
oh the object value it wraps
Returns:
an Optional instance with the given nullable value.

virtual Object::Holder get (  )  const [virtual]

Return the object value.

Returns:
the object value

virtual bool isPresent (  )  const [virtual]

Return true if there is a value present, otherwise false.

Returns:
true if there is a value present, otherwise, false

virtual Object::Holder orElse ( Object::Holder  oh  )  const [virtual]

Return value if present, otherwise, the given object.

Parameters:
oh the default object value to return
Returns:
the value if present, otherwise, return the given object

static Optional::View emptyInstance (  )  [static]

Return an empty Optional instance.

Returns:
the empty Optional


The documentation for this class was generated from the following file:
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.