#include <SequenceableCollection.h>
Inheritance diagram for Core::SequenceableCollection:


Public Member Functions | |
| virtual Object * | any (void) |
| Answer any item from the collection. | |
| virtual Object * | at (int index) const abstract |
| virtual void | put (int index, Object *obj) abstract |
| virtual long | size (void) const abstract |
| Answer how many elements the collection includes. | |
| virtual Object * | first (void) |
| virtual Object * | last (void) |
| virtual void | replace (long start, long stop, const SequenceableCollection *collection) |
| virtual void | replace (long start, long stop, const SequenceableCollection *collection, long startIndex) |
| virtual void | replaceAll (Object *element, Object *replacement) |
| virtual void | replaceAll (Object *element, Object *replacement, long startIndex, long stopIndex) |
| virtual long | indexOf (Object *element) const |
| Finds first index of element in a collection. | |
| virtual long | lastIndexOf (Object *element) const |
| Finds last index of element in a collection. | |
| virtual long | nextIndexOf (Object *element, long startIndex, long stopIndex) const |
| virtual long | prevIndexOf (Object *element, long startIndex, long stopIndex) const |
| virtual long | indexOfSubCollection (SequenceableCollection *coll) const |
| virtual long | indexOfSubCollection (SequenceableCollection *coll, long startIndex) const |
| virtual void | changeSize (long newSize) abstract |
| virtual void | grow (void) |
| virtual void | growToAtLeast (long items) |
| virtual Array * | asArray (void) |
| virtual ByteArray * | asByteArray (void) |
| virtual String * | asString (void) |
| virtual ReadStream * | readStream (void) |
| virtual ReadAppendStream * | readAppendStream (void) |
| virtual WriteStream * | writeStream (void) |
| virtual Object * | copy (void) abstract |
| virtual Object * | copy (long from, long to) |
| Returns a new collection with the same items as the specified portion of this collection. | |
| virtual SequenceableCollection * | copyReplace (long from, long to, SequenceableCollection *replacement) |
| virtual SequenceableCollection & | operator+ (SequenceableCollection &collection) |
| virtual Object * | remove (Object *) |
| virtual bool | includesSubcollection (SequenceableCollection *coll) const |
| virtual bool | isSequenceable (void) const |
| virtual bool | startsWith (SequenceableCollection *coll) const |
| virtual bool | endsWith (SequenceableCollection *coll) const |
Protected Member Functions | |
| virtual Object * | privNextForIterator (CollectionIterator *iter) const |
|
|
Answer any item from the collection.
Reimplemented from Core::Collection. Reimplemented in Core::Array. Definition at line 35 of file SequenceableCollection.cc. References first(). 00036 {
00037 return first();
00038 }
|
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Array. Definition at line 172 of file SequenceableCollection.cc. References at(), Core::Array::put(), and size(). Referenced by Core::String::asArrayOfSubstringsSeparatedBy(). 00173 {
00174 Array *newArray = new Array(size());
00175 for (long i = 0; i < size(); i++) {
00176 newArray->put(i, at(i));
00177 }
00178 return newArray;
00179 }
|
|
|
Reimplemented in Core::ByteArray. Definition at line 181 of file SequenceableCollection.cc. References nil, and Core::Object::shouldNotImplement(). 00182 {
00183 shouldNotImplement(new String(__PRETTY_FUNCTION__));
00184 return nil;
00185 }
|
|
|
Reimplemented in Core::ByteArray, and Core::String. Definition at line 187 of file SequenceableCollection.cc. References nil, and Core::Object::shouldNotImplement(). 00188 {
00189 shouldNotImplement(new String(__PRETTY_FUNCTION__));
00190 return nil;
00191 }
|
|
|
|
Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String. Referenced by grow(), and growToAtLeast(). |
|
||||||||||||
|
Returns a new collection with the same items as the specified portion of this collection.
Reimplemented in Core::Array, Core::ByteArray, and Core::String. Definition at line 213 of file SequenceableCollection.cc. References Core::Collection::copyEmpty(), and replace(). 00214 {
00215 SequenceableCollection *newColl;
00216 int newSize = to - from;
00217
00218 newColl = (SequenceableCollection *) copyEmpty(newSize);
00219 newColl->replace(0, newSize, this, from);
00220 return newColl;
00221 }
|
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String. Referenced by Core::WriteStream::contents(), Core::PositionableStream::contents(), Core::InternalStream::contents(), Core::String::copy(), Core::OrderedCollection::copy(), Core::ByteArray::copy(), Core::Array::copy(), and Core::InternalStream::upToEnd(). |
|
||||||||||||||||
|
Definition at line 223 of file SequenceableCollection.cc. References Core::Collection::copyEmpty(), replace(), and size(). Referenced by Core::String::concatenateWith(), Core::String::operator+(), operator+(), and Tools::HierarchicalConfigurationReader::readLine(). 00225 {
00226 SequenceableCollection *newCollection;
00227 long newSize;
00228 long endReplacement;
00229
00230 newSize = size() - (to - from) + replacement->size();
00231 endReplacement = from + replacement->size();
00232 newCollection = (SequenceableCollection *) copyEmpty(newSize);
00233 newCollection->replace(0, from, this, 0);
00234 newCollection->replace(from, endReplacement, replacement, 0);
00235 newCollection->replace(endReplacement, newSize, this, to);
00236 return newCollection;
00237 }
|
|
|
Reimplemented in Core::String. Definition at line 267 of file SequenceableCollection.cc. References indexOfSubCollection(), Core::Collection::isEmpty(), and size(). Referenced by Core::String::endsWith(). 00268 {
00269 int start = size() - coll->size();
00270 if (start < 0) return false;
00271 return indexOfSubCollection(coll, start) >= 0 || coll->isEmpty();
00272 }
|
|
|
Reimplemented in Core::OrderedCollection. Definition at line 40 of file SequenceableCollection.cc. References at(), and Core::Collection::emptyCheck(). Referenced by any(), Tools::Filename::constructString(), Tools::Filename::isAbsolute(), Core::Object::printOn(), and Tools::HierarchicalConfigurationReader::readLine(). 00041 {
00042 emptyCheck();
00043 return at(0);
00044 }
|
|
|
Reimplemented in Core::OrderedCollection. Definition at line 160 of file SequenceableCollection.cc. References changeSize(), Core::Collection::growSize(), and size(). 00161 {
00162 changeSize(size() + growSize());
00163 }
|
|
|
Definition at line 165 of file SequenceableCollection.cc. References changeSize(), Core::Collection::growSize(), and size(). Referenced by Core::InternalStream::nextPutAll(), and Core::InternalStream::pastEndPut(). 00166 {
00167 if (items < size()) return;
00168 changeSize(items + growSize());
00169 }
|
|
|
Reimplemented in Core::String. Definition at line 252 of file SequenceableCollection.cc. References indexOfSubCollection(), and Core::Collection::isEmpty(). Referenced by Core::String::includesSubcollection(). 00253 {
00254 return indexOfSubCollection(coll) >= 0 || coll->isEmpty();
00255 }
|
|
|
Finds first index of element in a collection. If none found returns -1. Reimplemented in Core::String. Definition at line 91 of file SequenceableCollection.cc. References nextIndexOf(), and size(). Referenced by Core::String::indexOf(). 00092 {
00093 long index;
00094
00095 index = nextIndexOf(element, 0, size());
00096 if (index < 0 || index >= size()) index = -1;
00097 return index;
00098 }
|
|
||||||||||||
|
Definition at line 134 of file SequenceableCollection.cc. References at(), nextIndexOf(), and size(). 00136 {
00137 long subSize = coll->size();
00138 Object *firstElement;
00139 long len, matchIndex;
00140
00141 if (subSize == 0) return -1;
00142 if (subSize + startIndex > size()) return -1;
00143 firstElement = coll->at(0);
00144 len = size() - subSize + 1;
00145 matchIndex = nextIndexOf(firstElement, startIndex, len);
00146 if (subSize == 1)
00147 return (matchIndex >= 0 && matchIndex < len) ? matchIndex : -1;
00148 while (matchIndex < len) {
00149 long index = 1;
00150 while (this->at(matchIndex + index)->isEqual(coll->at(index))) {
00151 index++;
00152 if (index == subSize) return matchIndex;
00153 }
00154 matchIndex = nextIndexOf(firstElement, matchIndex + 1, len);
00155 }
00156 return -1;
00157 }
|
|
|
Definition at line 129 of file SequenceableCollection.cc. Referenced by endsWith(), includesSubcollection(), and startsWith(). 00130 {
00131 return indexOfSubCollection(coll, 0);
00132 }
|
|
|
Reimplemented from Core::Collection. Definition at line 257 of file SequenceableCollection.cc. 00258 {
00259 return true;
00260 }
|
|
|
Reimplemented in Core::OrderedCollection. Definition at line 46 of file SequenceableCollection.cc. References at(), Core::Collection::emptyCheck(), and size(). Referenced by Tools::HierarchicalConfigurationReader::readLine(). 00047 {
00048 emptyCheck();
00049 return at(size()-1);
00050 }
|
|
|
Finds last index of element in a collection. If none found returns -1. Reimplemented in Core::String. Definition at line 100 of file SequenceableCollection.cc. References prevIndexOf(), and size(). Referenced by Core::String::lastIndexOf(). 00101 {
00102 long index;
00103
00104 index = prevIndexOf(element, size(), 0);
00105 if (index < 0 || index >= size()) index = -1;
00106 return index;
00107 }
|
|
||||||||||||||||
|
Reimplemented in Core::String. Definition at line 109 of file SequenceableCollection.cc. References at(), and Core::Object::isEqual(). Referenced by indexOf(), indexOfSubCollection(), Core::String::nextIndexOf(), and replaceAll(). 00111 {
00112 for (long index = startIndex; index < stopIndex; index++) {
00113 if (at(index)->isEqual(element))
00114 return index;
00115 }
00116 return stopIndex;
00117 }
|
|
|
Reimplemented in Core::String. Definition at line 239 of file SequenceableCollection.cc. References copyReplace(), and size(). 00240 {
00241 return *copyReplace(size(), size(), &collection);
00242 }
|
|
||||||||||||||||
|
Reimplemented in Core::String. Definition at line 119 of file SequenceableCollection.cc. References at(), and Core::Object::isEqual(). Referenced by lastIndexOf(), and Core::String::prevIndexOf(). 00121 {
00122 for (long index = startIndex - 1; index >= stopIndex; index--) {
00123 if (at(index)->isEqual(element))
00124 return index;
00125 }
00126 return stopIndex - 1;
00127 }
|
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Array, and Core::OrderedCollection. Definition at line 275 of file SequenceableCollection.cc. References at(), nil, Core::CollectionIterator::position(), and size(). 00276 {
00277 long index = iter->position();
00278 for (; index < size(); index += 1) {
00279 Object *item = at(index);
00280 if (item != nil) {
00281 iter->position(index);
00282 return item;
00283 }
00284 }
00285 iter->position(index);
00286 return nil;
00287 }
|
|
||||||||||||
|
Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String. Referenced by Core::Stream::next(), Core::PositionableStream::next(), Core::WriteStream::nextPut(), Core::ExternalWriteStream::nextPut(), Core::InternalStream::pastEndPut(), replace(), and replaceAll(). |
|
|
Definition at line 198 of file SequenceableCollection.cc. 00199 {
00200 return new ReadAppendStream(this);
00201 }
|
|
|
Definition at line 193 of file SequenceableCollection.cc. Referenced by Tools::Filename::components(), Tools::ConfigurationReader::onString(), and Core::InternalEncodedStreamFactory::readStream(). 00194 {
00195 return new ReadStream(this);
00196 }
|
|
|
Reimplemented from Core::Collection. Reimplemented in Core::OrderedCollection. Definition at line 245 of file SequenceableCollection.cc. References nil, and Core::Object::shouldNotImplement(). 00246 {
00247 shouldNotImplement(new String(__PRETTY_FUNCTION__));
00248 return nil;
00249 }
|
|
||||||||||||||||||||
|
Reimplemented in Core::ByteArray. Definition at line 61 of file SequenceableCollection.cc. 00064 {
00065 long repOff = repStart - start;
00066 if (this == replacement && repStart < start) {
00067 /* Replacement would be overwritten, copy in reverse order. */
00068 for (long i = stop - 1; i >= start; i--)
00069 put(i, replacement->at(repOff + i));
00070 } else {
00071 for (long i = start; i < stop; i++)
00072 put(i, replacement->at(repOff + i));
00073 }
00074 }
|
|
||||||||||||||||
|
Reimplemented in Core::ByteArray. Definition at line 52 of file SequenceableCollection.cc. References Core::Object::error(), and size(). Referenced by Core::OrderedCollection::changeSize(), copy(), copyReplace(), Core::PositionableStream::next(), Core::InternalStream::nextPutAll(), and Core::ByteArray::replace(). 00054 {
00055 if (collection->size() != stop - start)
00056 error(new String("Size of replacement doesn\'t match."),
00057 new String(__PRETTY_FUNCTION__));
00058 replace(start, stop, collection, 0);
00059 }
|
|
||||||||||||||||||||
|
Definition at line 81 of file SequenceableCollection.cc. References nextIndexOf(), and put(). 00083 {
00084 long index = startIndex - 1;
00085
00086 while ((index = nextIndexOf(element, index+1, stopIndex)) < stopIndex) {
00087 put(index, replacement);
00088 }
00089 }
|
|
||||||||||||
|
Definition at line 76 of file SequenceableCollection.cc. References size(). Referenced by Tools::HierarchicalConfigurationReader::parseLine(), and Tools::ConfigurationReader::readLine(). 00077 {
00078 replaceAll(element, replacement, 0, size());
00079 }
|
|
|
Answer how many elements the collection includes.
Reimplemented from Core::Collection. Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String. Referenced by asArray(), copyReplace(), endsWith(), Core::ExternalWriteStream::flush(), grow(), growToAtLeast(), indexOf(), indexOfSubCollection(), Core::PositionableStream::initialize(), last(), lastIndexOf(), Core::Stream::nextPutAll(), Core::InternalStream::nextPutAll(), operator+(), Core::InternalStream::pastEndPut(), OS::Process::privateExecuteJob(), privNextForIterator(), replace(), replaceAll(), and Core::SearchTreeNode::valueAt(). |
|
|
Reimplemented in Core::String. Definition at line 262 of file SequenceableCollection.cc. References indexOfSubCollection(), and Core::Collection::isEmpty(). Referenced by Core::String::startsWith(). 00263 {
00264 return indexOfSubCollection(coll) == 0 || coll->isEmpty();
00265 }
|
|
|
Definition at line 203 of file SequenceableCollection.cc. Referenced by Core::InternalEncodedStreamFactory::writeStream(). 00204 {
00205 return new WriteStream(this);
00206 }
|
1.4.2