Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

SafeComparator Class Reference

#include <coherence/util/comparator/SafeComparator.hpp>

Inherits Object, Comparator, QueryMapComparator, EntryAwareComparator, and PortableObject.

Inherited by EntryComparator, and InverseComparator.

List of all members.


Detailed Description

NULL-safe delegating comparator.

NULL values are evaluated as "less then" any non-null value. If the wrapped comparator is not specified then all non-null values must implement the coherence::util::Comparable interface. Use SafeComparator::getInstance to obtain an instance of non-delegating SafeComparator.

Author:
djl 2008.05.05

Public Types

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

Public Member Functions

virtual int32_t  compare (Object::View vO1, Object::View vO2) const
  Compares its two arguments for order.
virtual int32_t  compareEntries (QueryMap::Entry::View vEntry1, QueryMap::Entry::View vEntry2) const
  Compare two entries using the underlying comparator.
virtual bool  isKeyComparator () const
  Specifies whether this comparator expects to compare keys or values.
Returns:
true if Entry keys are expected; false otherwise

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 void  toStream (std::ostream &out) const
  Output a human-readable description of this Object to the given stream.

coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toStream 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.

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

 String::Handle hs = COH_TO_STRING(vKey << " = " << vValue);
Parameters:
out  the stream used to output the description

virtual Comparator::View  getComparator () const
  Obtain the wrapped Comparator.

Static Public Member Functions

static bool  isKeyComparator (Comparator::View vComparator)
  Check whether the specified comparator expects to compare keys or values.
static int32_t  compareSafe (Comparator::View vComparator, Object::View vO1, Object::View vO2)
  Compares its two arguments for order.
static
SafeComparator::Handle 
getInstance ()
  An instance of the SafeComparator.

Protected Member Functions

  SafeComparator ()
  Default constructor (necessary for the PortableObject interface).
  SafeComparator (Comparator::View vComparator)
  Construct a SafeComparator delegating to the specified (wrapped) comparator.

Protected Attributes

MemberView< Comparator m_vComparator
  The wrapped Comparator.

Constructor & Destructor Documentation

SafeComparator ( Comparator::View  vComparator  )  [protected]

Construct a SafeComparator delegating to the specified (wrapped) comparator.

Parameters:
vComparator  Comparator object to delegate comparison of non-null values (optional)

Member Function Documentation

virtual int32_t compare ( Object::View  vO1,
Object::View  vO2  
) const [virtual]

Compares its two arguments for order.

Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Null values are evaluated as "less then" any non-null value. If the wrapped comparator is not specified, all non-null values must implement the Comparable interface.

Parameters:
vO1  the first object to be compared
vO2  the second object to be compared
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second
Exceptions:
ClassCastException  if the arguments' types prevent them from being compared by this Comparator.

Implements Comparator.

Reimplemented in EntryComparator, and InverseComparator.

virtual int32_t compareEntries ( QueryMap::Entry::View  vEntry1,
QueryMap::Entry::View  vEntry2  
) const [virtual]

Compare two entries using the underlying comparator.

If the wrapped comparator does not implement the QueryMapComparator interface, revert to the entry values comparison.

Implements QueryMapComparator.

Reimplemented in InverseComparator.

static bool isKeyComparator ( Comparator::View  vComparator  )  [static]

Check whether the specified comparator expects to compare keys or values.

Parameters:
vComparator  a Comparator to check
Returns:
true if the comparator expects keys; false otherwise

virtual Comparator::View getComparator (  )  const [virtual]

Obtain the wrapped Comparator.

Returns:
the wrapped Comparator

static int32_t compareSafe ( Comparator::View  vComparator,
Object::View  vO1,
Object::View  vO2  
) [static]

Compares its two arguments for order.

Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Null values are evaluated as "less then" any non-null value. Non-null values must implement the coherence::util::Comparable interface.

Parameters:
vComparator  a comparator to use for the comparison (optional)
vO1  the first object to be compared
vO2  the second object to be compared
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second
Exceptions:
ClassCastException  if the arguments are not Comparable

Member Data Documentation

MemberView<Comparator> m_vComparator [protected]

The wrapped Comparator.

Could be null.


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