00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_ABSTRACT_COLLECTION_HPP 00008 #define COH_ABSTRACT_COLLECTION_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/util/Collection.hpp" 00013 #include "coherence/util/Iterator.hpp" 00014 00015 00016 00017 COH_OPEN_NAMESPACE2(coherence,util) 00018 00019 00020 /** 00021 * This class provides a skeletal implementation of the <tt>Collection</tt> 00022 * interface, to minimize the effort required to implement this interface. 00023 * 00024 * To implement an unmodifiable collection, the programmer needs only to 00025 * extend this class and provide implementations for the <tt>size</tt> and 00026 * <tt>iterator</tt> methods. 00027 * 00028 * To implement a modifiable collection, the programmer must additionally 00029 * override this class's <tt>add</tt>, <tt>remove</tt>, <tt>removeAll</tt>, 00030 * <tt>retainAll</tt> and <tt>clear</tt> methods 00031 * (which otherwise throw an <tt>UnsupportedOperationException</tt>). 00032 * 00033 * The programmer should generally provide a void (no argument) and 00034 * <tt>Collection</tt> constructor, as per the recommendation in the 00035 * <tt>Collection</tt> interface specification. 00036 * 00037 * @see Collection 00038 */ 00039 class COH_EXPORT AbstractCollection 00040 : public abstract_spec<AbstractCollection, 00041 extends<Object>, 00042 implements<Collection> > 00043 { 00044 // ----- Collection interface -------------------------------------------- 00045 00046 public: 00047 // Query Operations 00048 00049 /** 00050 * {@inheritDoc} 00051 */ 00052 virtual size32_t size() const = 0; 00053 00054 /** 00055 * {@inheritDoc} 00056 */ 00057 virtual bool isEmpty() const; 00058 00059 /** 00060 * {@inheritDoc} 00061 */ 00062 virtual bool contains(Object::View v) const; 00063 00064 /** 00065 * {@inheritDoc} 00066 */ 00067 virtual ObjectArray::Handle toArray( 00068 ObjectArray::Handle hao = NULL) const; 00069 00070 /** 00071 * {@inheritDoc} 00072 * 00073 * This implementation iterates over the specified collection, 00074 * checking each element returned by the iterator in turn to see if 00075 * it's contained in this collection. If all elements are so 00076 * contained <tt>true</tt> is returned, otherwise <tt>false</tt>. 00077 */ 00078 virtual bool containsAll(Collection::View vc) const; 00079 00080 /** 00081 * {@inheritDoc} 00082 * 00083 * This implementation will throw a 00084 * coherence::lang::UnsupportedOperationException 00085 */ 00086 virtual bool add(Object::Holder oh); 00087 00088 /** 00089 * {@inheritDoc} 00090 * 00091 * This implementation will throw a 00092 * coherence::lang::UnsupportedOperationException unless #add() is 00093 * overridden (assuming the specified collection is non-empty). 00094 */ 00095 virtual bool addAll(Collection::View vc); 00096 00097 /** 00098 * {@inheritDoc} 00099 * 00100 * This implementation will throw a 00101 * coherence::lang::UnsupportedOperationException unless #add() is 00102 * overridden (assuming the specified collection is non-empty). 00103 */ 00104 virtual bool remove(Object::View v); 00105 00106 /** 00107 * {@inheritDoc} 00108 * 00109 * This implementation will throw a 00110 * coherence::lang::UnsupportedOperationException} unless #remove() is 00111 * overridden (assuming the specified collection is non-empty). 00112 */ 00113 virtual bool removeAll(Collection::View vc); 00114 00115 /** 00116 * {@inheritDoc} 00117 * 00118 * This implementation will throw a 00119 * coherence::lang::UnsupportedOperationException unless #remove() is 00120 * overridden (assuming there are items to be removed by the 00121 * operation). 00122 */ 00123 virtual bool retainAll(Collection::View vc); 00124 00125 /** 00126 * {@inheritDoc} 00127 * 00128 * This implementation will throw a 00129 * coherence::lang::UnsupportedOperationException. 00130 */ 00131 virtual void clear(); 00132 00133 00134 // ----- Object interface ----------------------------------------------- 00135 00136 public: 00137 /** 00138 * {@inheritDoc} 00139 */ 00140 virtual TypedHandle<const String> toString() const; 00141 }; 00142 00143 COH_CLOSE_NAMESPACE2 00144 00145 #endif // COH_ABSTRACT_COLLECTION_HPP