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

E90870-01

coherence/util/LinkedList.hpp

00001 /*
00002 * LinkedList.hpp
00003 *
00004 * Copyright (c) 2000, 2019, 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_LINKED_LIST_HPP
00017 #define COH_LINKED_LIST_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/Collection.hpp"
00022 #include "coherence/util/ListIterator.hpp"
00023 #include "coherence/util/AbstractList.hpp"
00024 #include "coherence/util/SubList.hpp"
00025 
00026 COH_OPEN_NAMESPACE2(coherence,util)
00027 
00028 
00029 /**
00030 * A linked list implementation of List.
00031 *
00032 * @author nsa 2008.02.04
00033 */
00034 class COH_EXPORT LinkedList
00035     : public cloneable_spec<LinkedList,
00036         extends<AbstractList> >
00037     {
00038     friend class factory<LinkedList>;
00039 
00040     // ----- constructors ---------------------------------------------------
00041 
00042     protected:
00043         /**
00044         * Create a new LinkedList.
00045         *
00046         * @return a new LinkedList
00047         */
00048         LinkedList();
00049 
00050         /**
00051         * Create a new LinkedList that has a reference to every element in
00052         * the supplied collection.
00053         *
00054         * @param vc  The collection to base the LinkedList on
00055         *
00056         * @return a new LinkedList
00057         */
00058         LinkedList(Collection::View vc);
00059 
00060         /**
00061         * @internal
00062         */
00063         LinkedList(const LinkedList& that);
00064 
00065         /**
00066         * Destructor.
00067         */
00068         virtual ~LinkedList();
00069 
00070 
00071     // ----- List interface -------------------------------------------------
00072 
00073     public:
00074         /**
00075         * {@inheritDoc}
00076         */
00077         virtual bool add(size32_t i, Object::Holder oh);
00078 
00079         /**
00080         * {@inheritDoc}
00081         */
00082         virtual bool addAll(size32_t i, Collection::View vc);
00083 
00084         /**
00085         * {@inheritDoc}
00086         */
00087         virtual Object::Holder get(size32_t i) const;
00088 
00089         /**
00090         * {@inheritDoc}
00091         */
00092         using List::get;
00093 
00094         /**
00095         * {@inheritDoc}
00096         */
00097         virtual size32_t indexOf(Object::View v) const;
00098 
00099         /**
00100         * {@inheritDoc}
00101         */
00102         virtual size32_t lastIndexOf(Object::View v) const;
00103 
00104         /**
00105         * {@inheritDoc}
00106         */
00107         virtual ListIterator::Handle listIterator(size32_t index = 0) const;
00108 
00109         /**
00110         * {@inheritDoc}
00111         */
00112         virtual ListMuterator::Handle listIterator(size32_t index = 0);
00113 
00114         /**
00115         * {@inheritDoc}
00116         */
00117         virtual Object::Holder remove(size32_t index);
00118 
00119         /**
00120         * {@inheritDoc}
00121         */
00122         virtual Object::Holder set(size32_t index, Object::Holder oh);
00123 
00124         /**
00125         * {@inheritDoc}
00126         */
00127         virtual List::View subList(size32_t fromIndex, size32_t toIndex) const;
00128 
00129         /**
00130         * {@inheritDoc}
00131         */
00132         virtual List::Handle subList(size32_t fromIndex, size32_t toIndex);
00133 
00134 
00135     // ----- Collection interface -------------------------------------------
00136 
00137     public:
00138         /**
00139         * {@inheritDoc}
00140         */
00141         virtual size32_t size() const;
00142 
00143         /**
00144         * {@inheritDoc}
00145         */
00146         virtual Iterator::Handle iterator() const;
00147 
00148         /**
00149         * {@inheritDoc}
00150         */
00151         virtual Muterator::Handle iterator();
00152 
00153         /**
00154         * {@inheritDoc}
00155         */
00156         virtual bool add(Object::Holder oh);
00157 
00158         /**
00159         * {@inheritDoc}
00160         */
00161         virtual bool addAll(Collection::View vc);
00162 
00163         /**
00164         * {@inheritDoc}
00165         */
00166         virtual bool remove(Object::View v);
00167 
00168         /**
00169         * {@inheritDoc}
00170         */
00171         virtual bool removeAll(Collection::View vColl);
00172 
00173         /**
00174         * {@inheritDoc}
00175         */
00176         virtual bool retainAll(Collection::View vCol);
00177 
00178         /**
00179         * {@inheritDoc}
00180         */
00181         virtual void clear();
00182 
00183 
00184     // ----- Object interface -----------------------------------------------
00185 
00186     protected:
00187         /**
00188         * {@inheritDoc}
00189         */
00190         virtual void onEscape(bool fEscaped) const;
00191 
00192 
00193     // ----- nested class: ListElement --------------------------------------
00194 
00195     public:
00196         /**
00197         * ListElement is the foundation element for the linked list
00198         */
00199         class ListElement
00200             : public class_spec<ListElement>
00201             {
00202             friend class factory<ListElement>;
00203 
00204             // ----- constructor ----------------------------------------
00205 
00206             protected:
00207                 /**
00208                 * Create a new ListElement object.
00209                 *
00210                 * @param hNext  the element that will be next in the list
00211                 * @param hPrev  the element that will be previous in the
00212                 *               list
00213                 * @param hObj   the object this list element contains
00214                 *
00215                 * @return a newly created ListElement
00216                 */
00217                 ListElement(ListElement::Handle hNext,
00218                         ListElement::Handle hPrev, Object::Holder hObj);
00219 
00220 
00221             // ----- ListElement interface ------------------------------
00222 
00223             public:
00224                 /**
00225                 * Helper method to find a ListElement at the specified
00226                 * position
00227                 *
00228                 * @param thElement  the starting position to find the element
00229                 *                   from
00230                 * @param c          the index of the element to find
00231                 *
00232                 * @return a ListElement at the specified position
00233                 *
00234                 * @throws coherence::lang::IndexOutOfBoundsException if the
00235                 *         index is out of range
00236                 */
00237                 template<class T> static TypedHandle<T>
00238                         nextElement(const TypedHandle<T>& thElement, size32_t c);
00239 
00240             // ----- Object interface -----------------------------------
00241             public:
00242                 /**
00243                 * {@inheritDoc}
00244                 */
00245                 virtual size64_t sizeOf(bool fDeep = false) const;
00246 
00247             // ----- data members ---------------------------------------
00248 
00249             public:
00250                 /**
00251                 * Reference to the next element in the list
00252                 */
00253                 mutable MemberHandle<ListElement> next;
00254 
00255                 /**
00256                 * Reference to the previous element in the list
00257                 */
00258                 MemberHandle<ListElement> previous;
00259 
00260                 /**
00261                 * Reference to the actual object contained by this list
00262                 */
00263                 MemberHolder<Object> value;
00264             };
00265 
00266 
00267     // ----- nested class: SubLinkedList ----------------------------------
00268 
00269     public:
00270         /**
00271         * Utility class to implement a SubList of a LinkedList.
00272         * SubLinkedList delegates through the the LinkedList for all
00273         * modification operations
00274         */
00275         class SubLinkedList
00276             : public class_spec<SubLinkedList,
00277                 extends<SubList> >
00278             {
00279             friend class factory<SubLinkedList>;
00280 
00281             // ----- constructors ---------------------------------------
00282 
00283             protected:
00284                 /**
00285                 * create a new SubLinkedList.
00286                 *
00287                 * @param fromIndex  the starting point of the sublist in the
00288                 *                   list provided (inclusive).
00289                 * @param toIndex    the end point of the sublist in the list
00290                 *                   provided (exclusive)
00291                 * @param ohList     the list to create a sublist of
00292                 *
00293                 * @return a new SubLinkedList
00294                 */
00295                 SubLinkedList(size32_t fromIndex, size32_t toIndex,
00296                         List::Holder ohList);
00297 
00298 
00299             // ----- List interface --------------------------------------
00300 
00301             public:
00302                 /**
00303                 * {@inheritDoc}
00304                 */
00305                 virtual bool retainAll(Collection::View vColl);
00306 
00307                 /**
00308                 * {@inheritDoc}
00309                 */
00310                 virtual void clear();
00311 
00312                 /**
00313                 * {@inheritDoc}
00314                 */
00315                 virtual List::View
00316                         subList(size32_t fromIndex, size32_t toIndex) const;
00317 
00318                 /**
00319                 * {@inheritDoc}
00320                 */
00321                 virtual List::Handle
00322                         subList(size32_t fromIndex, size32_t toIndex);
00323             };
00324 
00325 
00326     // ----- helper methods -------------------------------------------------
00327 
00328     protected:
00329         /**
00330         * Helper method that will throw a
00331         * coherence::lang::IndexOutOfBoundsException if the supplied index
00332         * is out of range
00333         *
00334         * @param i  the index to test
00335         */
00336         virtual void assertIndex(size32_t i) const;
00337 
00338     private:
00339         /**
00340         * Remove a ListElement from the linked list.
00341         *
00342         * @param hElement  the element to remove
00343         */
00344         Object::Holder removeElement(ListElement::Handle hElement,
00345                 size32_t index);
00346 
00347         /**
00348         * Add a ListElement to the linked list.
00349         *
00350         * @param hNext  the element which will follow the new element
00351         * @param oh     the value portion of the new element
00352         */
00353         void addElement(ListElement::Handle hNext, Object::Holder oh);
00354 
00355     // ----- data members ---------------------------------------------------
00356 
00357     protected:
00358         /**
00359         * The number of elements in the list
00360         */
00361         size32_t m_cElements;
00362 
00363         /**
00364         * The head of the list.
00365         */
00366         mutable MemberHandle<ListElement> m_hHead;
00367 
00368         /**
00369         * The tail of the list.
00370         */
00371         mutable MemberHandle<ListElement> m_hTail;
00372 
00373 
00374     // ----- friends --------------------------------------------------------
00375 
00376     friend class SubLinkedList;
00377     friend class LinkedListIterator;
00378     };
00379 
00380 COH_CLOSE_NAMESPACE2
00381 
00382 #endif // COH_LINKED_LIST_HPP
Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.