#include <coherence/util/extractor/AbstractExtractor.hpp>
Inherits Object, ValueExtractor, QueryMapComparator, and PortableObject.
Inherited by AbstractCompositeExtractor, EntryExtractor, IdentityExtractor, KeyExtractor, and ReflectionExtractor.
It provides common functionality that allows any extending extractor to be used as a value Comparator.
Public Types | |||||||||||||
| typedef spec::Handle | Handle | ||||||||||||
| AbstractExtractor Handle definition. | |||||||||||||
| typedef spec::View | View | ||||||||||||
| AbstractExtractor View definition. | |||||||||||||
| typedef spec::Holder | Holder | ||||||||||||
| AbstractExtractor Holder definition. | |||||||||||||
Public Member Functions | |||||||||||||
| virtual Object::Holder | extract (Object::Holder ohTarget) const =0 | ||||||||||||
| Extract the value from the passed object. The returned value may be NULL.
| |||||||||||||
| virtual int32_t | compareEntries (QueryMap::Entry::View vEntry1, QueryMap::Entry::View vEntry2) const | ||||||||||||
| Compare two entries based on the rules specified by Comparator. If possible, use the coherence::util::QueryMap.Entry::extract() method to optimize the value extraction process. This method is expected to be implemented by Comparator wrappers, such as ChainedComparator and InverseComparator, which simply pass on this invocation to the wrapped Comparator 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 ValueExtractor implementations that implement the Comparator interface. It is expected that in most cases, the Comparator wrappers will eventually terminate at (i.e. delegate to) ValueExtractors that also implement this interface.
| |||||||||||||
| virtual int32_t | compare (Object::View v1, Object::View v2) const | ||||||||||||
| Compare two Objects. If both Objects are comparable with this Comparator, return < 0, 0 or > 0 if the first Object is less than, equal to, or greater than the second Object. The general contract for this method is:
A typical implementation of Comparator may look as follows: int32_t MyTypeComparator::compare(Object::View v1, Object::View v2) const { // compares instances of class MyType only if (!v1 || !v2) { COH_THROW(NullPointerException()); } MyType::View vTypedObj1 = cast<MyType::View>(v1); MyType::View vTypedObj2 = cast<MyType::View>(v2); if (!vTypedObj1 || !vTypedObj1) { COH_THROW(IllegalArgumentException("Instances of MyType expected")); } // here we suppose that the state of the MyType is defined by // single field of integer type if (vTypedObj1->m_intField == vTypedObj2->m_intField) { return 0; } else if (vTypedObj1->m_intField < vTypedObj2->m_intField) { return -1; } else { return 1; } } | |||||||||||||