Common collection protocols
These same protocols are supported by many different types of collections.
The following table describes protocols supported by CLDT collection classes.
Accessing
after:, at:, basicAt:, before:, findFirst:, findLast:, first, first:, fourth, indexOf:, indexOf:ifAbsent:, indexOfAny:, indexOfAny:ifAbsent:, indexOfAny:startingAt:, indexOfAny:startingAt:ifAbsent:, indexOfSubCollection:, indexOfSubCollection:ifAbsent:, indexOfSubCollection:startingAt:, indexOfSubCollection:startingAt:ifAbsent:, last , last:, second:, third:
Porting tip:
Smalltalk/V does not support indexOfSubCollection:startingAt: or indexOfSubCollection:startingAt:ifAbsent:.
Adding
add:, addAll:
Byte accessing
byteAt:, byteAt:put:
Porting tip:
Smalltalk/V does not support byteAt: and byteAt:put:.
Converting
asArray, asBag, asByteArray, asOrderedCollection, asSet, asSortedCollection, asSortedCollection:
Copying
copyFrom:to:, copyReplaceAll:with:, copyReplaceFrom:to:with:, copyReplaceFrom:to:withObject:, copyReplacing:withObject:, copyWith:, copyWithout:, reverse
Note:
copyReplaceFrom:to:withObject: and copyReplacing:withObject: are not in the Blue Book, but we have found them to be useful.
Porting tip:
Smalltalk/V does not support copyReplaceAll:with:, copyReplaceFrom:to:withObject: and copyReplacing:withObject:.
Objectworks/Smalltalk does not support copyReplaceFrom:to:withObject: and copyReplacing:withObject:.
Smalltalk/V uses reversed instead of reverse. Smalltalk/V uses different semantics for copyWithout:. In Smalltalk/V, only the first element equal to the argument is omitted from the copy, while in VA Smalltalk and Objectworks\Smalltalk, all elements equal to the argument are left out.
Creating instances (class methods)
new, new:, with:, with:with:, with:with:with:, with:with:with:with: with:with:with:with:with: with:with:with:with:with:with:
Creating dictionaries (class methods)
new, new:
Dictionary accessing
add:, addAll:, associationAt:, associationAt:ifAbsent:, at:, at:ifAbsent:, at:ifAbsentPut:, at:ifPresent:, at:put:, includesKey:, keyAtValue:, keyAtValue:ifAbsent:, keys, removeAllKeys:, removeAllKeys:ifAbsent:, removeKey:, removeKey:ifAbsent:, values
Note:
Several messages in this protocol have the same names as messages in other protocols but have different semantics: add:, addAll:, at:, and at:put:. The use of these names is well established in the Smalltalk community and has not been changed in CLDT. The messages at:ifAbsentPut:, at:ifPresent:, removeAllKeys:, and removeAllKeys:ifAbsent: are not in the Blue Book, but have been included in CLDT because their use results in more compact and readable code.
Porting tip:
The messages at:ifAbsentPut:, at:ifPresent:, removeAllKeys:, and removeAllKeys:ifAbsent: are not supported in Smalltalk/V or Objectworks\Smalltalk.
Dictionary enumerating
associationsDo:, keysAndValuesDo:, keysDo:
Enumerating
allSatisfy:, anySatisfy:, collect:, conform:, count:, detect:, detect:ifNone:, difference:, do:, do:separatedBy:, inject:into:, intersection:, noneSatisfy:, reject:, select:, union:
Note:
The conform: message checks if each element of a collection satisfies a condition, expressed as a one-argument block. Even though conform: is not defined in the Blue Book, it has been included because it seems to be a natural complement to the other Blue Book enumeration methods.
Although noneSatisfy: is not part of the ANSI Smalltalk specification, it is supported on all platforms and seems to be a natural complement to allSatisfy: and anySatisfy:.
The count: message is not part of the ANSI Smalltalk specification, but it is widely supported and efficient (compared to alternatives).
Porting tip:
The conform: message is not supported in Smalltalk/V or Objectworks\Smalltalk.
The ANSI allSatisfy: message should be used in preference to the CLDT conform: message to aid portability.
Ordered enumerating
doWithIndex:, from:to:do:, from:to:doWithIndex:, from:to:keysAndValuesDo:, keysAndValuesDo:, reverseDo:, with:do:
Note:
The semantics of these operations require that the receiver collection be ordered.
Porting tip:
The doWithIndex:, from:to:do:, and from:to:doWithIndex: messages are not supported in Smalltalk/V or ObjectWorks\Smalltalk.
The ANSI from:to:keysAndValuesDo: and keysAndValuesDo: messages should be used in preference to the CLDT from:to:doWithIndex: and doWithIndex: messages to aid portability.
Ordered removing
removeAtIndex:, removeFirst, removeLast
Note:
The semantics of these operations require that the receiver collection be ordered.
Rehashing
rehash
Note:
It is customary for collections such as Set, Dictionary, IdentityDictionary, and LookupTable to use the hash of elements to implement efficient access and store operations. The use of element hash values to locate elements creates a problem if the hash values of the elements change for some reason. For example, if a copy of the collection is passed to another platform in a distributed system that uses different hash functions for objects in the collection, the collection will not function correctly. The rehash message enables implementers to guarantee that hash-based accessing is safe.
Removing
remove:, remove:ifAbsent:, removeAll:
String accessing and converting
<, <=, >, >=, allSubStrings:, asLowercase, asNumber, asString, asSymbol, asUppercase, includesSubString:, includesSubString:caseSensitive:, indexOf:matchCase:startingAt:, match:, match:ignoreCase:, matchPatternFrom:in:from:ignoreCase:, nullTerminated, sameAs:, subStrings, subStrings:
Note:
Implementations of the messages <, <=, >, and >= use the U.S. English collation sequence and do not necessarily reflect the collation sequence used by the underlying platform. The message is needed for practical string searching.
The implementation of subStrings: has changed to conform to the ANSI Smalltalk specification; allSubStrings: provides the original behavior for those who need it.
Porting tip:
Smalltalk/V does not support match: and sameAs:. It also uses asLowerCase and asUpperCase rather than the Blue Book (and VA Smalltalk) spelling asLowercase and asUppercase.
Neither Smalltalk/V nor Objectworks\Smalltalk support indexOf:matchCase:startingAt:.
Collating sequences vary from platform to platform (for example, case sensitivity) and from language to language (for example, some languages treat certain combinations of letters as a single character). String comparison results can therefore differ between platforms. The messages <, <=, >, and >= perform case insensitive comparison, while the = message is case sensitive. This means, for example, that <= is not the "logical or" of < and =. Use sameAs: instead of = for case insensitive equality comparison.
Storing
at:put:, atAll:put:, atAllPut:, basicAt:put:, replaceFrom:to:with:, replaceFrom:to:with:startingAt:, replaceFrom:to:withObject:
Note:
The message replaceFrom:to:withObject: is not in the Blue Book but has been included in CLDT for symmetry and completeness.
Porting tip:
The method replaceFrom:to:withObject: is supported in Smalltalk/V but not in Objectworks\Smalltalk.
Testing
includes:, isEmpty, notEmpty, occurrencesOf:, size