1866
|
1 |
"
|
|
2 |
Jun430 (2002/05/28)
|
|
3 |
|
|
4 |
Copyleft 1996-2002
|
|
5 |
AOKI Atsushi, ODA Tomohiro, HOSHI Takanori, NISHINAKA Yoshiyuki,
|
|
6 |
YAMADA Ryousuke, WATANABE Katsuhiro, Ankur J. Chavda, NISHIHARA Satoshi,
|
|
7 |
MATSUDA Ryouichi, MATSUO Minoru, Brent N. Reeves, ASAOKA Hiroko, and TANAKA Shinichi.
|
|
8 |
"
|
|
9 |
"{ Package: 'stx:libbasic2' }"
|
|
10 |
|
|
11 |
SequenceableCollection subclass:#SequenceWithSentinel
|
|
12 |
instanceVariableNames:'sequence sentinel'
|
|
13 |
classVariableNames:''
|
|
14 |
poolDictionaries:''
|
|
15 |
category:'Collections-Sequenceable'
|
|
16 |
!
|
|
17 |
|
|
18 |
!SequenceWithSentinel class methodsFor:'documentation'!
|
|
19 |
|
|
20 |
copyright
|
|
21 |
"
|
|
22 |
Jun430 (2002/05/28)
|
|
23 |
|
|
24 |
Copyleft 1996-2002
|
|
25 |
AOKI Atsushi, ODA Tomohiro, HOSHI Takanori, NISHINAKA Yoshiyuki,
|
|
26 |
YAMADA Ryousuke, WATANABE Katsuhiro, Ankur J. Chavda, NISHIHARA Satoshi,
|
|
27 |
MATSUDA Ryouichi, MATSUO Minoru, Brent N. Reeves, ASAOKA Hiroko, and TANAKA Shinichi.
|
|
28 |
"
|
|
29 |
|
|
30 |
"Modified: / 27-03-2007 / 11:31:36 / cg"
|
|
31 |
!
|
|
32 |
|
|
33 |
documentation
|
|
34 |
"
|
|
35 |
A collection with a default value for out-of-bounds accessed values.
|
|
36 |
"
|
|
37 |
|
|
38 |
"Created: / 27-03-2007 / 11:32:14 / cg"
|
|
39 |
!
|
|
40 |
|
|
41 |
examples
|
|
42 |
"
|
|
43 |
[exBegin]
|
|
44 |
|coll|
|
|
45 |
|
|
46 |
coll := SequenceWithSentinel on:#(10 20 30 40 50) sentinel:'invalid'.
|
|
47 |
Transcript show:'1->'; showCR:(coll at:1).
|
|
48 |
Transcript show:'5->'; showCR:(coll at:5).
|
|
49 |
Transcript show:'6->'; showCR:(coll at:6).
|
|
50 |
coll do:[:each | Transcript showCR:each].
|
|
51 |
[exEnd]
|
|
52 |
"
|
|
53 |
|
|
54 |
"Created: / 27-03-2007 / 11:32:14 / cg"
|
|
55 |
! !
|
|
56 |
|
|
57 |
!SequenceWithSentinel class methodsFor:'instance creation'!
|
|
58 |
|
|
59 |
new
|
|
60 |
self shouldNotImplement
|
|
61 |
|
|
62 |
"Modified: / 27-03-2007 / 11:36:32 / cg"
|
|
63 |
!
|
|
64 |
|
|
65 |
on: aSequence sentinel: anObject
|
|
66 |
"return a new collection based on aSequence but with invalid bounds-accesses returning abObject"
|
|
67 |
|
|
68 |
| newSequence |
|
|
69 |
|
|
70 |
newSequence := self basicNew.
|
|
71 |
newSequence sequence: aSequence sentinel: anObject.
|
|
72 |
^ newSequence
|
|
73 |
|
|
74 |
"Modified: / 27-03-2007 / 11:38:05 / cg"
|
|
75 |
! !
|
|
76 |
|
|
77 |
!SequenceWithSentinel methodsFor:'accessing'!
|
|
78 |
|
|
79 |
at: anIndex
|
|
80 |
"return the element at anIndex, or sentinel if the index is invalid"
|
|
81 |
|
|
82 |
^ (anIndex between:1 and:self size)
|
|
83 |
ifTrue: [sequence at: anIndex]
|
|
84 |
ifFalse: [sentinel]
|
|
85 |
|
|
86 |
"Modified: / 27-03-2007 / 11:33:23 / cg"
|
|
87 |
!
|
|
88 |
|
|
89 |
at: anIndex put: anObject
|
|
90 |
^ sequence at: anIndex put: anObject
|
|
91 |
|
|
92 |
"Modified: / 27-03-2007 / 11:33:59 / cg"
|
|
93 |
!
|
|
94 |
|
|
95 |
size
|
|
96 |
"answer my size"
|
|
97 |
|
|
98 |
^ sequence size
|
|
99 |
|
|
100 |
"Modified: / 27-03-2007 / 11:34:22 / cg"
|
|
101 |
! !
|
|
102 |
|
|
103 |
!SequenceWithSentinel methodsFor:'enumeration'!
|
|
104 |
|
|
105 |
do:aBlock
|
|
106 |
sequence do:aBlock
|
|
107 |
|
|
108 |
"Created: / 27-03-2007 / 11:34:46 / cg"
|
|
109 |
! !
|
|
110 |
|
|
111 |
!SequenceWithSentinel methodsFor:'growing'!
|
|
112 |
|
|
113 |
grow:howBig
|
|
114 |
sequence grow:howBig
|
|
115 |
|
|
116 |
"Created: / 27-03-2007 / 11:35:40 / cg"
|
|
117 |
! !
|
|
118 |
|
|
119 |
!SequenceWithSentinel methodsFor:'private'!
|
|
120 |
|
|
121 |
sentinel: anObject
|
|
122 |
"set the sentinel - the value returned for invalid indices"
|
|
123 |
|
|
124 |
sentinel := anObject
|
|
125 |
|
|
126 |
"Modified: / 27-03-2007 / 11:33:53 / cg"
|
|
127 |
!
|
|
128 |
|
|
129 |
sequence: aSequence
|
|
130 |
"set the underlying collection"
|
|
131 |
|
|
132 |
sequence := aSequence
|
|
133 |
|
|
134 |
"Modified: / 27-03-2007 / 11:34:10 / cg"
|
|
135 |
!
|
|
136 |
|
|
137 |
sequence: aSequence sentinel: aSentinelValue
|
|
138 |
"set the underlying collection and the sentinel (default)"
|
|
139 |
|
|
140 |
sequence := aSequence.
|
|
141 |
sentinel := aSentinelValue.
|
|
142 |
|
|
143 |
"Created: / 27-03-2007 / 11:37:24 / cg"
|
|
144 |
! !
|
|
145 |
|
3019
|
146 |
!SequenceWithSentinel methodsFor:'testing'!
|
|
147 |
|
|
148 |
isFixedSize
|
|
149 |
"return true if the receiver cannot grow"
|
|
150 |
|
|
151 |
^ sequence isFixedSize
|
|
152 |
! !
|
|
153 |
|
1866
|
154 |
!SequenceWithSentinel class methodsFor:'documentation'!
|
|
155 |
|
|
156 |
version
|
3019
|
157 |
^ '$Header: /cvs/stx/stx/libbasic2/SequenceWithSentinel.st,v 1.2 2013-06-25 11:23:55 cg Exp $'
|
1866
|
158 |
! !
|
3019
|
159 |
|