Show / Hide Table of Contents

Class SafeComparer

Null-safe delegating comparator.

Inheritance
object
SafeComparer
EntryComparer
InverseComparer
Implements
IQueryCacheComparer
IEntryAwareComparer
IComparer
IPortableObject
Inherited Members
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: Tangosol.Util.Comparator
Assembly: Coherence.dll
Syntax
public class SafeComparer : IQueryCacheComparer, IEntryAwareComparer, IComparer, IPortableObject
Remarks

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 IComparable interface.

Use SafeComparer.Instance to obtain an instance of non-delegating SafeComparer.

Constructors

SafeComparer()

Default constructor.

Declaration
public SafeComparer()

SafeComparer(IComparer)

Construct a SafeComparer delegating to the specified (wrapped) comparer.

Declaration
public SafeComparer(IComparer comparer)
Parameters
Type Name Description
IComparer comparer

IComparer object to delegate comparison of non-null values (optional).

Fields

Instance

The trivial SafeComparer.

Declaration
public static readonly SafeComparer Instance
Field Value
Type Description
SafeComparer

m_comparer

The wrapped IComparer.

Declaration
protected IComparer m_comparer
Field Value
Type Description
IComparer

Properties

Comparer

The wrapped IComparer.

Declaration
public virtual IComparer Comparer { get; }
Property Value
Type Description
IComparer

The wrapped IComparer.

Methods

Compare(object, object)

Compares its two arguments for order.

Declaration
public virtual int Compare(object o1, object o2)
Parameters
Type Name Description
object o1

The first object to be compared.

object o2

The second object to be compared.

Returns
Type Description
int

A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Remarks

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 comparer is not specified, all non-null values must implement the IComparable interface.

Exceptions
Type Condition
InvalidCastException

If the arguments' types prevent them from being compared by this IComparer.

CompareEntries(IQueryCacheEntry, IQueryCacheEntry)

Compare two entries based on the rules specified by IComparer.

Declaration
public virtual int CompareEntries(IQueryCacheEntry entry1, IQueryCacheEntry entry2)
Parameters
Type Name Description
IQueryCacheEntry entry1

The first entry to compare values from; read-only.

IQueryCacheEntry entry2

The second entry to compare values from; read-only.

Returns
Type Description
int

A negative integer, zero, or a positive integer as the first entry denotes a value that is is less than, equal to, or greater than the value denoted by the second entry .

Remarks

If possible, use the Extract(IValueExtractor) method to optimize the value extraction process.

This method is expected to be implemented by IComparer wrappers, which simply pass on this invocation to the wrapped IComparer objects if they too implement this interface, or to invoke their default compare method passing the actual objects (not the extracted values) obtained from the extractor using the passed entries.

This interface is also expected to be implemented by IValueExtractor implementations that implement the IComparer interface. It is expected that in most cases, the IComparer wrappers will eventually terminate at (i.e. delegate to) IValueExtractors that also implement this interface.

Exceptions
Type Condition
InvalidCastException

If the arguments' types prevent them from being compared by this IComparer.

ArgumentException

If the extractor cannot handle the passed objects for any other reason; an implementor should include a descriptive message.

CompareSafe(IComparer, object, object)

Compares its two arguments for order.

Declaration
public static int CompareSafe(IComparer comparer, object o1, object o2)
Parameters
Type Name Description
IComparer comparer

A comparer to use for the comparison (optional).

object o1

The first object to be compared.

object o2

The second object to be compared.

Returns
Type Description
int

A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Remarks

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 that do not implement IComparable interface will be evaluated as equal.

Exceptions
Type Condition
ArgumentException

If the arguments are not of the same type or do not implement IComparable.

Equals(object)

Determine if two comparers are equal.

Declaration
public override bool Equals(object o)
Parameters
Type Name Description
object o

The other comparer.

Returns
Type Description
bool

true if the passed object is equal to this.

Overrides
object.Equals(object)

GetHashCode()

Return the hash code for this comparator.

Declaration
public override int GetHashCode()
Returns
Type Description
int

The hash code value for this comparator.

Overrides
object.GetHashCode()

IsKeyComparer()

Specifies whether this comparer expects to compare keys or values.

Declaration
public bool IsKeyComparer()
Returns
Type Description
bool

true if entry keys are expected; false otherwise.

IsKeyComparer(IComparer)

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

Declaration
public static bool IsKeyComparer(IComparer comparer)
Parameters
Type Name Description
IComparer comparer

A IComparer to check.

Returns
Type Description
bool

true if the comparer expects keys; false otherwise.

ReadExternal(IPofReader)

Restore the contents of a user type instance by reading its state using the specified IPofReader object.

Declaration
public virtual void ReadExternal(IPofReader reader)
Parameters
Type Name Description
IPofReader reader

The IPofReader from which to read the object's state.

Exceptions
Type Condition
IOException

If an I/O error occurs.

ToString()

Returns a human-readable description for this IComparer.

Declaration
public override string ToString()
Returns
Type Description
string

A string description of the IComparer.

Overrides
object.ToString()

WriteExternal(IPofWriter)

Save the contents of a POF user type instance by writing its state using the specified IPofWriter object.

Declaration
public virtual void WriteExternal(IPofWriter writer)
Parameters
Type Name Description
IPofWriter writer

The IPofWriter to which to write the object's state.

Exceptions
Type Condition
IOException

If an I/O error occurs.

Implements

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