|
Class: SequenceWithSentinel
Object
|
+--Collection
|
+--SequenceableCollection
|
+--SequenceWithSentinel
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.4
date: 2021/01/20 14:07:02
- user: cg
- file: SequenceWithSentinel.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
A collection with a default value for out-of-bounds accessed values.
copyrightJun430 (2002/05/28)
Copyleft 1996-2002
AOKI Atsushi, ODA Tomohiro, HOSHI Takanori, NISHINAKA Yoshiyuki,
YAMADA Ryousuke, WATANABE Katsuhiro, Ankur J. Chavda, NISHIHARA Satoshi,
MATSUDA Ryouichi, MATSUO Minoru, Brent N. Reeves, ASAOKA Hiroko, and TANAKA Shinichi.
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
-
evaluate the argument, aBlock for every element in the collection.
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].
|
|