home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
-
-
- template < class Element >
- Boolean IAEqualitySequence < Element >::
- operator == (IAEqualitySequence < Element > const& collection) const
- { return this->containsAllFrom (collection) &&
- collection.containsAllFrom (*this);
- }
-
- template < class Element >
- Boolean IAEqualitySequence < Element >::
- operator != (IAEqualitySequence < Element > const& collection) const
- { return ! operator == (collection);
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- unionWith (IAEqualitySequence < Element > const& collection)
- { addAllFrom (collection);
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- intersectionWith (IAEqualitySequence < Element > const& collection)
- { IAEqualityCollection < Element > const* env = &collection;
- removeAll (IAEqualityCollection < Element >::isNotContained, &env);
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- differenceWith (IAEqualitySequence < Element > const& collection)
- { IAEqualityCollection < Element > const* env = &collection;
- removeAll (IAEqualityCollection < Element >::isContained, &env);
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- addUnion (IAEqualitySequence < Element > const& collection1,
- IAEqualitySequence < Element > const& collection2)
- { addAllFrom (collection1);
- addAllFrom (collection2);
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- addIntersection (IAEqualitySequence < Element > const& collection1,
- IAEqualitySequence < Element > const& collection2)
- { ICursor *cursor = collection1.newCursor ();
- forCursor (*cursor) {
- if (collection2.contains (collection1.elementAt (*cursor)))
- add (collection1.elementAt (*cursor));
- }
- delete cursor;
- }
-
- template < class Element >
- void IAEqualitySequence < Element >::
- addDifference (IAEqualitySequence < Element > const& collection1,
- IAEqualitySequence < Element > const& collection2)
- { ICursor *cursor = collection1.newCursor ();
- forCursor (*cursor) {
- if (! collection2.contains (collection1.elementAt (*cursor)))
- add (collection1.elementAt (*cursor));
- }
- delete cursor;
- }
-
- template < class Element >
- long IAEqualitySequence < Element >::
- compare (IAEqualitySequence < Element > const& collection,
- long (*comparisonFunction) (Element const&, Element const&)) const
- { long result = 0;
- ICursor *thisCursor = newCursor ();
- ICursor *collectionCursor = collection.newCursor ();
-
- for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
- result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
- thisCursor->setToNext (), collectionCursor->setToNext ()) {
- result = (*comparisonFunction) (this->elementAt (*thisCursor),
- collection.elementAt (*collectionCursor));
- }
-
- if (result == 0) {
- if (thisCursor->isValid () && ! collectionCursor->isValid ())
- result = 1;
- else if (! thisCursor->isValid () && collectionCursor->isValid ())
- result = -1;
- else {
- }
- }
- delete thisCursor;
- delete collectionCursor;
-
- return result;
- }
-