Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


com.tangosol.util.comparator
Class EntryComparator

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.comparator.SafeComparator
          extended by com.tangosol.util.comparator.EntryComparator

All Implemented Interfaces:
ExternalizableLite, PortableObject, EntryAwareComparator, QueryMapComparator, Serializable, Comparator

public class EntryComparator
extends SafeComparator

Comparator implementation used to compare map entries. Depending on the comparison style this comparator will compare entries' values, entries' keys or, when the provided comparator is an instance of QueryMapComparator, the entries themselves.

Author:
gg 2002.12.14

Field Summary
static int CMP_AUTO
          Indicates that this EntryComparator should choose the comparison style based on the underying comparator type.
static int CMP_ENTRY
          Indicates that entries that implement QueryMap.Entry interface will be compared using the compareEntries() method.
static int CMP_KEY
          Indicates that this EntryComparator should compare the entries' keys.
static int CMP_VALUE
          Indicates that this EntryComparator should compare the entries' values.
protected  int m_nStyle
          Comparison style utilized by this EntryComparator.

 

Fields inherited from class com.tangosol.util.comparator.SafeComparator
INSTANCE, m_comparator

 

Constructor Summary
EntryComparator()
          Default constructor (for ExternalizableLite and PortableObject).
EntryComparator(Comparator comparator)
          Construct an EntryComparator to compare entries' values using the provided Comparator object.
EntryComparator(Comparator comparator, int nStyle)
          Construct an EntryComparator to compare entries using the provided Comparator object according to the specified comparison style.

 

Method Summary
 int compare(Object o1, Object o2)
          Compares two arguments for order.
 boolean equals(Object o)
          Determine if two EntryComparator objects are equal.
 int getComparisonStyle()
          Obtain the comparison style value utilized by this EntryComparator.
 boolean isCompareEntry()
          Check whether or not this EntryComparator pass entries themselves for comparison to the underlying compareEntries() method.
 boolean isCompareKey()
          Check whether or not this EntryComparator uses entries' keys to pass for comparison to the underlying Comparator.
 boolean isCompareValue()
          Check whether or not this EntryComparator uses entries' values to pass for comparison to the underlying Comparator.
 void readExternal(DataInput in)
          Restore the contents of this object by loading the object's state from the passed DataInput object.
 void readExternal(PofReader in)
          Restore the contents of a user type instance by reading its state using the specified PofReader object.
 void writeExternal(DataOutput out)
          Save the contents of this object by storing the object's state into the passed DataOutput object.
 void writeExternal(PofWriter out)
          Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

 

Methods inherited from class com.tangosol.util.comparator.SafeComparator
compareEntries, compareSafe, getComparator, hashCode, isKeyComparator, isKeyComparator, toString

 

Field Detail

CMP_AUTO

public static final int CMP_AUTO
Indicates that this EntryComparator should choose the comparison style based on the underying comparator type.
See Also:
Constant Field Values

CMP_VALUE

public static final int CMP_VALUE
Indicates that this EntryComparator should compare the entries' values.
See Also:
Constant Field Values

CMP_KEY

public static final int CMP_KEY
Indicates that this EntryComparator should compare the entries' keys.
See Also:
Constant Field Values

CMP_ENTRY

public static final int CMP_ENTRY
Indicates that entries that implement QueryMap.Entry interface will be compared using the compareEntries() method.
See Also:
Constant Field Values

m_nStyle

protected int m_nStyle
Comparison style utilized by this EntryComparator. Valid values are any of the CMP_* constants.

Constructor Detail

EntryComparator

public EntryComparator()
Default constructor (for ExternalizableLite and PortableObject).

EntryComparator

public EntryComparator(Comparator comparator)
Construct an EntryComparator to compare entries' values using the provided Comparator object. The EntryComparator will choose the comparison style based on the specified comparator type: if the comparator is an instance of the KeyExtractor, the CMP_KEY style will be assumed; otherwise, the CMP_VALUE style is used.
Parameters:
comparator - the comparator to use; if not specified the "natural" comparison of entries' values is used

EntryComparator

public EntryComparator(Comparator comparator,
                       int nStyle)
Construct an EntryComparator to compare entries using the provided Comparator object according to the specified comparison style. If the style is CMP_AUTO then the comparator type is checked: if the comparator is an instance of the KeyExtractor, the CMP_KEY style will be assumed; otherwise, the CMP_VALUE style is used.
Parameters:
comparator - the comparator to use; if not specified the "natural" comparison is used
nStyle - the comparison style to use; valid values are any of the CMP_* constants

Method Detail

compare

public int compare(Object o1,
                   Object o2)
Compares two arguments for order. The arguments must be Map.Entry objects. Depending on the comparison style, this method will pass either the entries' values, keys or the entries themselves to the underlying Comparator.
Specified by:
compare in interface Comparator
Overrides:
compare in class SafeComparator
Parameters:
o1 - the first object to be compared
o2 - 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

equals

public boolean equals(Object o)
Determine if two EntryComparator objects are equal.
Specified by:
equals in interface Comparator
Overrides:
equals in class SafeComparator
Parameters:
o - the other object
Returns:
true if the passed object is equal to this
See Also:
Object.equals(java.lang.Object), Object.hashCode()

getComparisonStyle

public int getComparisonStyle()
Obtain the comparison style value utilized by this EntryComparator. The returned value should be one of the CMP_* constants.
Returns:
the comparison style value

isCompareValue

public boolean isCompareValue()
Check whether or not this EntryComparator uses entries' values to pass for comparison to the underlying Comparator.
Returns:
true iff entries' values are used for comparison

isCompareKey

public boolean isCompareKey()
Check whether or not this EntryComparator uses entries' keys to pass for comparison to the underlying Comparator.
Returns:
true iff entries' keys are used for comparison

isCompareEntry

public boolean isCompareEntry()
Check whether or not this EntryComparator pass entries themselves for comparison to the underlying compareEntries() method.
Returns:
true iff entries themselves are used for comparison

readExternal

public void readExternal(DataInput in)
                  throws IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.
Specified by:
readExternal in interface ExternalizableLite
Overrides:
readExternal in class SafeComparator
Parameters:
in - the DataInput stream to read data from in order to restore the state of this object
Throws:
IOException - if an I/O exception occurs
NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into

writeExternal

public void writeExternal(DataOutput out)
                   throws IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.
Specified by:
writeExternal in interface ExternalizableLite
Overrides:
writeExternal in class SafeComparator
Parameters:
out - the DataOutput stream to write the state of this object to
Throws:
IOException - if an I/O exception occurs

readExternal

public void readExternal(PofReader in)
                  throws IOException
Restore the contents of a user type instance by reading its state using the specified PofReader object.
Specified by:
readExternal in interface PortableObject
Overrides:
readExternal in class SafeComparator
Parameters:
in - the PofReader from which to read the object's state
Throws:
IOException - if an I/O error occurs

writeExternal

public void writeExternal(PofWriter out)
                   throws IOException
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
Specified by:
writeExternal in interface PortableObject
Overrides:
writeExternal in class SafeComparator
Parameters:
out - the PofWriter to which to write the object's state
Throws:
IOException - if an I/O error occurs

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.