|
Class: SequenceWithSentinel
Object
|
+--Collection
|
+--SequenceableCollection
|
+--SequenceWithSentinel
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.2
date: 2013/06/25 11:23:55
- user: cg
- file: SequenceWithSentinel.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
A collection with a default value for out-of-bounds accessed values.
instance creation
-
new
-
(comment from inherited method)
return an instance of myself without indexed variables
-
on: aSequence sentinel: anObject
-
return a new collection based on aSequence but with invalid bounds-accesses returning abObject
accessing
-
at: anIndex
-
return the element at anIndex, or sentinel if the index is invalid
-
at: anIndex put: anObject
-
(comment from inherited method)
store the 2nd arg, anObject as indexed instvar with index, anInteger.
this method can be redefined in subclasses. Returns anObject (sigh)
-
size
-
answer my size
enumeration
-
do: aBlock
-
(comment from inherited method)
evaluate the argument, aBlock for every element in the collection in
sequence order.
growing
-
grow: howBig
-
(comment from inherited method)
change the receiver's size
private
-
sentinel: anObject
-
set the sentinel - the value returned for invalid indices
-
sequence: aSequence
-
set the underlying collection
-
sequence: aSequence sentinel: aSentinelValue
-
set the underlying collection and the sentinel (default)
testing
-
isFixedSize
-
return true if the receiver cannot grow
|coll|
coll := SequenceWithSentinel on:#(10 20 30 40 50) sentinel:'invalid'.
Transcript show:'1->'; showCR:(coll at:1).
Transcript show:'5->'; showCR:(coll at:5).
Transcript show:'6->'; showCR:(coll at:6).
coll do:[:each | Transcript showCR:each].
|
|