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

E80355-01

coherence/util/SubSet.hpp

00001 /*
00002 * SubSet.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_SUB_SET_HPP
00017 #define COH_SUB_SET_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/AbstractSet.hpp"
00022 #include "coherence/util/Set.hpp"
00023 
00024 COH_OPEN_NAMESPACE2(coherence,util)
00025 
00026 
00027 /**
00028 * Implements a set which is based on another set, which is assumed to be
00029 * immutable. Unlike DeltaSet, the SubSet is assumed to be a subset of the
00030 * underlying set, and optimizes for both remove and retain operations.
00031 *
00032 * @author tb 2009.02.10
00033 */
00034 class COH_EXPORT SubSet
00035     : public cloneable_spec<SubSet,
00036         extends<AbstractSet> >
00037     {
00038     friend class factory<SubSet>;
00039 
00040     // ----- constructors ---------------------------------------------------
00041 
00042     protected:
00043         /**
00044         * Construct this set based on an existing set.
00045         *
00046         * @param hSet  the set to base this subset on
00047         */
00048         SubSet(Set::Holder hSet);
00049 
00050         /**
00051         * Copy constructor.
00052         */
00053         SubSet(const SubSet& that);
00054 
00055 
00056     // ----- SubSet accessors -----------------------------------------------
00057 
00058     public:
00059         /**
00060         * Determine what items were in the original set.
00061         *
00062         * @return the set used to construct this SubSet
00063         */
00064         virtual Set::View getOriginal() const;
00065 
00066         /**
00067         * Determine if the set has been modified.
00068         *
00069         * @return  true if any items have been removed
00070         */
00071         virtual bool isModified() const;
00072 
00073         /**
00074         * Determine if the SubSet is tracking retained items versus removed
00075         * items.
00076         *
00077         * @return true if the SubSet is tracking just the retained items,
00078         *         false if the SubSet is tracking just the removed items
00079         */
00080         virtual bool isTrackingRetained() const;
00081 
00082         /**
00083         * Determine what items were added to the subset. Do not modify the
00084         * returned set.
00085         *
00086         * @return a set of retained items
00087         */
00088         virtual Set::View getRetained() const;
00089 
00090         /**
00091         * Determine if the SubSet is tracking removed items versus retained
00092         * items.
00093         *
00094         * @return true if the SubSet is tracking just the removed items,
00095         *         false if the SubSet is tracking just the retained items
00096         */
00097         virtual bool isTrackingRemoved() const;
00098 
00099         /**
00100         * Determine what items were removed from the subset.
00101         *
00102         * @return an immutable set of removed items
00103         */
00104         virtual Set::View getRemoved() const;
00105 
00106     protected:
00107         /**
00108          * Instantiate a new modification set containing either removed or
00109          * retained items.
00110          *
00111          * @param cSize  an initial size of the modification set
00112          */
00113         virtual Set::Handle instantiateModificationSet(size32_t cSize) const;
00114 
00115     public:
00116         /**
00117         * Get a mutable set of items that are retained in the subset.
00118         *
00119         * @return a mutable set of retained items
00120         */
00121         virtual Set::Handle ensureRetained();
00122 
00123         /**
00124         * Get a mutable set of items that are removed in the subset.
00125         *
00126         * @return a mutable set of removed items
00127         */
00128         virtual Set::Handle ensureRemoved();
00129 
00130         /**
00131         * Apply the changes to the underlying set ("commit").
00132         */
00133         virtual void resolve();
00134 
00135         /**
00136         * Discard the changes to the set ("rollback").
00137         */
00138         virtual void reset();
00139 
00140 
00141     // ----- Collection interface -------------------------------------------
00142 
00143     public:
00144         /**
00145         * {@inheritDoc}
00146         */
00147         virtual size32_t size() const;
00148 
00149         /**
00150         * {@inheritDoc}
00151         */
00152         virtual bool isEmpty() const;
00153 
00154         /**
00155         * {@inheritDoc}
00156         */
00157         virtual bool contains(Object::View v) const;
00158 
00159         /**
00160         * {@inheritDoc}
00161         */
00162         virtual bool containsAll(Collection::View vCol) const;
00163 
00164         /**
00165         * {@inheritDoc}
00166         */
00167         virtual Iterator::Handle iterator() const;
00168 
00169         /**
00170         * {@inheritDoc}
00171         */
00172         virtual Muterator::Handle iterator();
00173 
00174         /**
00175         * {@inheritDoc}
00176         */
00177         virtual ObjectArray::Handle toArray(
00178                 ObjectArray::Handle hao = NULL) const;
00179 
00180         /**
00181         * {@inheritDoc}
00182         */
00183         virtual bool add(Object::Holder oh);
00184 
00185         /**
00186         * {@inheritDoc}
00187         */
00188         virtual bool addAll(Collection::View vCol);
00189 
00190         /**
00191         * {@inheritDoc}
00192         */
00193         virtual bool remove(Object::View v);
00194 
00195         /**
00196         * {@inheritDoc}
00197         */
00198         virtual bool removeAll(Collection::View vCol);
00199 
00200         /**
00201         * {@inheritDoc}
00202         */
00203         virtual bool retainAll(Collection::View vCol);
00204 
00205         /**
00206         * {@inheritDoc}
00207         */
00208         virtual void clear();
00209 
00210 
00211     // ----- helpers --------------------------------------------------------
00212 
00213     protected:
00214         /**
00215          * Instantiate a new retained set with all elements in the specified
00216          * collection that also exist in the specified set and are not excluded.
00217          *
00218          * @param vColOuter    collection to iterate
00219          * @param vSetMatch    set to test the presence for each iterated element
00220          * @param vSetExclude  optional set of excluded elements
00221          */
00222      void retainAllInternal(Collection::View vColOuter, 
00223              Set::View vSetMatch, Set::View vSetExclude);
00224 
00225 
00226     // ----- data members ---------------------------------------------------
00227 
00228     protected:
00229         /**
00230         * The underlying set (assumed immutable).
00231         */
00232         FinalHolder<Set> f_ohSetOrig;
00233 
00234         /**
00235         * The removed or retained items.
00236         */
00237         MemberHandle<Set> m_hSetMod;
00238 
00239         /**
00240         * Toggles between whether the modifications are removed or retained.
00241         */
00242         bool m_fRetained;
00243     };
00244 
00245 COH_CLOSE_NAMESPACE2
00246 
00247 #endif // COH_SUB_SET_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.