Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/filter/ArrayFilter.hpp

00001 /*
00002 * ArrayFilter.hpp
00003 *
00004 * Copyright (c) 2000, 2010, 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_ARRAY_FILTER_HPP
00017 #define COH_ARRAY_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/io/pof/PortableObject.hpp"
00024 #include "coherence/util/filter/EntryFilter.hpp"
00025 #include "coherence/util/filter/IndexAwareFilter.hpp"
00026 
00027 COH_OPEN_NAMESPACE3(coherence,util,filter)
00028 
00029 using coherence::io::pof::PofReader;
00030 using coherence::io::pof::PofWriter;
00031 using coherence::io::pof::PortableObject;
00032 
00033 
00034 /**
00035 * Filter which is a logical operator of a filter array.
00036 *
00037 * @author djl  2008.03.23
00038 */
00039 class COH_EXPORT ArrayFilter
00040     : public abstract_spec<ArrayFilter,
00041         extends<Object>,
00042         implements<IndexAwareFilter, PortableObject> >
00043     {
00044     // ----- constructors ---------------------------------------------------
00045 
00046     protected:
00047         /**
00048         * Default constructor (necessary for the PortableObject interface).
00049         */
00050         ArrayFilter();
00051 
00052         /**
00053         * Construct a logical filter that applies a binary operator to a
00054         * filter array. The result is defined as:
00055         *   aFilter[0] &lt;op&gt; aFilter[1] ... &lt;op&gt; aFilter[n]
00056         *
00057         * @param vaFilter  the filter array
00058         */
00059         ArrayFilter(ObjectArray::View vaFilter);
00060 
00061 
00062     // ----- PortableObject interface ---------------------------------------
00063 
00064      public:
00065         /**
00066         * {@inheritDoc}
00067         */
00068         virtual void readExternal(PofReader::Handle hIn);
00069 
00070         /**
00071         * {@inheritDoc}
00072         */
00073         virtual void writeExternal(PofWriter::Handle hOut) const;
00074 
00075 
00076     // ----- Object interface -----------------------------------------------
00077 
00078     public:
00079         /**
00080         * Compare the ArrayFilter with another object to determine
00081         * equality. Two ArrayFilter objects are considered equal
00082         * iff they belong to the same class and their underlying Filter
00083         * arrays are deep-equal.
00084         *
00085         * @return true iff this ArrayFilter and the passed object
00086         *         are equivalent
00087         */
00088         virtual bool equals(Object::View v) const;
00089 
00090         /**
00091         * {@inheritDoc}
00092         */
00093         virtual size32_t hashCode() const;
00094 
00095         /**
00096         * {@inheritDoc}
00097         */
00098         virtual void toStream(std::ostream& out) const;
00099 
00100 
00101     // ----- data member accessors ------------------------------------------
00102 
00103     public:
00104         /**
00105         * Obtain the Filter array.
00106         *
00107         * @return the Filter array
00108         */
00109         virtual ObjectArray::View getFilters() const;
00110 
00111 
00112     // ----- internal helpers -----------------------------------------------
00113 
00114     protected:
00115         /**
00116         * Calculate the effectiveness and sort all the participating filters
00117         * according to their effectiveness.
00118         *
00119         * @param vMapIndexes  the available MapIndex objects keyed by
00120         *                     the related ValueExtractor; read-only
00121         * @param vSetKeys     the set of keys that will be filtered; read-only
00122         *
00123         * @return the array of WeightedFilter objects sorted by the
00124         *         effectiveness (the most effective in the front)
00125         */
00126         virtual ObjectArray::View calculateFilters(Map::View vMapIndexes,
00127                 Set::View vSetKeys) const;
00128 
00129 
00130         /**
00131         * Apply the specified IndexAwareFilter to the specified keySet.
00132         *
00133         * @param vFilter      the IndexAwareFilter to apply an index to
00134         * @param vMapIndexes  the available MapIndex objects keyed by
00135         *                     the related ValueExtractor; read-only
00136         * @param hSetKeys     the mutable set of keys that remain to be
00137         *                     filtered
00138         *
00139         * @return a Filter object that can be used to process the remaining
00140         *         keys, or null if no additional filter processing is
00141         *         necessary
00142         */
00143         virtual Filter::View applyFilter(IndexAwareFilter::View vFilter,
00144                 Map::View vMapIndexes, Set::Handle hSetKeys) const;
00145 
00146 
00147     // ----- inner class: WeightedFilter ------------------------------------
00148 
00149     public:
00150         /**
00151         * A thin wrapper around a Filter allowing for sorting the filters
00152         * according to their effectiveness.
00153         *
00154         * @author tb  2009.02.09
00155         */
00156         class COH_EXPORT WeightedFilter
00157             : public class_spec<WeightedFilter,
00158                     extends<Object>,
00159                     implements<Comparable> >
00160             {
00161             friend class factory<WeightedFilter>;
00162 
00163             // ----- constructors ---------------------------------------
00164 
00165             protected:
00166                 /**
00167                 * Construct the WeightedFilter.
00168                 *
00169                 * @param vFilter  the wrapped filter
00170                 * @param nEffect  the filter's effectiveness
00171                 */
00172                 WeightedFilter(Filter::View vFilter, int32_t nEffect);
00173 
00174             // ----- Comparable interface -------------------------------
00175 
00176             public:
00177                 /**
00178                 * Compares this WeightedFilter with the specified
00179                 * WeightedFilter for order.  Returns a negative integer, zero,
00180                 * or a positive integer as this WeightedFilter's effectiveness
00181                 * is less than, equal to, or greater than the effectiveness of
00182                 * the specified WeightedFilter object.
00183                 *
00184                 * @param v  the Object to be compared
00185                 *
00186                 * @return a negative integer, zero, or a positive integer as
00187                 *         this object is less than, equal to, or greater than
00188                 *         the specified object
00189                 *
00190                 * @throws ClassCastException if the specified object's type
00191                 *         prevents it from being compared to this
00192                 *         WeightedFilter
00193                 */
00194                 int32_t compareTo(Object::View v) const;
00195 
00196             // ----- accessors ------------------------------------------
00197 
00198             public:
00199                 /**
00200                 * Get the wrapped filter.
00201                 *
00202                 * @return the wrapped filter
00203                 */
00204                 Filter::View getFilter() const;
00205 
00206                 /**
00207                 * Get the effectiveness value of the wrapped filter.
00208                 *
00209                 * @return the effectiveness of the wrapped filter
00210                 */
00211                 int32_t getEffectiveness() const;
00212 
00213             // ----- data members ---------------------------------------
00214 
00215             protected:
00216                 /**
00217                 * The wrapped filter.
00218                 */
00219                 MemberView<Filter> m_vFilter;
00220 
00221                 /**
00222                 * The effectiveness of the wrapped filter.
00223                 */
00224                 int32_t m_nEffect;
00225             };
00226 
00227 
00228     // ----- data members ---------------------------------------------------
00229 
00230     protected:
00231         /**
00232         * The Filter array.
00233         */
00234         MemberView<ObjectArray> m_vaFilter;
00235     };
00236 
00237 COH_CLOSE_NAMESPACE3
00238 
00239 #endif // COH_EXTRACTOR_FILTER_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.