Oracle Coherence for C++ API
Release 3.6.1.0

E18813-01

coherence/util/ReadOnlyMultiList.hpp

00001 /*
00002 * ReadOnlyMultiList.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_READ_ONLY_MULTI_LIST_HPP
00017 #define COH_READ_ONLY_MULTI_LIST_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/AbstractList.hpp"
00022 #include "coherence/util/Collection.hpp"
00023 #include "coherence/util/Iterator.hpp"
00024 #include "coherence/util/List.hpp"
00025 #include "coherence/util/Set.hpp"
00026 #include "coherence/util/WrapperCollections.hpp"
00027 
00028 
00029 COH_OPEN_NAMESPACE2(coherence,util)
00030 
00031 /**
00032 * Implementation of the List interface in a read-only fashion based on a
00033 * collection of arrays.
00034 * <p/>
00035 * This class also implements the Set interface, although the contents are
00036 * not checked to determine whether each element is unique. It is the
00037 * responsibility of the user to ensure that the elements are unique if the
00038 * object is used as a Set.
00039 * <p/>
00040 * Note: while preserved for backward compatibility, as of Coherence 3.6, use of
00041 *       this class specifically as a List or a Set is deprecated.  Instead, the
00042 *       getList(), getSet() methods should be used.
00043 *
00044 * @author gg, mf  2009.1.20
00045 *
00046 * @since Coherence 3.6
00047 * @see ReadOnlyArrayList
00048 */
00049 class COH_EXPORT ReadOnlyMultiList
00050     : public class_spec<ReadOnlyMultiList,
00051         extends<AbstractList>,
00052         implements<Set> >
00053     {
00054     friend class factory<ReadOnlyMultiList>;
00055 
00056     // ----- handle definitions (needed for nested classes) -----------------
00057 
00058     public:
00059         typedef this_spec::Handle Handle;
00060         typedef this_spec::View   View;
00061         typedef this_spec::Holder Holder;
00062 
00063 
00064     // ----- constructors ---------------------------------------------------
00065 
00066     protected:
00067         /**
00068         * Construct a List containing the elements of the specified array of
00069         * Object arrays.
00070         *
00071         * @param vaao  the array of arrays backing the MultiList
00072         */
00073         ReadOnlyMultiList(ObjectArray::View vaao);
00074 
00075 
00076     // ----- accessors ------------------------------------------------------
00077         
00078     public:
00079         /**
00080         * Return a List view of this ReadOnlyMultiList.
00081         *
00082         * @return a List view of this ReadOnlyMultiList
00083         */
00084         virtual List::Handle getList();
00085 
00086         /**
00087         * Return a List view of this ReadOnlyMultiList.
00088         *
00089         * @return a List view of this ReadOnlyMultiList
00090         */
00091         virtual List::View getList() const;
00092 
00093         /**
00094         * Return a Set view of this ReadOnlyMultiList.
00095         *
00096         * @return a Set view of this ReadOnlyMultiList
00097         */
00098         virtual Set::Handle getSet();
00099 
00100         /**
00101         * Return a Set view of this ReadOnlyMultiList.
00102         *
00103         * @return a Set view of this ReadOnlyMultiList
00104         */
00105         virtual Set::View getSet() const;
00106 
00107         
00108     // ----- List interface -------------------------------------------------
00109 
00110     public:
00111         /**
00112         * {@inheritDoc}
00113         */
00114         virtual size32_t size() const;
00115 
00116         /**
00117         * {@inheritDoc}
00118         */
00119         virtual Object::Holder get(size32_t i) const;
00120         using List::get;
00121 
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual Object::Holder set(size32_t i, Object::Holder oh);
00126 
00127         /**
00128         * {@inheritDoc}
00129         */
00130         virtual bool add(size32_t i, Object::Holder oh);
00131         using Collection::add;
00132 
00133         /**
00134         * {@inheritDoc}
00135         */
00136         virtual bool addAll(size32_t i, Collection::View vColl);
00137         using Collection::addAll;
00138 
00139         /**
00140         * {@inheritDoc}
00141         */
00142         virtual Object::Holder remove(size32_t i);
00143         using Collection::remove;
00144 
00145         /**
00146         * {@inheritDoc}
00147         */
00148         virtual size32_t indexOf(Object::View v) const;
00149 
00150         /**
00151         * {@inheritDoc}
00152         */
00153         virtual size32_t lastIndexOf(Object::View v) const;
00154 
00155         /**
00156         * {@inheritDoc}
00157         */
00158         virtual bool contains(Object::View v) const;
00159 
00160         /**
00161         * {@inheritDoc}
00162         */
00163         virtual ObjectArray::Handle toArray(ObjectArray::Handle ha = NULL) const;
00164 
00165         /**
00166         * {@inheritDoc}
00167         */
00168         virtual Iterator::Handle iterator() const;
00169         using Collection::iterator;
00170 
00171         /**
00172         * {@inheritDoc}
00173         */
00174         virtual Muterator::Handle iterator();
00175         using List::iterator;
00176 
00177         /**
00178         * {@inheritDoc}
00179         */
00180         virtual ListIterator::Handle listIterator(size32_t i = 0) const;
00181 
00182         /**
00183         * {@inheritDoc}
00184         */
00185         virtual ListMuterator::Handle listIterator(size32_t i = 0);
00186 
00187         /**
00188         * {@inheritDoc}
00189         */
00190         virtual List::View subList(size32_t iFrom, size32_t iTo) const;
00191 
00192         /**
00193         * {@inheritDoc}
00194         */
00195         virtual List::Handle subList(size32_t iFrom, size32_t iTo);
00196 
00197 
00198     // ----- Object methods -------------------------------------------------
00199 
00200     public:
00201         /**
00202         * {@inheritDoc}
00203         */
00204         virtual bool equals(Object::View v) const;
00205 
00206 
00207     // ----- helpers --------------------------------------------------------
00208 
00209     public:
00210         /**
00211         * Calculate the total number of element in the array of arrays.
00212         *
00213         * @param vaao  an array of arrays
00214         *
00215         * @return the total number of elements
00216         */
00217         static size32_t calculateTotalLength(ObjectArray::View vaao);
00218 
00219         /**
00220         * Create a single dimensional array containing all elements of the
00221         * specified array of arrays.
00222         *
00223         * @param vaaoFrom  an array of arrays to copy from
00224         * @param cTotal    the total length of the flattened array; pass npos
00225         *                  for it to be calculated
00226         * @param vaoTo     an array to copy the elements into (optional)
00227         *
00228         * @return an array containing all the elements of the array of arrays
00229         *
00230         * @throws ArrayIndexOutOfBoundsException if the total length parameter
00231         *         was not sufficient to hold the flattened array
00232         */
00233         static ObjectArray::Handle flatten(ObjectArray::View vaaoFrom,
00234                 size32_t cTotal, ObjectArray::Handle haoTo = NULL);
00235 
00236     protected:
00237         /**
00238         * Common subList method implementation.
00239         */
00240         template<class T> static List::Holder subList(T, size32_t iFrom,
00241                 size32_t iTo);
00242 
00243 
00244     // ----- inner class: ListView ------------------------------------------
00245 
00246     protected:
00247         /**
00248         * ListView exposes the underlying ReadOnlyMultiList through the List
00249         * interface, maintaining correct equals() and hashCode() semantics.
00250         */
00251         class COH_EXPORT ListView
00252             : public class_spec<ListView,
00253                 extends<WrapperCollections::AbstractWrapperList> >
00254             {
00255             friend class factory<ListView>;
00256             
00257             // ----- constructors -------------------------------------------
00258 
00259             protected:    
00260                 /**
00261                 * Construct a ListView over the specified ReadOnlyMultiList.
00262                 */
00263                 ListView(ReadOnlyMultiList::Holder ohList);
00264 
00265             
00266             // ----- Object methods -----------------------------------------
00267 
00268                 /**
00269                 * {@inheritDoc}
00270                 */
00271                 virtual bool equals(Object::View v) const;
00272 
00273                 /**
00274                 * {@inheritDoc}
00275                 */
00276                 virtual size32_t hashCode() const;
00277             };
00278 
00279 
00280     // ----- inner class: SetView -------------------------------------------
00281 
00282     protected:
00283         /**
00284         * SetView exposes the underlying ReadOnlyMultiList through the Set
00285         * interface, maintaining correct equals() and hashCode() semantics.
00286         */
00287         class COH_EXPORT SetView
00288             : public class_spec<SetView,
00289                 extends<WrapperCollections::AbstractWrapperSet> >
00290             {
00291             friend class factory<SetView>;
00292             
00293             // ----- constructors -------------------------------------------
00294 
00295             protected:    
00296                 /**
00297                 * Construct a SetView over the specified ReadOnlyMultiList.
00298                 */
00299                 SetView(ReadOnlyMultiList::Holder ohSet);
00300 
00301             
00302             // ----- Object methods -----------------------------------------
00303 
00304                 /**
00305                 * {@inheritDoc}
00306                 */
00307                 virtual bool equals(Object::View v) const;
00308 
00309                 /**
00310                 * {@inheritDoc}
00311                 */
00312                 virtual size32_t hashCode() const;
00313             };
00314 
00315 
00316     // ----- data members ---------------------------------------------------
00317 
00318     private:
00319         /**
00320         * The array of Object arrays.
00321         */
00322         FinalView<ObjectArray> m_vaao;
00323 
00324         /**
00325         * A fully realized HashSet of this collections contents. This is
00326         * inflated and used for doing Set based operations if it is detected
00327         * that this collection is large and being accessed as a Set.
00328         */
00329         mutable MemberView<Set> m_vSet;
00330 
00331         /**
00332         * The total number of items.
00333         */
00334         const size32_t m_cTotal;
00335     };
00336 
00337 COH_CLOSE_NAMESPACE2
00338 
00339 #endif // COH_READ_ONLY_MULTI_LIST_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.