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

E47891-01

coherence/util/SubSet.hpp

00001 /*
00002 * SubSet.hpp
00003 *
00004 * Copyright (c) 2000, 2014, 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     // ----- constructor ----------------------------------------------------
00041 
00042     public:
00043         /**
00044         * @internal
00045         */
00046         SubSet(Set::Holder hSet);
00047 
00048         /**
00049         * Copy constructor.
00050         */
00051         SubSet(const SubSet& that);
00052 
00053 
00054     // ----- SubSet accessors -----------------------------------------------
00055     public:
00056 
00057         /**
00058         * Determine what items were in the original set.
00059         *
00060         * @return the set used to construct this SubSet
00061         */
00062         virtual Set::View getOriginal() const;
00063 
00064         /**
00065         * Determine if the set has been modified.
00066         *
00067         * @return  true if any items have been removed
00068         */
00069         virtual bool isModified() const;
00070 
00071         /**
00072         * Determine if the SubSet is tracking retained items versus removed
00073         * items.
00074         *
00075         * @return true if the SubSet is tracking just the retained items,
00076         *         false if the SubSet is tracking just the removed items
00077         */
00078         virtual bool isTrackingRetained() const;
00079 
00080         /**
00081         * Determine what items were added to the subset. Do not modify the
00082         * returned set.
00083         *
00084         * @return a set of retained items
00085         */
00086         virtual Set::View getRetained() const;
00087 
00088         /**
00089         * Determine if the SubSet is tracking removed items versus retained
00090         * items.
00091         *
00092         * @return true if the SubSet is tracking just the removed items,
00093         *         false if the SubSet is tracking just the retained items
00094         */
00095         virtual bool isTrackingRemoved() const;
00096 
00097         /**
00098         * Determine what items were removed from the subset.
00099         *
00100         * @return an immutable set of removed items
00101         */
00102         virtual Set::View getRemoved() const;
00103 
00104         /**
00105         * Get a mutable set of items that are retained in the subset.
00106         *
00107         * @return a mutable set of retained items
00108         */
00109         virtual Set::Handle ensureRetained();
00110 
00111         /**
00112         * Get a mutable set of items that are removed in the subset.
00113         *
00114         * @return a mutable set of removed items
00115         */
00116         virtual Set::Handle ensureRemoved();
00117 
00118         /**
00119         * Apply the changes to the underlying set ("commit").
00120         */
00121         virtual void resolve();
00122 
00123         /**
00124         * Discard the changes to the set ("rollback").
00125         */
00126         virtual void reset();
00127 
00128 
00129     // ----- Collection interface -------------------------------------------
00130 
00131     public:
00132         /**
00133         * {@inheritDoc}
00134         */
00135         virtual size32_t size() const;
00136 
00137         /**
00138         * {@inheritDoc}
00139         */
00140         virtual bool isEmpty() const;
00141 
00142         /**
00143         * {@inheritDoc}
00144         */
00145         virtual bool contains(Object::View v) const;
00146 
00147         /**
00148         * {@inheritDoc}
00149         */
00150         virtual bool containsAll(Collection::View vCol) const;
00151 
00152         /**
00153         * {@inheritDoc}
00154         */
00155         virtual Iterator::Handle iterator() const;
00156 
00157         /**
00158         * {@inheritDoc}
00159         */
00160         virtual Muterator::Handle iterator();
00161 
00162         /**
00163         * {@inheritDoc}
00164         */
00165         virtual ObjectArray::Handle toArray(
00166                 ObjectArray::Handle hao = NULL) const;
00167 
00168         /**
00169         * {@inheritDoc}
00170         */
00171         virtual bool add(Object::Holder oh);
00172 
00173         /**
00174         * {@inheritDoc}
00175         */
00176         virtual bool addAll(Collection::View vCol);
00177 
00178         /**
00179         * {@inheritDoc}
00180         */
00181         virtual bool remove(Object::View v);
00182 
00183         /**
00184         * {@inheritDoc}
00185         */
00186         virtual bool removeAll(Collection::View vCol);
00187 
00188         /**
00189         * {@inheritDoc}
00190         */
00191         virtual bool retainAll(Collection::View vCol);
00192 
00193         /**
00194         * {@inheritDoc}
00195         */
00196         virtual void clear();
00197 
00198 
00199     // ----- data members ---------------------------------------------------
00200 
00201     protected:
00202         /**
00203         * The underlying set (assumed immutable).
00204         */
00205         FinalHolder<Set> f_ohSetOrig;
00206 
00207         /**
00208         * The removed or retained items.
00209         */
00210         MemberHandle<Set> m_hSetMod;
00211 
00212         /**
00213         * Toggles between whether the modifications are removed or retained.
00214         */
00215         bool m_fRetained;
00216     };
00217 
00218 COH_CLOSE_NAMESPACE2
00219 
00220 #endif // COH_SUB_SET_HPP
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.