Collection.h

Go to the documentation of this file.
00001 #ifndef JAVA_UTIL_COLLECTION_H
00002 #define JAVA_UTIL_COLLECTION_H 1
00003 
00004 #ifndef JAVA_LANG_SYNC_H
00005 #include <java_lang/Sync.h>
00006 #endif /* JAVA_LANG_SYNC_H */
00007 #ifndef JAVA_UTIL_ITERATOR_H
00008 #include <java_util/Iterator.h>
00009 #endif /* JAVA_UTIL_ITERATOR_H */
00010 
00011 namespace java {
00012   namespace util {
00013 
00080     class JAVA_UTIL_SPEC Collection : virtual public Interface {
00081 
00082     public:
00083 
00087       static Ref<Collection> emptyCollection();
00088 
00095       static Ref<Collection> singletonCollection(const ObjectRef& o);
00096 
00128       static Ref<Collection> synchronizedCollection(const Ref<Collection>& c, const Ref<Sync>& sync = 0);
00129 
00151       static Ref<Collection> immutableCollection(const Ref<Collection>& c);
00152 
00160       virtual jint size() const = 0;
00161 
00167       virtual jboolean isEmpty() const = 0;
00168 
00183       virtual jboolean contains(const ObjectRef& o) const = 0;
00184 
00193       virtual Ref<Iterator> iterator() const = 0;
00194 
00211       virtual Array<ObjectRef> toArray() const = 0;
00212 
00245       virtual jboolean add(const ObjectRef& o) = 0;
00246 
00267       virtual jboolean remove(const ObjectRef& o) = 0;
00268 
00286       virtual jboolean containsAll(const Collection& c) const = 0;
00287 
00312       virtual jboolean addAll(const Collection& c) = 0;
00313 
00338       virtual jboolean removeAll(const Collection& c) = 0;
00339 
00363       virtual jboolean retainAll(const Collection& c) = 0;
00364 
00373       virtual void clear() = 0;
00374 
00375       /*
00376        * Compares the specified object with this collection for equality. <p>
00377        *
00378        * While the <tt>Collection</tt> interface adds no stipulations to the
00379        * general contract for the <tt>Object.equals</tt>, programmers who
00380        * implement the <tt>Collection</tt> interface "directly" (in other words,
00381        * create a class that is a <tt>Collection</tt> but is not a <tt>Set</tt>
00382        * or a <tt>List</tt>) must exercise care if they choose to override the
00383        * <tt>Object.equals</tt>.  It is not necessary to do so, and the simplest
00384        * course of action is to rely on <tt>Object</tt>'s implementation, but
00385        * the implementer may wish to implement a "value comparison" in place of
00386        * the default "reference comparison."  (The <tt>List</tt> and
00387        * <tt>Set</tt> interfaces mandate such value comparisons.)<p>
00388        *
00389        * The general contract for the <tt>Object.equals</tt> method states that
00390        * equals must be symmetric (in other words, <tt>a.equals(b)</tt> if and
00391        * only if <tt>b.equals(a)</tt>).  The contracts for <tt>List.equals</tt>
00392        * and <tt>Set.equals</tt> state that lists are only equal to other lists,
00393        * and sets to other sets.  Thus, a custom <tt>equals</tt> method for a
00394        * collection class that implements neither the <tt>List</tt> nor
00395        * <tt>Set</tt> interface must return <tt>false</tt> when this collection
00396        * is compared to any list or set.  (By the same logic, it is not possible
00397        * to write a class that correctly implements both the <tt>Set</tt> and
00398        * <tt>List</tt> interfaces.)
00399        *
00400        * @param o Object to be compared for equality with this collection.
00401        * @return <tt>true</tt> if the specified object is equal to this
00402        * collection
00403        * 
00404        */
00405       //virtual jboolean equals(const Object& o) const = 0;
00406 
00407       /*
00408        * Returns the hash code value for this collection.  While the
00409        * <tt>Collection</tt> interface adds no stipulations to the general
00410        * contract for the <tt>Object.hashCode</tt> method, programmers should
00411        * take note that any class that overrides the <tt>Object.equals</tt>
00412        * method must also override the <tt>Object.hashCode</tt> method in order
00413        * to satisfy the general contract for the <tt>Object.hashCode</tt>method.
00414        * In particular, <tt>c1.equals(c2)</tt> implies that
00415        * <tt>c1.hashCode()==c2.hashCode()</tt>.
00416        *
00417        * @return the hash code value for this collection
00418        */
00419       //virtual jint hashCode() const = 0;
00420 
00421     private:
00422 
00423       REGISTER_MEMBERS;
00424 
00425     };
00426 
00427   } // namespace util
00428 } // namespace java
00429 
00430 #endif /* JAVA_UTIL_COLLECTION_H */

Generated on Fri May 16 11:54:42 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3