coherence/util/filter/ComparisonFilter.hpp

00001 /*
00002 * ComparisonFilter.hpp
00003 *
00004 * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_COMPARISON_FILTER_HPP
00017 #define COH_COMPARISON_FILTER_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/pof/PofReader.hpp"
00022 #include "coherence/io/pof/PofWriter.hpp"
00023 #include "coherence/util/ValueExtractor.hpp"
00024 #include "coherence/util/filter/ExtractorFilter.hpp"
00025 
00026 COH_OPEN_NAMESPACE3(coherence,util,filter)
00027 
00028 using coherence::io::pof::PofReader;
00029 using coherence::io::pof::PofWriter;
00030 
00031 
00032 /**
00033 * Filter which compares the result of a method invocation with a value.
00034 *
00035 * @author djl  2008.03.02
00036 */
00037 class COH_EXPORT ComparisonFilter
00038     : public abstract_spec<ComparisonFilter,
00039         extends<ExtractorFilter> >
00040     {
00041     // ----- constructors ---------------------------------------------------
00042 
00043     protected:
00044         /**
00045         * Default constructor (necessary for the ExternalizableLite interface).
00046         */
00047         ComparisonFilter();
00048 
00049         /**
00050         * Construct a ComparisonFilter.
00051         *
00052         * @param vExtractor the ComparisonFilter to use by this filter
00053         * @param vObject    the object to compare the result with
00054         */
00055         ComparisonFilter(ValueExtractor::View vValueExtractor,
00056                 Object::View vObject);
00057 
00058 
00059     // ----- PortableObject interface ---------------------------------------
00060 
00061     public:
00062         /**
00063         * {@inheritDoc}
00064         */
00065         virtual void readExternal(PofReader::Handle hIn);
00066 
00067         /**
00068         * {@inheritDoc}
00069         */
00070         virtual void writeExternal(PofWriter::Handle hOut) const;
00071 
00072 
00073     // ----- helpers --------------------------------------------------------
00074 
00075     protected:
00076         /**
00077         * Helper method to calculate effectiveness for ComparisonFilters that
00078         * need no more than a single index match in order to retrieve all
00079         * necessary keys to perform the applyIndex() operation.
00080         * Such filters are: Contains, Equals, NotEquals.
00081         *
00082         * @param vMapIndexes  the available MapIndex objects keyed by the
00083         *                     related ValueExtractor; read-only
00084         * @param vSetKeys     the set of keys that will be filtered; read-only
00085         *
00086         * @return an effectiveness estimate of how well this filter can use
00087         *         the specified indexes to filter the specified keys
00088         */
00089         virtual int32_t calculateMatchEffectiveness(Map::View vMapIndexes,
00090                 Set::View vSetKeys) const;
00091 
00092         /**
00093         * Helper method to calculate effectiveness for ComparisonFilters that
00094         * need a range of values from an index in order to retrieve all
00095         * necessary keys to perform the applyIndex() operation.
00096         * Such filters are: Less, LessEquals, Greater, GreaterEquals.
00097         *
00098         * @param vMapIndexes  the available MapIndex objects keyed by the
00099         *                     related ValueExtractor; read-only
00100         * @param vSetKeys     the set of keys that will be filtered; read-only
00101         *
00102         * @return an effectiveness estimate of how well this filter can use
00103         *         the specified indexes to filter the specified keys
00104         */
00105         virtual int32_t calculateRangeEffectiveness(Map::View vMapIndexes,
00106                 Set::View vSetKeys) const;
00107 
00108     public:
00109         /**
00110         * Helper method to calculate effectiveness (or rather ineffectiveness)
00111         * of a simple iteration against a key set that has to be performed due
00112         * to an absence of corresponding index.
00113         *
00114         * @param cKeys  the number of keys to iterate through
00115         */
00116         static int32_t calculateIteratorEffectiveness(int32_t cKeys);
00117 
00118 
00119     // ----- Object interface -----------------------------------------------
00120 
00121     public:
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual bool equals(Object::View v) const;
00126 
00127         /**
00128         * {@inheritDoc}
00129         */
00130         virtual size32_t hashCode() const;
00131 
00132         /**
00133         * {@inheritDoc}
00134         */
00135         virtual void toStream(std::ostream& out) const;
00136 
00137 
00138     // ----- data member accessors ------------------------------------------
00139 
00140     public:
00141         /**
00142         * Get the object to compare the reflection result with.
00143         *
00144         * @return the object to compare the reflection result with
00145         */
00146         virtual Object::View getValue() const;
00147 
00148 
00149     // ----- data members ---------------------------------------------------
00150 
00151     protected:
00152         /**
00153         * The ValueExtractor used by this filter.
00154         */
00155         MemberView<Object> m_vValue;
00156     };
00157 
00158 COH_CLOSE_NAMESPACE3
00159 
00160 #endif // COH_COMPARISON_FILTER_HPP
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.