Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/util/aggregator/AbstractComparableAggregator.hpp

00001 /*
00002 * AbstractComparableAggregator.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_ABSTRACT_COMPARABLE_AGGREGATOR_HPP
00017 #define COH_ABSTRACT_COMPARABLE_AGGREGATOR_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/aggregator/AbstractAggregator.hpp"
00022 #include "coherence/util/Comparator.hpp"
00023 #include "coherence/util/ValueExtractor.hpp"
00024 
00025 COH_OPEN_NAMESPACE3(coherence,util,aggregator)
00026 
00027 using coherence::io::pof::PofReader;
00028 using coherence::io::pof::PofWriter;
00029 using coherence::io::pof::PortableObject;
00030 
00031 using coherence::util::Comparator;
00032 using coherence::util::ValueExtractor;
00033 
00034 
00035 /**
00036 * Abstract aggregator that processes values extracted from a set of entries
00037 * in a Map, with knowledge of how to compare those values. There are two ways
00038 * to use the AbstractComparableAggregator:
00039 * <ul>
00040 * <li>All the extracted objects must implement <tt>Comparable</tt>, or</li>
00041 * <li>The AbstractComparableAggregator has to be provided with a
00042 * <tt>Comparator object</tt>.</li>
00043 * </ul>
00044 * If the set of entries passed to <tt>aggregate</tt> is empty, a
00045 * <tt>NULL</tt> result is returned.
00046 *
00047 * @author djl/pp  2008.05.09
00048 */
00049 class COH_EXPORT AbstractComparableAggregator
00050     : public abstract_spec<AbstractComparableAggregator,
00051         extends<AbstractAggregator> >
00052     {
00053     // ----- constructors ---------------------------------------------------
00054 
00055     protected:
00056         /**
00057         * @internal
00058         */
00059         AbstractComparableAggregator();
00060 
00061         /**
00062         * Construct an AbstractComparableAggregator object.
00063         *
00064         * @param vExtractor  the extractor that provides an object to be compared
00065         * @param vComparator the comparator used to compare the extracted
00066         *                    object, if NULL then the extracted object must
00067         *                    implement Comparable
00068         */
00069         AbstractComparableAggregator(ValueExtractor::View vExtractor,
00070                 Comparator::View vComparator = NULL);
00071 
00072 
00073     // ----- AbstractAggregator Interface  ----------------------------------
00074 
00075     protected:
00076         /**
00077         * {@inheritDoc}
00078         */
00079         virtual void init(bool fFinal);
00080 
00081         /**
00082         * {@inheritDoc}
00083         */
00084         virtual Object::Holder finalizeResult(bool fFinal);
00085 
00086 
00087     // ----- PortableObject interface ---------------------------------------
00088 
00089     public:
00090         /**
00091         * {@inheritDoc}
00092         */
00093         virtual void readExternal(PofReader::Handle hIn);
00094 
00095         /**
00096         * {@inheritDoc}
00097         */
00098         virtual void writeExternal(PofWriter::Handle hOut) const;
00099 
00100 
00101     // ----- data members ---------------------------------------------------
00102 
00103     protected:
00104         /**
00105         * The count of processed entries.
00106         */
00107         int32_t m_count;
00108 
00109         /**
00110         * The running result value.
00111         */
00112         MemberView<Object> m_vResult;
00113 
00114         /**
00115         * The comparator to use for comparing extracted values.
00116         */
00117         MemberView<Comparator> m_vComparator;
00118     };
00119 
00120 COH_CLOSE_NAMESPACE3
00121 
00122 #endif // COH_ABSTRACT_COMPARABLE_AGGREGATOR_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.