Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.3.0)

E80355-01

coherence/util/ReadOnlyMultiList.hpp

00001 /*
00002 * ReadOnlyMultiList.hpp
00003 *
00004 * Copyright (c) 2000, 2017, 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 *
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 *
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     private:
00076         /**
00077         * Blocked copy constructor.
00078         */
00079         ReadOnlyMultiList(const ReadOnlyMultiList&);
00080 
00081 
00082     // ----- accessors ------------------------------------------------------
00083 
00084     public:
00085         /**
00086         * Return a List view of this ReadOnlyMultiList.
00087         *
00088         * @return a List view of this ReadOnlyMultiList
00089         */
00090         virtual List::Handle getList();
00091 
00092         /**
00093         * Return a List view of this ReadOnlyMultiList.
00094         *
00095         * @return a List view of this ReadOnlyMultiList
00096         */
00097         virtual List::View getList() const;
00098 
00099         /**
00100         * Return a Set view of this ReadOnlyMultiList.
00101         *
00102         * @return a Set view of this ReadOnlyMultiList
00103         */
00104         virtual Set::Handle getSet();
00105 
00106         /**
00107         * Return a Set view of this ReadOnlyMultiList.
00108         *
00109         * @return a Set view of this ReadOnlyMultiList
00110         */
00111         virtual Set::View getSet() const;
00112 
00113 
00114     // ----- List interface -------------------------------------------------
00115 
00116     public:
00117         /**
00118         * {@inheritDoc}
00119         */
00120         virtual size32_t size() const;
00121 
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual Object::Holder get(size32_t i) const;
00126         using List::get;
00127 
00128         /**
00129         * {@inheritDoc}
00130         */
00131         virtual Object::Holder set(size32_t i, Object::Holder oh);
00132 
00133         /**
00134         * {@inheritDoc}
00135         */
00136         virtual bool add(size32_t i, Object::Holder oh);
00137         using Collection::add;
00138 
00139         /**
00140         * {@inheritDoc}
00141         */
00142         virtual bool addAll(size32_t i, Collection::View vColl);
00143         using Collection::addAll;
00144 
00145         /**
00146         * {@inheritDoc}
00147         */
00148         virtual Object::Holder remove(size32_t i);
00149         using Collection::remove;
00150 
00151         /**
00152         * {@inheritDoc}
00153         */
00154         virtual size32_t indexOf(Object::View v) const;
00155 
00156         /**
00157         * {@inheritDoc}
00158         */
00159         virtual size32_t lastIndexOf(Object::View v) const;
00160 
00161         /**
00162         * {@inheritDoc}
00163         */
00164         virtual bool contains(Object::View v) const;
00165 
00166         /**
00167         * {@inheritDoc}
00168         */
00169         virtual ObjectArray::Handle toArray(ObjectArray::Handle ha = NULL) const;
00170 
00171         /**
00172         * {@inheritDoc}
00173         */
00174         virtual Iterator::Handle iterator() const;
00175         using Collection::iterator;
00176 
00177         /**
00178         * {@inheritDoc}
00179         */
00180         virtual Muterator::Handle iterator();
00181         using List::iterator;
00182 
00183         /**
00184         * {@inheritDoc}
00185         */
00186         virtual ListIterator::Handle listIterator(size32_t i = 0) const;
00187 
00188         /**
00189         * {@inheritDoc}
00190         */
00191         virtual ListMuterator::Handle listIterator(size32_t i = 0);
00192 
00193         /**
00194         * {@inheritDoc}
00195         */
00196         virtual List::View subList(size32_t iFrom, size32_t iTo) const;
00197 
00198         /**
00199         * {@inheritDoc}
00200         */
00201         virtual List::Handle subList(size32_t iFrom, size32_t iTo);
00202 
00203 
00204     // ----- Object methods -------------------------------------------------
00205 
00206     public:
00207         /**
00208         * {@inheritDoc}
00209         */
00210         virtual bool equals(Object::View v) const;
00211 
00212 
00213     // ----- helpers --------------------------------------------------------
00214 
00215     public:
00216         /**
00217         * Calculate the total number of element in the array of arrays.
00218         *
00219         * @param vaao  an array of arrays
00220         *
00221         * @return the total number of elements
00222         */
00223         static size32_t calculateTotalLength(ObjectArray::View vaao);
00224 
00225         /**
00226         * Create a single dimensional array containing all elements of the
00227         * specified array of arrays.
00228         *
00229         * @param vaaoFrom  an array of arrays to copy from
00230         * @param cTotal    the total length of the flattened array; pass npos
00231         *                  for it to be calculated
00232         * @param vaoTo     an array to copy the elements into (optional)
00233         *
00234         * @return an array containing all the elements of the array of arrays
00235         *
00236         * @throws ArrayIndexOutOfBoundsException if the total length parameter
00237         *         was not sufficient to hold the flattened array
00238         */
00239         static ObjectArray::Handle flatten(ObjectArray::View vaaoFrom,
00240                 size32_t cTotal, ObjectArray::Handle haoTo = NULL);
00241 
00242     protected:
00243         /**
00244         * Common subList method implementation.
00245         */
00246         template<class T> static List::Holder subList(T, size32_t iFrom,
00247                 size32_t iTo);
00248 
00249 
00250     // ----- inner class: ListView ------------------------------------------
00251 
00252     protected:
00253         /**
00254         * ListView exposes the underlying ReadOnlyMultiList through the List
00255         * interface, maintaining correct equals() and hashCode() semantics.
00256         */
00257         class COH_EXPORT ListView
00258             : public class_spec<ListView,
00259                 extends<WrapperCollections::AbstractWrapperList> >
00260             {
00261             friend class factory<ListView>;
00262 
00263             // ----- constructors -------------------------------------------
00264 
00265             protected:    
00266                 /**
00267                 * Construct a ListView over the specified ReadOnlyMultiList.
00268                 */
00269                 ListView(ReadOnlyMultiList::Holder ohList);
00270 
00271 
00272             // ----- Object methods -----------------------------------------
00273 
00274                 /**
00275                 * {@inheritDoc}
00276                 */
00277                 virtual bool equals(Object::View v) const;
00278 
00279                 /**
00280                 * {@inheritDoc}
00281                 */
00282                 virtual size32_t hashCode() const;
00283             };
00284 
00285 
00286     // ----- inner class: SetView -------------------------------------------
00287 
00288     protected:
00289         /**
00290         * SetView exposes the underlying ReadOnlyMultiList through the Set
00291         * interface, maintaining correct equals() and hashCode() semantics.
00292         */
00293         class COH_EXPORT SetView
00294             : public class_spec<SetView,
00295                 extends<WrapperCollections::AbstractWrapperSet> >
00296             {
00297             friend class factory<SetView>;
00298 
00299             // ----- constructors -------------------------------------------
00300 
00301             protected:    
00302                 /**
00303                 * Construct a SetView over the specified ReadOnlyMultiList.
00304                 */
00305                 SetView(ReadOnlyMultiList::Holder ohSet);
00306 
00307 
00308             // ----- Object methods -----------------------------------------
00309 
00310                 /**
00311                 * {@inheritDoc}
00312                 */
00313                 virtual bool equals(Object::View v) const;
00314 
00315                 /**
00316                 * {@inheritDoc}
00317                 */
00318                 virtual size32_t hashCode() const;
00319             };
00320 
00321 
00322     // ----- data members ---------------------------------------------------
00323 
00324     private:
00325         /**
00326         * The array of Object arrays.
00327         */
00328         FinalView<ObjectArray> f_vaao;
00329 
00330         /**
00331         * A fully realized HashSet of this collections contents. This is
00332         * inflated and used for doing Set based operations if it is detected
00333         * that this collection is large and being accessed as a Set.
00334         */
00335         mutable FinalView<Set> f_vSet;
00336 
00337         /**
00338         * The total number of items.
00339         */
00340         const size32_t m_cTotal;
00341     };
00342 
00343 COH_CLOSE_NAMESPACE2
00344 
00345 #endif // COH_READ_ONLY_MULTI_LIST_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.