author | Stefan Vogel <sv@exept.de> |
Fri, 13 Apr 2001 18:57:35 +0200 | |
changeset 5844 | 3235138edd0e |
parent 5752 | 66031c1d493a |
child 5864 | efddf7097b68 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5359
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
14 |
|
1 | 15 |
Object subclass:#Collection |
936
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
16 |
instanceVariableNames:'' |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
17 |
classVariableNames:'InvalidKeySignal EmptyCollectionSignal ValueNotFoundSignal |
5497 | 18 |
NotEnoughElementsSignal RecursiveCollectionStoreStringSignal' |
936
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
19 |
poolDictionaries:'' |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
20 |
category:'Collections-Abstract' |
1 | 21 |
! |
22 |
||
2097 | 23 |
!Collection class methodsFor:'documentation'! |
88 | 24 |
|
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
155 | 28 |
All Rights Reserved |
1 | 29 |
|
88 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
1 | 38 |
|
88 | 39 |
documentation |
40 |
" |
|
41 |
Abstract superclass for all collections. |
|
42 |
This abstract class provides functionality common to all collections, |
|
43 |
without knowing how the concrete class implements things. Thus, all |
|
44 |
methods found here depend on some basic mechanisms to be defined in the |
|
45 |
concrete class. |
|
46 |
These basic methods are usually defined as #subclassResponsibility here. |
|
47 |
Some methods are also redefined for better performance. |
|
1289 | 48 |
|
1325 | 49 |
Subclasses should at least implement: |
50 |
do: - enumerate elements |
|
51 |
||
52 |
they should implement one of the following set of access messages: |
|
53 |
keyed collections: |
|
54 |
at:ifAbsent: - fetching an element |
|
55 |
at: - fetching an element |
|
56 |
at:put: - storing an element |
|
57 |
||
58 |
unkeyed collections: |
|
59 |
add: - add an element |
|
60 |
remove:ifAbsent: - remove an element |
|
61 |
||
62 |
||
1289 | 63 |
[author:] |
64 |
Claus Gittinger |
|
88 | 65 |
" |
66 |
! ! |
|
1 | 67 |
|
2097 | 68 |
!Collection class methodsFor:'initialization'! |
10 | 69 |
|
70 |
initialize |
|
71 |
"setup the signal" |
|
72 |
||
54 | 73 |
InvalidKeySignal isNil ifTrue:[ |
3102
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
74 |
InvalidKeySignal := ErrorSignal newSignalMayProceed:true. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
75 |
InvalidKeySignal nameClass:self message:#invalidKeySignal. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
76 |
InvalidKeySignal notifierString:'invalid key:'. |
345 | 77 |
|
3102
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
78 |
ValueNotFoundSignal := NotFoundSignal newSignalMayProceed:true. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
79 |
ValueNotFoundSignal nameClass:self message:#valueNotFoundSignal. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
80 |
ValueNotFoundSignal notifierString:'value not found:'. |
155 | 81 |
|
3102
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
82 |
NotEnoughElementsSignal := NotFoundSignal newSignalMayProceed:true. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
83 |
NotEnoughElementsSignal nameClass:self message:#notEnoughElementsSignal. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
84 |
NotEnoughElementsSignal notifierString:'not enough elements in collection'. |
348 | 85 |
|
3102
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
86 |
EmptyCollectionSignal := NotEnoughElementsSignal newSignalMayProceed:true. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
87 |
EmptyCollectionSignal nameClass:self message:#emptyCollectionSignal. |
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
88 |
EmptyCollectionSignal notifierString:'operation not allowed for empty collections'. |
54 | 89 |
] |
3102
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
90 |
|
2bc81588db6c
sigs are children of NotFoundSignal (ST80 compat)
Claus Gittinger <cg@exept.de>
parents:
3075
diff
changeset
|
91 |
"Modified: / 8.11.1997 / 19:18:17 / cg" |
10 | 92 |
! ! |
93 |
||
2097 | 94 |
!Collection class methodsFor:'instance creation'! |
155 | 95 |
|
602 | 96 |
new:size withAll:element |
5626 | 97 |
"return a new Collection of size, where all elements are |
602 | 98 |
initialized to element" |
348 | 99 |
|
602 | 100 |
|newCollection| |
92 | 101 |
|
602 | 102 |
newCollection := self new:size. |
103 |
size timesRepeat:[newCollection add:element] |
|
104 |
! |
|
1 | 105 |
|
5626 | 106 |
newFrom:aCollection |
107 |
"Return an instance of me containing the same elements as aCollection." |
|
108 |
||
109 |
^ self withAll:aCollection |
|
110 |
||
111 |
" |
|
112 |
Bag newFrom:#(1 2 3 4 4 5 6 7 7 7 ) |
|
113 |
Set newFrom:#(1 2 3 4 4 5 6 7 7 7 ) |
|
114 |
" |
|
115 |
! |
|
116 |
||
1 | 117 |
with:anObject |
118 |
"return a new Collection with one element:anObject" |
|
119 |
||
120 |
|newCollection| |
|
121 |
||
122 |
newCollection := self new. |
|
123 |
newCollection add:anObject. |
|
124 |
^ newCollection |
|
125 |
! |
|
126 |
||
127 |
with:firstObject with:secondObject |
|
128 |
"return a new Collection with two elements:firstObject and secondObject" |
|
129 |
||
130 |
|newCollection| |
|
131 |
||
132 |
newCollection := self new. |
|
1112 | 133 |
newCollection add:firstObject; add:secondObject. |
1 | 134 |
^ newCollection |
135 |
! |
|
136 |
||
137 |
with:firstObject with:secondObject with:thirdObject |
|
138 |
"return a new Collection with three elements" |
|
139 |
||
140 |
|newCollection| |
|
141 |
||
142 |
newCollection := self new. |
|
1112 | 143 |
newCollection add:firstObject; add:secondObject; add:thirdObject. |
1 | 144 |
^ newCollection |
145 |
! |
|
146 |
||
147 |
with:firstObject with:secondObject with:thirdObject with:fourthObject |
|
148 |
"return a new Collection with four elements" |
|
149 |
||
150 |
|newCollection| |
|
151 |
||
152 |
newCollection := self new. |
|
1112 | 153 |
newCollection add:firstObject; add:secondObject; add:thirdObject; add:fourthObject. |
1 | 154 |
^ newCollection |
155 |
! |
|
156 |
||
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
157 |
with:a1 with:a2 with:a3 with:a4 with:a5 |
345 | 158 |
"return a new Collection with five elements" |
159 |
||
160 |
|newCollection| |
|
161 |
||
162 |
newCollection := self new. |
|
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
163 |
newCollection add:a1; add:a2; add:a3; add:a4; add:a5. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
164 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
165 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
166 |
"Modified: 22.1.1997 / 19:34:01 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
167 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
168 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
169 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
170 |
"return a new Collection with size elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
171 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
172 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
173 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
174 |
newCollection := self new. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
175 |
newCollection add:a1; add:a2; add:a3; add:a4; add:a5; add:a6. |
345 | 176 |
^ newCollection |
2225
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
177 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
178 |
"Created: 22.1.1997 / 19:34:14 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
179 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
180 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
181 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 with:a7 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
182 |
"return a new Collection with seven elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
183 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
184 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
185 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
186 |
newCollection := self new. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
187 |
newCollection add:a1; add:a2; add:a3; add:a4; add:a5; add:a6; add:a7. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
188 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
189 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
190 |
"Created: 22.1.1997 / 19:34:24 / cg" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
191 |
! |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
192 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
193 |
with:a1 with:a2 with:a3 with:a4 with:a5 with:a6 with:a7 with:a8 |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
194 |
"return a new Collection with eight elements" |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
195 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
196 |
|newCollection| |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
197 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
198 |
newCollection := self new. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
199 |
newCollection add:a1; add:a2; add:a3; add:a4; add:a5; add:a6; add:a7; add:a8. |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
200 |
^ newCollection |
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
201 |
|
53313e47007a
added with:with: type of instance creation messages
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
202 |
"Created: 22.1.1997 / 19:34:34 / cg" |
345 | 203 |
! |
204 |
||
1 | 205 |
withAll:aCollection |
206 |
"return a new Collection with all elements taken from the argument, |
|
207 |
aCollection" |
|
208 |
||
209 |
|newCollection| |
|
210 |
||
211 |
newCollection := self new. |
|
212 |
newCollection addAll:aCollection. |
|
213 |
^newCollection |
|
214 |
! ! |
|
215 |
||
2097 | 216 |
!Collection class methodsFor:'Signal constants'! |
10 | 217 |
|
602 | 218 |
emptyCollectionSignal |
219 |
"return the signal used to report non-allowed operation on empty collections" |
|
345 | 220 |
|
602 | 221 |
^ EmptyCollectionSignal |
308 | 222 |
! |
223 |
||
602 | 224 |
invalidKeySignal |
225 |
"return the signal used to report bad key usage" |
|
308 | 226 |
|
602 | 227 |
^ InvalidKeySignal |
201 | 228 |
! |
229 |
||
602 | 230 |
notEnoughElementsSignal |
231 |
"return the signal used to report attempts for an operation, for which |
|
232 |
there are not enough elements in the collection" |
|
249 | 233 |
|
602 | 234 |
^ NotEnoughElementsSignal |
404 | 235 |
! |
236 |
||
602 | 237 |
valueNotFoundSignal |
238 |
"return the signal used to report a nonexisting element." |
|
404 | 239 |
|
602 | 240 |
^ ValueNotFoundSignal |
241 |
! ! |
|
404 | 242 |
|
2097 | 243 |
!Collection class methodsFor:'queries'! |
404 | 244 |
|
602 | 245 |
growIsCheap |
246 |
"return true, if this collection can easily grow |
|
247 |
(i.e. without a need for become:). |
|
248 |
Returns true here; this method is redefined in fix-size |
|
249 |
collections" |
|
404 | 250 |
|
602 | 251 |
^ true |
257 | 252 |
! ! |
253 |
||
5752
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
254 |
!Collection methodsFor:'Compatibility - Squeak'! |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
255 |
|
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
256 |
withIndexDo:aTwoArgBlock |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
257 |
"evaluate the argument, aBlock for every element in the collection, |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
258 |
passing both element and index as arguments." |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
259 |
|
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
260 |
^ self keysAndValuesDo:[:key :index | |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
261 |
aTwoArgBlock value:index value:key |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
262 |
]. |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
263 |
! ! |
66031c1d493a
added #withIndexDo: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5651
diff
changeset
|
264 |
|
1 | 265 |
!Collection methodsFor:'accessing'! |
266 |
||
602 | 267 |
anElement |
268 |
"return any element from the collection, or nil if there is none" |
|
269 |
||
270 |
self do: [:each | ^ each]. |
|
271 |
^ nil |
|
272 |
! |
|
273 |
||
1369
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
274 |
atAll:indexCollection put:anObject |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
275 |
"put anObject into all indexes from indexCollection in the receiver. |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
276 |
This abstract implementation requires that the receiver supports |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
277 |
access via a key (and indexCollection contains valid keys). |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
278 |
|
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
279 |
Notice: This operation modifies the receiver, NOT a copy; |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
280 |
therefore the change may affect all others referencing the receiver." |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
281 |
|
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
282 |
indexCollection do:[:index | self at:index put:anObject] |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
283 |
|
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
284 |
" |
3469
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
285 |
args: indexCollection : <Collection of keys<object> > |
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
286 |
returns: self |
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
287 |
" |
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
288 |
|
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
289 |
" |
1369
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
290 |
(Array new:10) atAll:(1 to:5) put:0 |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
291 |
(Array new:10) atAll:#(1 5 6 9) put:0 |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
292 |
(Dictionary new) atAll:#(foo bar baz) put:'hello' |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
293 |
|
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
294 |
raises an error: |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
295 |
(Set new) atAll:#(foo bar baz) put:'hello' |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
296 |
" |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
297 |
|
3469
2c7f6fc4685a
started args / returns comments.
Claus Gittinger <cg@exept.de>
parents:
3402
diff
changeset
|
298 |
"Modified: / 20.5.1998 / 14:50:46 / cg" |
1369
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
299 |
! |
5e7b6fabd248
raised #atAll:put: up in the hierarchy
Claus Gittinger <cg@exept.de>
parents:
1359
diff
changeset
|
300 |
|
4985 | 301 |
fifth |
302 |
"return the fifth element of the collection. |
|
303 |
For unordered collections, this simply returns the fifth |
|
304 |
element when enumerating them. |
|
305 |
This should be redefined in subclasses." |
|
306 |
||
307 |
^ self nth:5 |
|
308 |
||
309 |
" |
|
310 |
#(1 2 3 4 5) fifth |
|
311 |
" |
|
312 |
! |
|
313 |
||
68 | 314 |
first |
315 |
"return the first element of the collection. |
|
4855 | 316 |
For unordered collections, this simply returns the first |
317 |
element when enumerating them. |
|
68 | 318 |
This should be redefined in subclasses." |
319 |
||
320 |
self do:[:e | ^ e]. |
|
321 |
||
322 |
"error if collection is empty" |
|
155 | 323 |
^ self emptyCollectionError |
68 | 324 |
! |
325 |
||
936
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
326 |
firstIfEmpty:exceptionValue |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
327 |
"return the first element of the collection. |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
328 |
If its empty, return the excveptionValue. |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
329 |
(i.e. dont trigger an error as done in #first)" |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
330 |
|
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
331 |
self isEmpty ifTrue:[^ exceptionValue value]. |
3124 | 332 |
^ self first |
936
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
333 |
|
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
334 |
"Modified: 6.2.1996 / 15:27:17 / cg" |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
335 |
! |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
336 |
|
4985 | 337 |
fourth |
338 |
"return the fourth element of the collection. |
|
339 |
For unordered collections, this simply returns the fourth |
|
340 |
element when enumerating them. |
|
341 |
This should be redefined in subclasses." |
|
342 |
||
343 |
^ self nth:4 |
|
344 |
||
345 |
" |
|
346 |
#(1 2 3 4) fourth |
|
347 |
" |
|
348 |
! |
|
349 |
||
68 | 350 |
last |
351 |
"return the last element of the collection. |
|
352 |
This should be redefined in subclasses." |
|
353 |
||
354 |
|theLastOne any| |
|
355 |
||
356 |
any := false. |
|
357 |
self do:[:e | any := true. theLastOne := e]. |
|
358 |
any ifTrue:[ |
|
155 | 359 |
^ theLastOne |
68 | 360 |
]. |
361 |
||
362 |
"error if collection is empty" |
|
155 | 363 |
^ self emptyCollectionError |
68 | 364 |
! |
365 |
||
936
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
366 |
lastIfEmpty:exceptionValue |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
367 |
"return the last element of the collection. |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
368 |
If its empty, return the exceptionValue. |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
369 |
(i.e. dont trigger an error as done in #last)" |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
370 |
|
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
371 |
self isEmpty ifTrue:[^ exceptionValue value]. |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
372 |
^ self last |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
373 |
|
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
374 |
"Modified: 6.2.1996 / 15:27:17 / cg" |
9054edb471b3
added #firstIfEmpty: / #lastIfEmpty:
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
375 |
"Created: 6.2.1996 / 15:27:49 / cg" |
4855 | 376 |
! |
377 |
||
4985 | 378 |
nth:n |
379 |
"return the nth element of the collection. |
|
380 |
For unordered collections, this simply returns the nth |
|
381 |
element when enumerating them. |
|
382 |
This should be redefined in subclasses." |
|
383 |
||
384 |
|count| |
|
385 |
||
386 |
count := 1. |
|
387 |
self do:[:e | |
|
388 |
count == n ifTrue:[^ e]. |
|
389 |
count := count + 1 |
|
390 |
]. |
|
391 |
||
5266 | 392 |
"error if collection is smaller" |
393 |
^ self notEnoughElementsError |
|
4985 | 394 |
|
395 |
" |
|
396 |
#(1 2 3 4) nth:3 |
|
5266 | 397 |
#(1 2 3 4) nth:5 |
398 |
||
399 |
#(1 2 3 4) asSet nth:3 |
|
400 |
#(1 2 3 4) asSet nth:5 |
|
4985 | 401 |
" |
402 |
! |
|
403 |
||
4855 | 404 |
second |
405 |
"return the second element of the collection. |
|
406 |
For unordered collections, this simply returns the second |
|
407 |
element when enumerating them. |
|
408 |
This should be redefined in subclasses." |
|
409 |
||
4856 | 410 |
|count| |
4855 | 411 |
|
4856 | 412 |
count := 1. |
4855 | 413 |
self do:[:e | |
4856 | 414 |
count == 2 ifTrue:[^ e]. |
415 |
count := count + 1 |
|
4855 | 416 |
]. |
417 |
||
5266 | 418 |
"error if collection is smaller" |
419 |
^ self notEnoughElementsError |
|
4855 | 420 |
|
4856 | 421 |
" |
422 |
#(1 2 3) second |
|
423 |
" |
|
424 |
||
425 |
! |
|
426 |
||
4985 | 427 |
sixth |
428 |
"return the sixth element of the collection. |
|
429 |
For unordered collections, this simply returns the sixth |
|
430 |
element when enumerating them. |
|
431 |
This should be redefined in subclasses." |
|
432 |
||
433 |
^ self nth:6 |
|
434 |
||
435 |
" |
|
436 |
#(1 2 3 4 5 6 7) sixth |
|
437 |
" |
|
438 |
! |
|
439 |
||
4856 | 440 |
third |
441 |
"return the third element of the collection. |
|
442 |
For unordered collections, this simply returns the third |
|
443 |
element when enumerating them. |
|
444 |
This should be redefined in subclasses." |
|
445 |
||
4985 | 446 |
^ self nth:3 |
4856 | 447 |
|
448 |
||
449 |
" |
|
450 |
#(1 2 3) third |
|
451 |
" |
|
1 | 452 |
! ! |
453 |
||
454 |
!Collection methodsFor:'adding & removing'! |
|
455 |
||
456 |
add:anObject |
|
88 | 457 |
"add the argument, anObject to the receiver. |
458 |
If the receiver is ordered, the position of the new element is undefined |
|
2351 | 459 |
(i.e. dont depend on where it will be put). |
460 |
An error is raised here - it is to be implemented by a concrete subclass." |
|
1 | 461 |
|
462 |
^ self subclassResponsibility |
|
2351 | 463 |
|
464 |
"Modified: 1.2.1997 / 11:57:08 / cg" |
|
1 | 465 |
! |
466 |
||
1373
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
467 |
add:newObject withOccurrences:anInteger |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
468 |
"add the argument, anObject anInteger times to the receiver. |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
469 |
Returns the object." |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
470 |
|
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
471 |
anInteger timesRepeat:[self add:newObject]. |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
472 |
^ newObject |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
473 |
|
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
474 |
"Created: 11.5.1996 / 12:13:48 / cg" |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
475 |
! |
2c7cab1a4a2e
oops - typo; occurrences has two r's
Claus Gittinger <cg@exept.de>
parents:
1370
diff
changeset
|
476 |
|
1 | 477 |
addAll:aCollection |
1163 | 478 |
"add all elements of the argument, aCollection to the receiver. |
479 |
Returns the argument, aCollection." |
|
1 | 480 |
|
481 |
aCollection do:[:element | |
|
1163 | 482 |
self add:element |
1 | 483 |
]. |
484 |
^ aCollection |
|
88 | 485 |
|
486 |
" |
|
487 |
#(1 2 3 4) copy addAll:#(5 6 7 8) |
|
488 |
#(1 2 3 4) asOrderedCollection addAll:#(5 6 7 8) |
|
489 |
" |
|
1163 | 490 |
|
491 |
"Modified: 12.4.1996 / 13:29:20 / cg" |
|
1 | 492 |
! |
493 |
||
12 | 494 |
addAllFirst:aCollection |
495 |
"insert all elements of the argument, aCollection at the beginning |
|
1163 | 496 |
of the receiver. Returns the argument, aCollection." |
12 | 497 |
|
498 |
aCollection reverseDo:[:element | |
|
1163 | 499 |
self addFirst:element |
12 | 500 |
]. |
501 |
^ aCollection |
|
502 |
||
503 |
" |
|
504 |
|c| |
|
505 |
c := #(4 3 2 1) asOrderedCollection. |
|
1163 | 506 |
c addAllFirst:#(9 8 7 6 5). |
507 |
c |
|
12 | 508 |
" |
1163 | 509 |
|
510 |
"Modified: 12.4.1996 / 13:30:10 / cg" |
|
12 | 511 |
! |
512 |
||
602 | 513 |
addAllLast:aCollection |
1163 | 514 |
"add all elements of the argument, aCollection to the receiver. |
515 |
Returns the argument, aCollection." |
|
602 | 516 |
|
517 |
aCollection do:[:element | |
|
1163 | 518 |
self addLast:element |
602 | 519 |
]. |
520 |
^ aCollection |
|
521 |
||
522 |
" |
|
523 |
|c| |
|
524 |
c := #(4 3 2 1) asOrderedCollection. |
|
525 |
c addAllLast:#(9 8 7 6 5) |
|
526 |
" |
|
1163 | 527 |
|
528 |
"Modified: 12.4.1996 / 13:30:54 / cg" |
|
602 | 529 |
! |
530 |
||
531 |
addFirst:anObject |
|
532 |
"add the argument, anObject to the receiver. |
|
2351 | 533 |
If the receiver is ordered, the new element will be added at the beginning. |
534 |
An error is raised here - it is to be implemented by a concrete subclass." |
|
1 | 535 |
|
536 |
^ self subclassResponsibility |
|
2351 | 537 |
|
538 |
"Modified: 1.2.1997 / 11:57:19 / cg" |
|
1 | 539 |
! |
540 |
||
602 | 541 |
addLast:anObject |
542 |
"add the argument, anObject to the receiver. |
|
1163 | 543 |
If the receiver is ordered, the new element will be added at the end. |
544 |
Return the argument, anObject." |
|
602 | 545 |
|
546 |
^ self add:anObject |
|
1163 | 547 |
|
548 |
"Modified: 12.4.1996 / 13:31:12 / cg" |
|
602 | 549 |
! |
550 |
||
3124 | 551 |
contents:aCollection |
3767
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
552 |
"set my contents from aCollection |
5265 | 553 |
- this may be redefined in a concrete subclass for more performance" |
3124 | 554 |
|
3767
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
555 |
self removeAll. |
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
556 |
aCollection notNil ifTrue:[ |
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
557 |
self addAll:aCollection |
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
558 |
] |
3124 | 559 |
|
3767
bbf560999d90
care for nil arg in #contents:
Claus Gittinger <cg@exept.de>
parents:
3469
diff
changeset
|
560 |
"Modified: / 17.8.1998 / 10:18:43 / cg" |
3124 | 561 |
! |
562 |
||
1 | 563 |
remove:anObject |
2351 | 564 |
"search for the first element, which is equal to anObject; |
565 |
if found, remove and return it. |
|
566 |
If not found, report a 'value not found'-error. |
|
567 |
Uses equality compare (=) to search for the occurrence." |
|
1 | 568 |
|
1163 | 569 |
^ self remove:anObject ifAbsent:[self errorValueNotFound:anObject] |
570 |
||
2351 | 571 |
"Modified: 1.2.1997 / 11:58:48 / cg" |
1 | 572 |
! |
573 |
||
602 | 574 |
remove:anObject ifAbsent:exceptionBlock |
2351 | 575 |
"search for the first element, which is equal to anObject; |
576 |
if found, remove and return it. |
|
577 |
If not found, return the the value of the exceptionBlock. |
|
578 |
Uses equality compare (=) to search for the occurrence. |
|
579 |
An error is raised here - it is to be implemented by a concrete subclass." |
|
602 | 580 |
|
581 |
^ self subclassResponsibility |
|
2351 | 582 |
|
583 |
"Modified: 1.2.1997 / 11:56:53 / cg" |
|
602 | 584 |
! |
585 |
||
134 | 586 |
removeAll |
1163 | 587 |
"remove all elements from the receiver. Returns the receiver. |
134 | 588 |
This should be reimplemented in subclasses for better |
589 |
performance." |
|
590 |
||
2383 | 591 |
[self isEmpty] whileFalse:[ |
1163 | 592 |
self removeFirst |
134 | 593 |
]. |
1163 | 594 |
|
2383 | 595 |
"Modified: 12.2.1997 / 12:40:29 / cg" |
134 | 596 |
! |
597 |
||
1 | 598 |
removeAll:aCollection |
360 | 599 |
"remove all elements of the argument, aCollection from the receiver. |
1163 | 600 |
Return the argument, aCollection. |
5267 | 601 |
Raises an error, if some element-to-remove is not in the receiver. |
602 |
(see also: #removeAllFoundIn:, which does not raise an error). |
|
1163 | 603 |
|
360 | 604 |
Notice: for some collections (those not tuned for |
1163 | 605 |
resizing themself) this may be very slow. |
606 |
If the number of removed elements is big compared to to |
|
607 |
the receivers size, it may be better to copy the |
|
608 |
ones which are not to be removed into a new collection." |
|
1 | 609 |
|
610 |
aCollection do:[:element | self remove:element]. |
|
611 |
^ aCollection |
|
1163 | 612 |
|
5268 | 613 |
" |
614 |
|coll| |
|
615 |
||
616 |
coll := #(1 2 3 4 5 6) asSet. |
|
617 |
coll removeAll:#(4 5 6). |
|
618 |
coll |
|
619 |
" |
|
620 |
||
621 |
"raises an error: |
|
622 |
|coll| |
|
623 |
||
624 |
coll := #(1 2 3 4 5 6) asSet. |
|
625 |
coll removeAll:#(4 5 6 7 8). |
|
626 |
coll |
|
627 |
" |
|
628 |
||
629 |
"no error raised: |
|
630 |
|coll| |
|
631 |
||
632 |
coll := #(1 2 3 4 5 6) asSet. |
|
633 |
coll removeAllFoundIn:#(4 5 6 7 8). |
|
634 |
coll |
|
635 |
" |
|
636 |
||
637 |
||
348 | 638 |
! |
639 |
||
5265 | 640 |
removeAllFoundIn:aCollection |
5267 | 641 |
"Remove each element of aCollection, which is present in the receiver |
642 |
from the receiver. |
|
643 |
No error is raised, if some element-to-remove is not in the receiver. |
|
644 |
(see also: #removeAll:, which does raise an error)." |
|
4980 | 645 |
|
646 |
aCollection do:[:each | self remove:each ifAbsent:[]]. |
|
5265 | 647 |
^ aCollection |
5268 | 648 |
|
649 |
" |
|
650 |
|coll| |
|
651 |
||
652 |
coll := #(1 2 3 4 5 6) asSet. |
|
653 |
coll removeAllFoundIn:#(4 5 6 7 8). |
|
654 |
coll |
|
655 |
" |
|
656 |
||
657 |
"raises an error: |
|
658 |
|coll| |
|
659 |
||
660 |
coll := #(1 2 3 4 5 6) asSet. |
|
661 |
coll removeAll:#(4 5 6 7 8). |
|
662 |
coll |
|
663 |
" |
|
664 |
||
4980 | 665 |
! |
666 |
||
5265 | 667 |
removeAllSuchThat:aBlock |
4980 | 668 |
"Apply the condition to each element and remove it if the condition is true. |
5265 | 669 |
Return a collection of removed elements. |
5267 | 670 |
First elements-to-remove are collected, then removed in one operation." |
4980 | 671 |
|
5267 | 672 |
|removedElements| |
4980 | 673 |
|
5267 | 674 |
removedElements := OrderedCollection new. |
675 |
self do:[:element | |
|
4980 | 676 |
(aBlock value:element) ifTrue: [ |
5267 | 677 |
removedElements add:element |
4980 | 678 |
] |
679 |
]. |
|
5267 | 680 |
self removeAll:removedElements. |
681 |
^ removedElements |
|
682 |
||
683 |
" |
|
684 |
|coll| |
|
685 |
||
686 |
coll := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection. |
|
687 |
coll removeAllSuchThat:[:el | el even]. |
|
688 |
coll |
|
689 |
" |
|
690 |
" |
|
691 |
|coll| |
|
692 |
||
693 |
coll := #(1 2 3 4 5 6 7 8 9 10) asSet. |
|
694 |
coll removeAllSuchThat:[:el | el even]. |
|
695 |
coll |
|
696 |
" |
|
697 |
||
4980 | 698 |
! |
699 |
||
348 | 700 |
removeFirst |
701 |
"remove the first element from the receiver. |
|
702 |
Return the removed element." |
|
703 |
||
1561
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
704 |
self do:[:element | |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
705 |
self remove:element. |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
706 |
^ element. |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
707 |
]. |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
708 |
^ self emptyCollectionError |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
709 |
|
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
710 |
" |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
711 |
(Set with:3 with:2 with:1) removeFirst |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
712 |
" |
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
713 |
|
1f64a9b522c2
at least a suboptimal #removeFirst: can be provided by Collection
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
714 |
"Modified: 28.6.1996 / 18:55:33 / cg" |
348 | 715 |
! |
716 |
||
717 |
removeFirst:n |
|
718 |
"remove the first n elements from the receiver. |
|
5265 | 719 |
Return a collection of removed elements. |
360 | 720 |
Notice: for some collections (those not tuned for |
5265 | 721 |
resizing themself) this may be very slow." |
348 | 722 |
|
723 |
|ret| |
|
724 |
||
725 |
self size < n ifTrue:[ |
|
5265 | 726 |
^ self notEnoughElementsError |
348 | 727 |
]. |
728 |
ret := Array new:n. |
|
729 |
1 to:n do:[:i | |
|
5265 | 730 |
ret at:i put:(self removeFirst). |
348 | 731 |
]. |
732 |
^ ret |
|
733 |
! |
|
734 |
||
2351 | 735 |
removeIdentical:anObject |
736 |
"search for the first element, which is identical to anObject; |
|
737 |
if found, remove and return it. |
|
738 |
If not found, report a 'value not found'-error. |
|
739 |
Uses identity compare (==) to search for the occurrence." |
|
740 |
||
741 |
^ self removeIdentical:anObject ifAbsent:[self errorValueNotFound:anObject] |
|
742 |
||
743 |
"Modified: 12.4.1996 / 13:33:30 / cg" |
|
744 |
"Created: 1.2.1997 / 11:59:10 / cg" |
|
745 |
! |
|
746 |
||
747 |
removeIdentical:anObject ifAbsent:exceptionBlock |
|
748 |
"search for the first element, which is identical to anObject; |
|
749 |
if found, remove and return it. |
|
750 |
If not found, return the the value of the exceptionBlock. |
|
751 |
Uses identity compare (==) to search for the occurrence. |
|
752 |
An error is raised here - it is to be implemented by a concrete subclass." |
|
753 |
||
754 |
^ self subclassResponsibility |
|
755 |
||
756 |
"Created: 1.2.1997 / 11:56:01 / cg" |
|
757 |
"Modified: 1.2.1997 / 11:56:59 / cg" |
|
758 |
! |
|
759 |
||
602 | 760 |
removeLast |
761 |
"remove the last element from the receiver. |
|
2351 | 762 |
Return the removed element. |
763 |
An error is raised here - it is to be implemented by a concrete subclass." |
|
602 | 764 |
|
765 |
^ self subclassResponsibility |
|
2351 | 766 |
|
767 |
"Modified: 1.2.1997 / 11:57:53 / cg" |
|
602 | 768 |
! |
769 |
||
348 | 770 |
removeLast:n |
771 |
"remove the last n elements from the receiver. |
|
5265 | 772 |
Return a collection of removed elements. |
360 | 773 |
Notice: for some collections (those not tuned for |
5265 | 774 |
resizing themself) this may be very slow." |
348 | 775 |
|
776 |
|ret| |
|
777 |
||
778 |
self size < n ifTrue:[ |
|
5265 | 779 |
^ self notEnoughElementsError |
348 | 780 |
]. |
781 |
ret := Array new:n. |
|
782 |
n to:1 by:-1 do:[:i | |
|
5265 | 783 |
ret at:i put:(self removeLast). |
348 | 784 |
]. |
785 |
^ ret |
|
1 | 786 |
! ! |
787 |
||
602 | 788 |
!Collection methodsFor:'converting'! |
789 |
||
790 |
asArray |
|
791 |
"return a new Array with the collections elements" |
|
792 |
||
793 |
|anArray |
|
794 |
index "{ Class: SmallInteger }" | |
|
1 | 795 |
|
602 | 796 |
anArray := Array new:(self size). |
797 |
index := 1. |
|
798 |
self do:[:each | |
|
799 |
anArray at:index put:each. |
|
800 |
index := index + 1 |
|
801 |
]. |
|
802 |
^ anArray |
|
1 | 803 |
! |
804 |
||
602 | 805 |
asBag |
806 |
"return a new Bag with the receiver collections elements" |
|
1 | 807 |
|
602 | 808 |
^ self addAllTo:(Bag new) |
1 | 809 |
! |
810 |
||
602 | 811 |
asByteArray |
812 |
"return a new ByteArray with the collections elements |
|
813 |
(which must convert to integers in the range 0..255)." |
|
1 | 814 |
|
602 | 815 |
|aByteArray |
816 |
index "{ Class: SmallInteger }" | |
|
1 | 817 |
|
602 | 818 |
aByteArray := ByteArray new:(self size). |
819 |
index := 1. |
|
820 |
self do:[:each | |
|
821 |
aByteArray at:index put:each asInteger. |
|
822 |
index := index + 1 |
|
823 |
]. |
|
824 |
^ aByteArray |
|
1 | 825 |
! |
826 |
||
5607
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
827 |
asCollection |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
828 |
"return myself as a Collection. |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
829 |
I am already a Collection." |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
830 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
831 |
^ self |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
832 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
833 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
834 |
! |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
835 |
|
602 | 836 |
asDoubleArray |
837 |
"return a new DoubleArray with the collections elements |
|
838 |
(which must convert to floats)." |
|
839 |
||
840 |
|aDoubleArray |
|
841 |
index "{ Class: SmallInteger }" | |
|
842 |
||
843 |
aDoubleArray := DoubleArray new:(self size). |
|
844 |
index := 1. |
|
845 |
self do:[:each | |
|
846 |
aDoubleArray at:index put:each asFloat. |
|
847 |
index := index + 1 |
|
848 |
]. |
|
849 |
^ aDoubleArray |
|
850 |
! |
|
68 | 851 |
|
602 | 852 |
asFloatArray |
853 |
"return a new FloatArray with the collections elements |
|
854 |
(which must convert to floats)." |
|
855 |
||
856 |
|aFloatArray |
|
857 |
index "{ Class: SmallInteger }" | |
|
858 |
||
859 |
aFloatArray := FloatArray new:(self size). |
|
860 |
index := 1. |
|
861 |
self do:[:each | |
|
862 |
aFloatArray at:index put:each asFloat. |
|
863 |
index := index + 1 |
|
864 |
]. |
|
865 |
^ aFloatArray |
|
866 |
! |
|
867 |
||
868 |
asIdentitySet |
|
869 |
"return a new IdentitySet with the receiver collections elements" |
|
870 |
||
871 |
^ self addAllTo:(IdentitySet new:self size) |
|
68 | 872 |
! |
873 |
||
2167 | 874 |
asList |
875 |
"return a new List with the receiver collections elements" |
|
876 |
||
877 |
^ self addAllTo:(List new:self size) |
|
878 |
||
879 |
"Created: 14.2.1997 / 16:25:23 / cg" |
|
880 |
! |
|
881 |
||
602 | 882 |
asOrderedCollection |
883 |
"return a new OrderedCollection with the receiver collections elements" |
|
884 |
||
885 |
^ self addAllTo:(OrderedCollection new:self size) |
|
886 |
! |
|
887 |
||
1394 | 888 |
asRunArray |
889 |
"return a new RunArray with the collections elements" |
|
890 |
||
3367
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
891 |
^ RunArray from:self. |
1394 | 892 |
|
3367
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
893 |
"/ |runs lastElement occurrences| |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
894 |
"/ |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
895 |
"/ runs := RunArray new. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
896 |
"/ occurrences := 0. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
897 |
"/ self do:[:each | |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
898 |
"/ each == lastElement ifTrue:[ |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
899 |
"/ occurrences := occurrences + 1 |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
900 |
"/ ] ifFalse:[ |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
901 |
"/ runs add:lastElement withOccurrences:occurrences. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
902 |
"/ occurrences := 1. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
903 |
"/ lastElement := each |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
904 |
"/ ]. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
905 |
"/ ]. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
906 |
"/ occurrences ~~ 0 ifTrue:[ |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
907 |
"/ runs add:lastElement withOccurrences:occurrences |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
908 |
"/ ]. |
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
909 |
"/ ^ runs |
1394 | 910 |
|
911 |
" |
|
912 |
#(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray |
|
913 |
" |
|
914 |
||
3367
9510bc82d4d6
use #from: instance creation method in #asRunArray.
Claus Gittinger <cg@exept.de>
parents:
3191
diff
changeset
|
915 |
"Modified: / 7.4.1998 / 09:50:54 / cg" |
1394 | 916 |
! |
917 |
||
5607
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
918 |
asSequenceableCollection |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
919 |
"return myself as a SequenceableCollection. |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
920 |
I am already a Collection, but not sequenceable." |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
921 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
922 |
^ self asArray |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
923 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
924 |
|
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
925 |
! |
94c690ba0dea
Define #asCollection, #asSequenceableCollection
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
926 |
|
602 | 927 |
asSet |
928 |
"return a new Set with the receiver collections elements" |
|
929 |
||
930 |
^ self addAllTo:(Set new:self size) |
|
931 |
! |
|
932 |
||
933 |
asSortedCollection |
|
934 |
"return a new SortedCollection with the receiver collections elements" |
|
1 | 935 |
|
602 | 936 |
|aSortedCollection| |
937 |
||
938 |
aSortedCollection := SortedCollection new:self size. |
|
939 |
aSortedCollection addAll:self. |
|
940 |
^ aSortedCollection |
|
941 |
! |
|
942 |
||
943 |
asSortedCollection:sortBlock |
|
944 |
"return a new SortedCollection with the receiver collections elements, |
|
945 |
using sortBlock for comparing" |
|
946 |
||
947 |
|aSortedCollection| |
|
948 |
||
949 |
aSortedCollection := SortedCollection sortBlock:sortBlock. |
|
950 |
aSortedCollection addAll:self. |
|
951 |
^ aSortedCollection |
|
1 | 952 |
! |
953 |
||
2919 | 954 |
asSortedStrings |
955 |
"Create & return a SortedCollection that sorts the receivers |
|
956 |
elements according to the locales collating policy. |
|
957 |
This is currently not really support - strings are sorted |
|
958 |
without caring for the locale." |
|
959 |
||
960 |
|aSortedCollection| |
|
961 |
||
962 |
aSortedCollection := SortedCollection forStrings:self size. |
|
963 |
aSortedCollection addAll:self. |
|
964 |
^ aSortedCollection |
|
965 |
||
966 |
"Created: 13.9.1997 / 09:36:22 / cg" |
|
967 |
"Modified: 13.9.1997 / 09:43:00 / cg" |
|
968 |
! |
|
969 |
||
970 |
asSortedStrings:sortBlock |
|
971 |
"Create & return a SortedCollection that sorts the receivers |
|
3061 | 972 |
elements using sortBlock and according to the locales collating policy, |
973 |
which is passed as first arg to sortBlock. |
|
2919 | 974 |
This is currently not really support - strings are sorted |
975 |
without caring for the locale." |
|
976 |
||
977 |
|aSortedCollection| |
|
978 |
||
979 |
aSortedCollection := SortedCollection forStrings:self size. |
|
980 |
aSortedCollection sortBlock:sortBlock. |
|
981 |
aSortedCollection addAll:self. |
|
982 |
^ aSortedCollection |
|
983 |
||
3061 | 984 |
"Created: / 13.9.1997 / 09:36:45 / cg" |
985 |
"Modified: / 27.10.1997 / 16:39:48 / cg" |
|
2919 | 986 |
! |
987 |
||
988 |
asSortedStrings:sortBlock with:aCollationPolicy |
|
989 |
"Create & return a SortedCollection that sorts the receivers |
|
990 |
elements using sortBlock and according to the specified locales collating policy. |
|
991 |
This is currently not really support - strings are sorted |
|
992 |
without caring for the locale." |
|
993 |
||
994 |
|aSortedCollection| |
|
995 |
||
996 |
aSortedCollection := SortedCollection forStrings:self size collatedBy:aCollationPolicy. |
|
997 |
aSortedCollection sortBlock:sortBlock. |
|
998 |
aSortedCollection addAll:self. |
|
999 |
^ aSortedCollection |
|
1000 |
||
1001 |
"Created: 13.9.1997 / 09:37:21 / cg" |
|
1002 |
"Modified: 13.9.1997 / 09:45:27 / cg" |
|
1003 |
! |
|
1004 |
||
1005 |
asSortedStringsWith: aCollationPolicy |
|
1006 |
"Create & return a SortedCollection that sorts the receivers |
|
1007 |
elements according to the specified locales collating policy. |
|
1008 |
This is currently not really support - strings are sorted |
|
1009 |
without caring for the locale." |
|
1010 |
||
1011 |
|aSortedCollection| |
|
1012 |
||
1013 |
aSortedCollection := SortedCollection forStrings:self size collatedBy:aCollationPolicy. |
|
1014 |
aSortedCollection addAll:self. |
|
1015 |
^ aSortedCollection |
|
1016 |
||
1017 |
"Created: 13.9.1997 / 09:37:50 / cg" |
|
1018 |
"Modified: 13.9.1997 / 09:44:08 / cg" |
|
1019 |
! |
|
1020 |
||
602 | 1021 |
asString |
1022 |
"return a String with the collections elements |
|
1023 |
(which must convert to characters)" |
|
1024 |
||
1025 |
|aString |
|
1026 |
index "{ Class: SmallInteger }" | |
|
360 | 1027 |
|
602 | 1028 |
aString := String new:(self size). |
1029 |
index := 1. |
|
1030 |
self do:[:each | |
|
1031 |
aString at:index put:each asCharacter. |
|
1032 |
index := index + 1 |
|
360 | 1033 |
]. |
602 | 1034 |
^ aString |
1035 |
! |
|
1036 |
||
1037 |
asStringCollection |
|
1413 | 1038 |
"return a new string collection containing the elements; |
1039 |
these ought to be strings. (i.e. String or Text instances)" |
|
602 | 1040 |
|
1041 |
^ self addAllTo:(StringCollection new) |
|
1413 | 1042 |
|
1043 |
"Modified: 18.5.1996 / 13:54:34 / cg" |
|
360 | 1044 |
! |
1045 |
||
602 | 1046 |
asText |
1047 |
"return a Text-object (collection of lines) from myself. |
|
1048 |
BIG warning: asText is totally misnamed here |
|
1049 |
- ST/X's asText has nothing to do with PP's asText. |
|
1050 |
Therefore it will be removed/renamed soon. |
|
1051 |
Please use #asStringCollection." |
|
1 | 1052 |
|
602 | 1053 |
self obsoleteMethodWarning:'use #asStringCollection; #asText will change its meaning'. |
1054 |
||
1055 |
^ self asStringCollection |
|
1056 |
! |
|
1057 |
||
1058 |
readStream |
|
1059 |
"return a stream for reading from the receiver" |
|
1060 |
||
1061 |
^ ReadStream on:self |
|
88 | 1062 |
|
1063 |
" |
|
602 | 1064 |
|s| |
1065 |
||
1066 |
s := 'hello world' readStream. |
|
1067 |
s next:5. |
|
1068 |
s next. |
|
1069 |
(s next:5) inspect |
|
88 | 1070 |
" |
1 | 1071 |
! |
1072 |
||
602 | 1073 |
writeStream |
1074 |
"return a stream for writing onto the receiver" |
|
1075 |
||
1076 |
^ WriteStream on:self |
|
2 | 1077 |
|
602 | 1078 |
" |
1079 |
|s| |
|
1080 |
||
1081 |
s := #() copy writeStream. |
|
1082 |
s nextPut:1. |
|
1083 |
s nextPut:2. |
|
1084 |
s nextPut:3. |
|
1085 |
s contents inspect |
|
1086 |
" |
|
88 | 1087 |
|
1088 |
" |
|
602 | 1089 |
|s| |
2 | 1090 |
|
602 | 1091 |
s := OrderedCollection new writeStream. |
1092 |
s nextPut:1. |
|
1093 |
s nextPut:2. |
|
1094 |
s nextPut:3. |
|
1095 |
s contents inspect |
|
1096 |
" |
|
1097 |
! ! |
|
1 | 1098 |
|
602 | 1099 |
!Collection methodsFor:'copying'! |
1100 |
||
3381
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1101 |
copy |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1102 |
"return a copy of the receiver. |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1103 |
Redefined to pass the original as argument to tyhe postCopyFrom method." |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1104 |
|
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1105 |
^ self shallowCopy postCopyFrom:self |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1106 |
|
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1107 |
"Created: / 19.4.1998 / 20:02:53 / cg" |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1108 |
! |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1109 |
|
602 | 1110 |
copyEmpty |
1111 |
"return a copy of the receiver with no elements. |
|
1112 |
This is used by copying and enumeration methods |
|
1113 |
to get a new instance which is similar to the receiver." |
|
1114 |
||
1115 |
^ self species new |
|
1 | 1116 |
! |
1117 |
||
602 | 1118 |
copyEmpty:size |
1119 |
"return a copy of the receiver with no elements, but space for |
|
1120 |
size elements. This is used by copying and enumeration methods |
|
1121 |
to get a new instance which is similar to the receiver. |
|
1122 |
This method should be redefined in subclasses with instance |
|
1123 |
variables, which should be put into the copy too. |
|
1124 |
For example, SortedCollection has to copy its sortBlock into the |
|
1125 |
new collection." |
|
1 | 1126 |
|
602 | 1127 |
^ self species new:size |
360 | 1128 |
! |
1129 |
||
602 | 1130 |
copyEmptyAndGrow:size |
1131 |
"return a copy of the receiver with size nil elements. |
|
1132 |
This is used by copying and enumeration methods |
|
1133 |
to get a new instance which is similar to the receiver." |
|
155 | 1134 |
|
602 | 1135 |
^ (self copyEmpty:size) grow:size |
3381
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1136 |
! |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1137 |
|
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1138 |
postCopyFrom:original |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1139 |
"sent to a freshly copied object to give it a chance to adjust things. |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1140 |
Notice, that for Sets/Dicts etc. a rehash is not needed, since the copy |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1141 |
will have the same hash key as the receiver (as long as ST/X provides the |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1142 |
setHash: functionality)." |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1143 |
|
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1144 |
"for ST-80 compatibility, we try postCopy here ..." |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1145 |
^ self postCopy |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1146 |
|
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1147 |
"Created: / 19.4.1998 / 19:59:42 / cg" |
e1c12fa92fbf
moved #postCopyFrom: from object; redefined copy to send this instead
Claus Gittinger <cg@exept.de>
parents:
3367
diff
changeset
|
1148 |
"Modified: / 19.4.1998 / 20:03:57 / cg" |
1 | 1149 |
! ! |
1150 |
||
1151 |
!Collection methodsFor:'enumerating'! |
|
1152 |
||
602 | 1153 |
addAllTo:aCollection |
1154 |
"add all elements of the receiver, to aCollection. |
|
1155 |
Return aCollection." |
|
77 | 1156 |
|
602 | 1157 |
self do:[:each | aCollection add:each]. |
1158 |
^ aCollection |
|
5254 | 1159 |
|
1160 |
" |
|
1161 |
#(1 2 3 4 5 1 2 3 4 5) addAllTo:Set new |
|
1162 |
" |
|
1163 |
||
1164 |
"Modified: / 11.2.2000 / 11:22:14 / cg" |
|
77 | 1165 |
! |
1166 |
||
5207
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1167 |
allSatisfy:aBlock |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1168 |
"evaluate aBlock for each of the receiver's elements. |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1169 |
Return true, if aBlock returns true for all elements, false otherwise |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1170 |
(i.e. false if any element fails to satisfy the block-condition). |
5651 | 1171 |
This is an ANSI renomer of #conform:" |
5207
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1172 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1173 |
^ self conform:aBlock. |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1174 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1175 |
" |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1176 |
#(1 2 3 4 5) allSatisfy:[:el | el odd] |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1177 |
#(2 4 6 8 10) allSatisfy:[:el | el odd] |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1178 |
#(2 4 6 8 10) allSatisfy:[:el | el even] |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1179 |
" |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1180 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1181 |
! |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1182 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1183 |
anySatisfy:aBlock |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1184 |
"evaluate aBlock for each of the receiver's elements. |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1185 |
Return true, if aBlock ever returns true, false otherwise |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1186 |
(i.e. if any element satisfies the block-condition). |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1187 |
This is an ANSI renomer of #contains:" |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1188 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1189 |
^ self contains:aBlock. |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1190 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1191 |
" |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1192 |
#(1 2 3 4 5) anySatisfy:[:el | el odd] |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1193 |
#(2 4 6 8 10) anySatisfy:[:el | el odd] |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1194 |
" |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1195 |
|
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1196 |
! |
1b927d32eb51
added #anySatisfy:: and #allSatisy: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
5048
diff
changeset
|
1197 |
|
1 | 1198 |
collect:aBlock |
1199 |
"for each element in the receiver, evaluate the argument, aBlock |
|
1200 |
and return a new collection with the results" |
|
1201 |
||
1202 |
|newCollection| |
|
1203 |
||
201 | 1204 |
newCollection := self species new. |
1205 |
self do:[:element | newCollection add:(aBlock value:element)]. |
|
1 | 1206 |
^ newCollection |
68 | 1207 |
|
1208 |
" |
|
1209 |
#(1 2 3 4) collect:[:n | n * 2] |
|
1210 |
" |
|
1 | 1211 |
! |
1212 |
||
4890 | 1213 |
collect:collectBlock thenSelect:selectBlock |
1214 |
"combination of collect followed by select. |
|
1215 |
May be redefined by some subclasses for optimal performance |
|
5265 | 1216 |
(avoidong the creation of intermediate garbage)" |
4890 | 1217 |
|
4892 | 1218 |
^ (self collect:collectBlock) select:selectBlock |
1219 |
||
1220 |
" |
|
1221 |
#(1 2 3 4 5 6 7) collect:[:i | i * 2] thenSelect:[:i | i < 10] |
|
1222 |
" |
|
4890 | 1223 |
|
1224 |
! |
|
1225 |
||
602 | 1226 |
conform:aBlock |
1227 |
"return true, if every element conforms to some condition. |
|
1228 |
I.e. return false, if aBlock returns false for any element; |
|
1229 |
true otherwise." |
|
77 | 1230 |
|
602 | 1231 |
self do:[:element | (aBlock value:element) ifFalse:[^ false]]. |
1232 |
^ true |
|
1233 |
! |
|
77 | 1234 |
|
2665
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1235 |
contains:aBlock |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1236 |
"evaluate aBlock for each of the receiver's elements. |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1237 |
Return true, if aBlock ever returns true, false otherwise." |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1238 |
|
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1239 |
self detect:aBlock ifNone:[^ false]. |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1240 |
^ true |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1241 |
|
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1242 |
" |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1243 |
#(1 2 3 4 5) contains:[:el | el odd] |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1244 |
#(2 4 6 8 10) contains:[:el | el odd] |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1245 |
" |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1246 |
|
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1247 |
"Modified: 26.5.1997 / 17:38:57 / cg" |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1248 |
! |
13998f6189af
added #contains: for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2639
diff
changeset
|
1249 |
|
602 | 1250 |
count:aBlock |
1251 |
"count elements, for which aBlock returns true. |
|
1252 |
Return the sum." |
|
1253 |
||
1254 |
^ self inject:0 into:[:sumSoFar :element | |
|
1255 |
(aBlock value:element) ifTrue:[sumSoFar + 1] |
|
1256 |
ifFalse:[sumSoFar] |
|
1257 |
] |
|
77 | 1258 |
|
1259 |
" |
|
602 | 1260 |
#(1 2 3 4 6 8 10) count:[:a | a even] |
1261 |
#(1 nil nil nil 2 3 nil 4 5) count:[:a | a isNil] |
|
77 | 1262 |
" |
1263 |
! |
|
1264 |
||
1 | 1265 |
detect:aBlock |
1266 |
"evaluate the argument, aBlock for each element in the receiver until |
|
1267 |
the block returns true; in this case return the element which caused |
|
1268 |
the true evaluation. |
|
345 | 1269 |
If none of the evaluations returns true, report an error" |
1 | 1270 |
|
1271 |
^ self detect:aBlock ifNone:[self errorNotFound] |
|
68 | 1272 |
|
1273 |
" |
|
1274 |
#(1 2 3 4) detect:[:n | n odd] |
|
1275 |
#(2 4 6 8) detect:[:n | n odd] |
|
1276 |
" |
|
1 | 1277 |
! |
1278 |
||
1279 |
detect:aBlock ifNone:exceptionBlock |
|
1280 |
"evaluate the argument, aBlock for each element in the receiver until |
|
1281 |
the block returns true; in this case return the element which caused |
|
1282 |
the true evaluation. |
|
1283 |
If none of the evaluations returns true, return the result of the |
|
1284 |
evaluation of the exceptionBlock" |
|
1285 |
||
1286 |
self do:[:each | |
|
155 | 1287 |
(aBlock value:each) ifTrue:[^ each]. |
1 | 1288 |
]. |
1289 |
^ exceptionBlock value |
|
68 | 1290 |
|
1291 |
" |
|
1292 |
#(1 2 3 4) detect:[:n | n odd] ifNone:['sorry'] |
|
1293 |
#(2 4 6 8) detect:[:n | n odd] ifNone:['sorry'] |
|
1294 |
" |
|
1 | 1295 |
! |
1296 |
||
421 | 1297 |
detectLast:aBlock |
1298 |
"evaluate the argument, aBlock for each element in the receiver until |
|
1299 |
the block returns true; in this case return the element which caused |
|
1300 |
the true evaluation. The elements are processed in reverse order. |
|
1301 |
If none of the evaluations returns true, report an error" |
|
1302 |
||
1303 |
^ self detectLast:aBlock ifNone:[self errorNotFound] |
|
1304 |
||
1305 |
" |
|
1306 |
#(1 2 3 4) detectLast:[:n | n odd] |
|
1307 |
#(2 4 6 8) detectLast:[:n | n odd] |
|
1308 |
" |
|
1309 |
! |
|
1310 |
||
1311 |
detectLast:aBlock ifNone:exceptionBlock |
|
1312 |
"evaluate the argument, aBlock for each element in the receiver until |
|
1313 |
the block returns true; in this case return the element which caused |
|
1314 |
the true evaluation. The elements are processed in reverse order. |
|
1315 |
If none of the evaluations returns true, return the result of the |
|
1316 |
evaluation of the exceptionBlock" |
|
1317 |
||
1318 |
self reverseDo:[:each | |
|
1319 |
(aBlock value:each) ifTrue:[^ each]. |
|
1320 |
]. |
|
1321 |
^ exceptionBlock value |
|
1322 |
||
1323 |
" |
|
1324 |
#(1 2 3 4) detectLast:[:n | n odd] ifNone:['sorry'] |
|
1325 |
#(2 4 6 8) detectLast:[:n | n odd] ifNone:['sorry'] |
|
1326 |
" |
|
1327 |
! |
|
1328 |
||
602 | 1329 |
do:aBlock |
1330 |
"evaluate the argument, aBlock for each element" |
|
1331 |
||
1332 |
^ self subclassResponsibility |
|
1333 |
! |
|
1334 |
||
4394 | 1335 |
do:aBlock inBetweenDo:betweenBlock |
1336 |
"evaluate the argument, aBlock for each element. |
|
1337 |
Between elements (i.e. after each except for the last), |
|
1338 |
evaluate betweenBlock. |
|
5254 | 1339 |
This is a utility helper for collection printers |
1340 |
(for example, to print a space between elements)." |
|
4394 | 1341 |
|
1342 |
|first| |
|
1343 |
||
1344 |
first := true. |
|
1345 |
self do:[:element | |
|
1346 |
first ifTrue:[ |
|
1347 |
first := false |
|
1348 |
] ifFalse:[ |
|
1349 |
betweenBlock value. |
|
1350 |
]. |
|
1351 |
aBlock value:element |
|
1352 |
]. |
|
1353 |
||
1354 |
" |
|
1355 |
#(1 2 3 4) do:[:el | Transcript show:el] |
|
1356 |
inBetweenDo:[ Transcript show:'-'] |
|
5619 | 1357 |
|
1358 |
(Dictionary with:(1->'one') with:(2->'two')) |
|
1359 |
do:[:el | Transcript showCR:el printString] |
|
1360 |
inBetweenDo:[ Transcript showCR:'----'] |
|
1361 |
||
1362 |
(Dictionary with:(1->'one') with:(2->'two')) |
|
1363 |
associations |
|
1364 |
do:[:el | Transcript showCR:el printString] |
|
1365 |
inBetweenDo:[ Transcript showCR:'----'] |
|
1366 |
||
4394 | 1367 |
" |
5254 | 1368 |
|
1369 |
"Modified: / 11.2.2000 / 11:23:15 / cg" |
|
4394 | 1370 |
! |
1371 |
||
1212 | 1372 |
doWithExit:aBlock |
1373 |
"evaluate the argument, aBlock for each element. |
|
1374 |
Passes an additional exit object, which can be used to leave |
|
1375 |
the loop early, by sending it a #value: message. |
|
1376 |
Returns nil or the value passed to the exit>>value: message. |
|
1377 |
||
1378 |
Notice, that this is different to a return from the block, which |
|
1379 |
returns from the enclosed method, NOT only from the block." |
|
1380 |
||
1381 |
^ [:exit | |
|
1382 |
self do:[:el | |
|
1383 |
aBlock value:el value:exit |
|
1384 |
]. |
|
1385 |
nil |
|
1386 |
] valueWithExit. |
|
1387 |
||
1388 |
"Example: |
|
1389 |
search for the first element which is >= 99; return it. |
|
1390 |
remaining elements are not processed: |
|
1391 |
||
1392 |
#(1 2 3 4 999 5 6 7 8 9) |
|
1393 |
doWithExit:[:element :exit | |
|
1422 | 1394 |
Transcript showCR:element. |
1212 | 1395 |
element >= 99 ifTrue:[exit value:element]] |
1396 |
||
1397 |
#(1 2 3 4 5 6 7 8 9) |
|
1398 |
doWithExit:[:element :exit | |
|
1422 | 1399 |
Transcript showCR:element. |
1212 | 1400 |
element >= 99 ifTrue:[exit value:element]] |
1401 |
" |
|
1402 |
||
1403 |
"to demonstrate the difference to returning from the block: |
|
1404 |
this works: |
|
1405 |
||
1406 |
|el| |
|
1407 |
||
1408 |
el := #(1 2 3 4 999 5 6 7 8 9) |
|
1409 |
doWithExit:[:element :exit | |
|
1410 |
element >= 99 ifTrue:[exit value:element]]. |
|
1422 | 1411 |
Transcript showCR:el. |
1212 | 1412 |
|
1413 |
||
1422 | 1414 |
this does NOT work as expected by a newComer ;-) (the showCR is not reached): |
1212 | 1415 |
|
1416 |
|el| |
|
1417 |
||
1418 |
el := #(1 2 3 4 999 5 6 7 8 9) |
|
1419 |
do:[:element | |
|
1420 |
element >= 99 ifTrue:[^ element]]. |
|
1422 | 1421 |
Transcript showCR:el. |
1212 | 1422 |
" |
1423 |
||
1424 |
"Modified: 18.4.1996 / 14:16:59 / cg" |
|
1425 |
! |
|
1426 |
||
1 | 1427 |
inject:thisValue into:binaryBlock |
1262 | 1428 |
"starting with thisValue for value, pass this value and each element |
1429 |
to binaryBlock, replacing value with the result returned from the block |
|
1430 |
in the next iteration." |
|
1431 |
||
1 | 1432 |
|nextValue| |
1433 |
||
1434 |
nextValue := thisValue. |
|
1435 |
self do: [:each | nextValue := binaryBlock value:nextValue value:each]. |
|
1436 |
^ nextValue |
|
68 | 1437 |
|
1262 | 1438 |
"sum up the elements of a collection: |
1439 |
||
68 | 1440 |
#(1 2 3 4) inject:0 into:[:accu :element | accu + element] |
1441 |
(1 to:10) inject:0 into:[:accu :element | accu + element] |
|
1262 | 1442 |
|
1443 |
find the minimum: |
|
1444 |
||
1445 |
|coll| |
|
1446 |
coll := #(1 99 -15 20 100). |
|
1447 |
coll inject:(coll first) into:[:minSoFar :element | minSoFar min:element] |
|
68 | 1448 |
" |
1262 | 1449 |
|
1450 |
"Modified: 23.4.1996 / 13:47:06 / cg" |
|
1 | 1451 |
! |
1452 |
||
602 | 1453 |
keysAndValuesDo:aTwoArgBlock |
1454 |
"evaluate the argument, aBlock for every element in the collection, |
|
1455 |
passing both index and element as arguments." |
|
1456 |
||
1457 |
^ self errorNotKeyed |
|
1458 |
! |
|
1459 |
||
1359 | 1460 |
keysAndValuesReverseDo:aTwoArgBlock |
1461 |
"evaluate the argument, aBlock in reverse order for every element in the collection, |
|
1462 |
passing both index and element as arguments." |
|
1463 |
||
1464 |
^ self errorNotKeyed |
|
1465 |
||
1466 |
"Created: 9.5.1996 / 00:58:24 / cg" |
|
1467 |
! |
|
1468 |
||
602 | 1469 |
pairsDo:aBlock |
1470 |
"evaluate the argument, aBlock for every element in the collection, |
|
1471 |
which is supposed to consist of 2-element collections. |
|
1472 |
The block is called with 2 arguments for each collection in the receiver." |
|
1473 |
||
1474 |
self do:[:aPair | |
|
1475 |
aBlock value:(aPair at:1) value:(aPair at:2). |
|
1476 |
] |
|
1477 |
" |
|
1478 |
#( (1 one) (2 two) (3 three) (4 four) (5 five) (6 six)) |
|
1422 | 1479 |
pairsDo:[:num :sym | Transcript show:num; show:' is: '; showCR:sym] |
602 | 1480 |
|
1481 |
||
1482 |
#( (1 1) (1 2) (1 3) (1 4) (1 5)) |
|
1422 | 1483 |
pairsDo:[:x :y | Transcript showCR:x@y] |
602 | 1484 |
" |
1485 |
! |
|
1486 |
||
1 | 1487 |
reject:aBlock |
1488 |
"return a new collection with all elements from the receiver, for which |
|
1489 |
the argument aBlock evaluates to false" |
|
1490 |
||
1491 |
^ self select:[:element | (aBlock value:element) == false] |
|
68 | 1492 |
|
1493 |
" |
|
1494 |
#(1 2 3 4) reject:[:e | e odd] |
|
1495 |
(1 to:10) reject:[:e | e even] |
|
1496 |
" |
|
1 | 1497 |
! |
1498 |
||
602 | 1499 |
reverseDo:aBlock |
1500 |
"evaluate the argument, aBlock for each element in reverse order." |
|
1501 |
||
1502 |
"it could be defined in terms of do: - but very inefficient. |
|
1503 |
Better force programmer to define a better version ..." |
|
1504 |
||
1505 |
^ self subclassResponsibility |
|
1506 |
! |
|
1507 |
||
1 | 1508 |
select:aBlock |
1509 |
"return a new collection with all elements from the receiver, for which |
|
5265 | 1510 |
the argument aBlock evaluates to true. |
1511 |
See also: #removeAllFoundIn: and #removeAllSuchThat:" |
|
1 | 1512 |
|
1513 |
|newCollection| |
|
1514 |
||
201 | 1515 |
newCollection := self species new. |
1 | 1516 |
self do:[:each | |
5265 | 1517 |
(aBlock value:each) ifTrue:[newCollection add:each]. |
1 | 1518 |
]. |
1519 |
^ newCollection |
|
68 | 1520 |
|
1521 |
" |
|
1522 |
#(1 2 3 4) select:[:e | e odd] |
|
1523 |
(1 to:10) select:[:e | e even] |
|
1524 |
" |
|
1525 |
! |
|
1526 |
||
1527 |
select:aBlock ifNone:exceptionBlock |
|
1528 |
"try a new collection with all elements from the receiver, for which |
|
1529 |
the argument aBlock evaluates to true. If none of the elements passes |
|
5265 | 1530 |
the check of aBlock, return the result of evaluating exceptionBlock. |
1531 |
See also: #removeAllFoundIn: and #removeAllSuchThat:" |
|
68 | 1532 |
|
1533 |
|newCollection| |
|
1534 |
||
1535 |
newCollection := self select:aBlock. |
|
1536 |
newCollection isEmpty ifTrue:[^ exceptionBlock value]. |
|
1537 |
^ newCollection |
|
1538 |
||
1539 |
" |
|
1540 |
#(1 2 3 4) select:[:e | e > 10] ifNone:['sorry'] |
|
1541 |
" |
|
12 | 1542 |
! |
1543 |
||
4892 | 1544 |
select:selectBlock thenCollect:collectBlock |
1545 |
"combination of select followed by collect. |
|
1546 |
May be redefined by some subclasses for optimal performance |
|
5844 | 1547 |
(avoiding the creation of intermediate garbage)" |
4892 | 1548 |
|
1549 |
^ (self select:selectBlock) collect:collectBlock |
|
1550 |
||
1551 |
" |
|
1552 |
#(1 2 3 4 5 6 7) select:[:i | i even] thenCollect:[:i | i * 2] |
|
1553 |
" |
|
1554 |
! |
|
1555 |
||
362 | 1556 |
triplesDo:aBlock |
1557 |
"evaluate the argument, aBlock for every element in the collection, |
|
1558 |
which is supposed to consist of 3-element collections. |
|
1559 |
The block is called with 3 arguments for each collection in the receiver." |
|
1560 |
||
1561 |
self do:[:aTriple | |
|
2639 | 1562 |
aBlock value:(aTriple at:1) value:(aTriple at:2) value:(aTriple at:3). |
362 | 1563 |
] |
1564 |
" |
|
2639 | 1565 |
#( (1 one eins) (2 two zwei) (3 three drei) (4 four vier) (5 five #'fuenf') (6 six sechs)) |
1422 | 1566 |
triplesDo:[:num :sym1 :sym2 | Transcript show:num; space; show:sym1; space; showCR:sym2] |
362 | 1567 |
" |
2639 | 1568 |
|
1569 |
"Modified: 10.5.1997 / 14:15:43 / cg" |
|
1 | 1570 |
! |
1571 |
||
602 | 1572 |
with:aCollection collect:aTwoArgBlock |
1573 |
"evaluate the argument, aBlock for successive elements from |
|
1574 |
each the receiver and the argument, aSequenceableCollection; |
|
1575 |
The second argument, aBlock must be a two-argument block, which is |
|
1576 |
evaluated for each element-pair. |
|
1577 |
Collect the results and return a collection containing them. |
|
1578 |
This method fails if neither the receiver nor aCollection is |
|
1579 |
a sequenceable collection (i.e. implements numeric key access)." |
|
260 | 1580 |
|
602 | 1581 |
|index "{ Class: SmallInteger }" |
1582 |
newCollection| |
|
1 | 1583 |
|
602 | 1584 |
newCollection := self species new. |
1585 |
index := 1. |
|
1586 |
aCollection isSequenceable ifFalse:[ |
|
1587 |
self isSequenceable ifFalse:[ |
|
1588 |
^ self error:'neither collection is sequenceable'. |
|
1589 |
]. |
|
1590 |
aCollection do:[:element | |
|
1591 |
newCollection add:(aTwoArgBlock value:(self at:index) |
|
1592 |
value:element). |
|
1593 |
index := index + 1 |
|
1594 |
] |
|
1595 |
] ifTrue:[ |
|
1596 |
self do:[:element | |
|
1597 |
newCollection add:(aTwoArgBlock value:element |
|
1598 |
value:(aCollection at:index)). |
|
1599 |
index := index + 1 |
|
1600 |
] |
|
1601 |
]. |
|
1602 |
^ newCollection |
|
201 | 1603 |
|
1604 |
" |
|
602 | 1605 |
(1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)] |
1606 |
#(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)] |
|
201 | 1607 |
" |
2 | 1608 |
! |
1609 |
||
602 | 1610 |
with:aCollection do:aTwoArgBlock |
1611 |
"evaluate the argument, aBlock for successive elements from |
|
1612 |
each the receiver and the argument, aSequenceableCollection. |
|
1613 |
The second argument, aBlock must be a two-argument block. |
|
1614 |
This method fails if neither the receiver nor aCollection is |
|
1615 |
a sequenceable collection (i.e. implements numeric key access)." |
|
1616 |
||
1617 |
|index "{ Class: SmallInteger }"| |
|
2 | 1618 |
|
602 | 1619 |
index := 1. |
1620 |
aCollection isSequenceable ifFalse:[ |
|
1621 |
self isSequenceable ifFalse:[ |
|
1622 |
^ self error:'neither collection is sequenceable'. |
|
1623 |
]. |
|
1624 |
aCollection do:[:element | |
|
1625 |
aTwoArgBlock value:(self at:index) value:element. |
|
1626 |
index := index + 1 |
|
1627 |
] |
|
1628 |
] ifTrue:[ |
|
1629 |
self do:[:element | |
|
1630 |
aTwoArgBlock value:element value:(aCollection at:index). |
|
1631 |
index := index + 1 |
|
1632 |
] |
|
1633 |
] |
|
201 | 1634 |
|
1635 |
" |
|
602 | 1636 |
(1 to:3) with:#(one two three) do:[:num :sym | |
1422 | 1637 |
Transcript showCR:(num->sym) |
602 | 1638 |
] |
1639 |
(1 to:3) with:#(one two three) asSet do:[:num :sym | |
|
1422 | 1640 |
Transcript showCR:(num->sym) |
602 | 1641 |
]. |
1642 |
(1 to:3) asSet with:#(one two three) do:[:num :sym | |
|
1422 | 1643 |
Transcript showCR:(num->sym) |
602 | 1644 |
] |
201 | 1645 |
" |
1 | 1646 |
! ! |
1647 |
||
602 | 1648 |
!Collection methodsFor:'error handling'! |
1649 |
||
1650 |
emptyCheck |
|
1651 |
"check if the receiver is empty; report an error if so" |
|
1652 |
||
1653 |
self size == 0 ifTrue:[ |
|
1654 |
^ self emptyCollectionError. |
|
1655 |
]. |
|
1656 |
! |
|
1657 |
||
1658 |
emptyCollectionError |
|
1659 |
"report an error that the operation is not allowed for |
|
1660 |
empty collections" |
|
1661 |
||
1662 |
^ EmptyCollectionSignal raise |
|
1663 |
! |
|
1664 |
||
1665 |
errorInvalidKey:aKey |
|
1666 |
"report an error that the given key was invalid" |
|
1667 |
||
1668 |
^ InvalidKeySignal raiseRequestWith:aKey |
|
1669 |
! |
|
1670 |
||
1671 |
errorNotKeyed |
|
1672 |
"report an error that keyed access methods are not allowed" |
|
1673 |
||
1674 |
^ self error:(self class name, 's do not respond to keyed accessing messages') |
|
1675 |
! |
|
1676 |
||
1677 |
errorValueNotFound:anObject |
|
1678 |
"report an error that an object was not found in the collection" |
|
1679 |
||
3075 | 1680 |
^ ValueNotFoundSignal |
1681 |
raiseRequestWith:anObject |
|
1682 |
||
1683 |
"Modified: / 30.10.1997 / 15:52:18 / cg" |
|
602 | 1684 |
! |
1685 |
||
1686 |
notEnoughElementsError |
|
1687 |
"report an error that the operation is not allowed, |
|
1688 |
since not enough elements are in the collection" |
|
1689 |
||
1690 |
^ NotEnoughElementsSignal raise |
|
1691 |
! ! |
|
1692 |
||
1693 |
!Collection methodsFor:'growing'! |
|
1694 |
||
1695 |
grow |
|
1696 |
"make the receiver larger" |
|
1697 |
||
1698 |
self grow:(self size + self growSize) |
|
1699 |
! |
|
1700 |
||
1701 |
grow:howBig |
|
1702 |
"change the receivers size" |
|
1703 |
||
1704 |
^ self subclassResponsibility |
|
1705 |
! |
|
1706 |
||
1707 |
growSize |
|
1708 |
"return a suitable size increment for growing. |
|
1709 |
The default returned here may be (and is) redefined in subclasses." |
|
1710 |
||
1711 |
^ self size max:2 |
|
1712 |
! ! |
|
1713 |
||
1 | 1714 |
!Collection methodsFor:'printing & storing'! |
1715 |
||
602 | 1716 |
displayString |
1717 |
"return a printed representation of the receiver for display in inspectors etc." |
|
1718 |
||
1719 |
|thisString buffer count string noneYet total limit| |
|
1720 |
||
1721 |
thisContext isRecursive ifTrue:[ |
|
3191
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1722 |
'Collection [error]: displayString of self referencing collection.' errorPrintCR. |
1413 | 1723 |
^ '#("recursive")' |
602 | 1724 |
]. |
1725 |
||
3964
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1726 |
string := self displayStringName , '('. |
602 | 1727 |
noneYet := true. |
1728 |
buffer := ''. |
|
1729 |
count := 0. |
|
1730 |
total := 0. |
|
1731 |
limit := self maxPrint. |
|
1732 |
||
3191
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1733 |
self printElementsDo: [:element | |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1734 |
thisString := element displayString. |
1413 | 1735 |
noneYet ifTrue:[ |
1736 |
noneYet := false. |
|
1737 |
buffer := buffer , thisString |
|
1738 |
] ifFalse:[ |
|
1739 |
buffer := buffer , (' ' , thisString) |
|
1740 |
]. |
|
1741 |
count := count + 1. |
|
1742 |
(count == 20) ifTrue:[ |
|
1743 |
string := string , buffer. |
|
1744 |
buffer := ''. |
|
1745 |
count := 0 |
|
1746 |
]. |
|
1747 |
total := total + 1. |
|
1748 |
(total > limit) ifTrue:[ |
|
1749 |
string := string , buffer , '... )'. |
|
1750 |
^ string |
|
1751 |
] |
|
602 | 1752 |
]. |
1753 |
string := string , buffer , ')'. |
|
1754 |
^ string |
|
1413 | 1755 |
|
3191
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1756 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1757 |
#(1 2 3 'hello' $a) asOrderedCollection displayString |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1758 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1759 |
(Dictionary new at:#hello put:'world'; |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1760 |
at:#foo put:'bar'; yourself) displayString |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1761 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1762 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1763 |
"Modified: / 20.1.1998 / 14:11:03 / stefan" |
3964
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1764 |
"Modified: / 2.2.1999 / 22:39:44 / cg" |
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1765 |
! |
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1766 |
|
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1767 |
displayStringName |
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1768 |
"redefinable helper for displayString" |
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1769 |
|
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1770 |
^ (self class name) |
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1771 |
|
a3129832fe16
allow redefinition of the displayed class name (displayString)
Claus Gittinger <cg@exept.de>
parents:
3767
diff
changeset
|
1772 |
"Created: / 2.2.1999 / 22:39:33 / cg" |
3191
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1773 |
! |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1774 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1775 |
maxPrint |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1776 |
"the print-limit; printOn: will try to not produce more output |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1777 |
than the limit defined here." |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1778 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1779 |
^ 5000 |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1780 |
! |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1781 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1782 |
printElementsDo:aBlock |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1783 |
"perform aBlock (1 arg) for all elements. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1784 |
Used in #printOn:. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1785 |
Subclasses (e.g. Dictionary) may redefine this." |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1786 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1787 |
^ self do:aBlock |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1788 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1789 |
"Created: / 20.1.1998 / 14:11:02 / stefan" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1790 |
! |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1791 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1792 |
printOn:aStream |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1793 |
"append a user readable representation of the receiver to aStream. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1794 |
The text appended is not meant to be read back for reconstruction of |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1795 |
the receiver. Also, this method limits the size of generated string. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1796 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1797 |
|
3402 | 1798 |
|limit firstOne s| |
3191
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1799 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1800 |
thisContext isRecursive ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1801 |
'Collection [error]: printOn: of self referencing collection.' errorPrintCR. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1802 |
aStream nextPutAll:'#("recursive")'. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1803 |
^ self |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1804 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1805 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1806 |
aStream nextPutAll:self class name. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1807 |
aStream nextPut:$(. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1808 |
firstOne := true. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1809 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1810 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1811 |
if aStream is not positionable, create an temporary positionable stream |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1812 |
(needed for limit calculation) |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1813 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1814 |
aStream isPositionable ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1815 |
s := aStream. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1816 |
] ifFalse:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1817 |
s := WriteStream on:(String new:50). |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1818 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1819 |
limit := s position + self maxPrint. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1820 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1821 |
self printElementsDo:[:element | |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1822 |
firstOne ifFalse:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1823 |
s space |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1824 |
] ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1825 |
firstOne := false |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1826 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1827 |
(s position >= limit) ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1828 |
s ~~ aStream ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1829 |
aStream nextPutAll:(s contents). |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1830 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1831 |
aStream nextPutAll:'...etc...)'. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1832 |
^ self |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1833 |
] ifFalse:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1834 |
element printOn:s. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1835 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1836 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1837 |
s ~~ aStream ifTrue:[ |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1838 |
aStream nextPutAll:(s contents). |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1839 |
]. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1840 |
aStream nextPut:$) |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1841 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1842 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1843 |
#(1 2 3 'hello' $a) printOn:Transcript |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1844 |
(Array new:100000) printOn:Transcript |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1845 |
(Array new:100000) printOn:Stdout |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1846 |
(Array new:100000) printString size |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1847 |
(Dictionary new at:#hello put:'world'; |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1848 |
at:#foo put:'bar'; yourself) printOn:Transcript |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1849 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1850 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1851 |
|a| |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1852 |
a := Array new:3. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1853 |
a at:2 put:a. |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1854 |
a printOn:Transcript |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1855 |
" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1856 |
|
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1857 |
"Modified: / 28.1.1997 / 00:39:17 / cg" |
390764c0d7b3
Make #printOn: more general (and optimal).
Stefan Vogel <sv@exept.de>
parents:
3124
diff
changeset
|
1858 |
"Modified: / 20.1.1998 / 14:11:03 / stefan" |
602 | 1859 |
! |
1860 |
||
1 | 1861 |
storeOn:aStream |
88 | 1862 |
"output a printed representation onto the argument, aStream. |
1863 |
The text can be re-read to reconstruct (a copy of) the receiver. |
|
1864 |
Recursive (i.e. cyclic) collections cannot be stored correctly |
|
1865 |
(use storeBinaryOn: to handle those)." |
|
1 | 1866 |
|
5254 | 1867 |
|notEmpty| |
1 | 1868 |
|
44 | 1869 |
thisContext isRecursive ifTrue:[ |
5498 | 1870 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
2289 | 1871 |
'Collection [error]: storeOn: of self referencing collection.' errorPrintCR. |
1413 | 1872 |
aStream nextPutAll:'#recursive'. |
1873 |
^ self |
|
44 | 1874 |
]. |
1875 |
||
1876 |
aStream nextPutAll:'('. |
|
1 | 1877 |
aStream nextPutAll:(self class name). |
44 | 1878 |
aStream nextPutAll:' new'. |
5254 | 1879 |
notEmpty := false. |
1 | 1880 |
self do:[:element | |
1413 | 1881 |
aStream nextPutAll:' add:'. |
1882 |
element storeOn:aStream. |
|
1883 |
aStream nextPutAll:';'. |
|
5254 | 1884 |
notEmpty := true |
1 | 1885 |
]. |
5254 | 1886 |
notEmpty ifTrue:[aStream nextPutAll:' yourself']. |
1 | 1887 |
aStream nextPut:$) |
44 | 1888 |
|
88 | 1889 |
" |
1890 |
OrderedCollection new storeOn:Transcript |
|
1891 |
(1 to:10) storeOn:Transcript |
|
1892 |
(Set new add:1; add:'hello'; yourself) storeOn:Transcript |
|
1893 |
" |
|
293 | 1894 |
" |
1895 |
|s| |
|
1896 |
||
1897 |
s := Set new. |
|
1898 |
s add:1; add:'hello'; add:s. |
|
1899 |
s storeOn:Transcript |
|
1900 |
" |
|
1413 | 1901 |
|
5254 | 1902 |
"Modified: / 11.2.2000 / 11:24:56 / cg" |
1 | 1903 |
! ! |
602 | 1904 |
|
1905 |
!Collection methodsFor:'queries'! |
|
1906 |
||
5359
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1907 |
defaultElement |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1908 |
^ nil |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1909 |
! |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1910 |
|
602 | 1911 |
isCollection |
1912 |
"return true, if the receiver is some kind of collection; |
|
1913 |
true is returned here - the method is redefined from Object." |
|
1914 |
||
1915 |
^ true |
|
1916 |
! |
|
1917 |
||
1174 | 1918 |
isSorted |
1919 |
"return true, if the receiver is sorted. |
|
1920 |
Collections which hold their elements in sorted order |
|
1921 |
should return true. Some algorithms (quicksort) degenerate when |
|
1922 |
operating on sorted collections and can be avoided if this information |
|
1923 |
is given. The default returned here (false) should not hurt. |
|
1924 |
I.e. you should NEVER depend on that in your application." |
|
1925 |
||
1926 |
^ false |
|
1927 |
||
1928 |
"Created: 13.4.1996 / 12:35:55 / cg" |
|
1929 |
! |
|
1930 |
||
5359
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1931 |
isSortedBy:aBlock |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1932 |
"return true, if my elements are sorted (already) by the given criterion (sortBlock). |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1933 |
Collections which hold their elements in sorted order |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1934 |
should return true. Some algorithms (quicksort) degenerate when |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1935 |
operating on sorted collections and can be avoided if this information |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1936 |
is given. The default returned here (false) should not hurt. |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1937 |
I.e. you should NEVER depend on that in your application." |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1938 |
|
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1939 |
^ false |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1940 |
|
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1941 |
! |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1942 |
|
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1943 |
isSortedCollection |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1944 |
"return true, if the receiver is a sortedCollection." |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1945 |
|
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1946 |
^ false |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1947 |
|
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1948 |
! |
396b77b6f1d2
added #isSortedCollection, #isSortedBy:
Claus Gittinger <cg@exept.de>
parents:
5268
diff
changeset
|
1949 |
|
602 | 1950 |
longestCommonPrefix |
1246 | 1951 |
"return the longest common prefix of my elements. |
1952 |
Typically used with string collections." |
|
1953 |
||
5532 | 1954 |
^ self longestCommonPrefixIgnoreCase:false |
1955 |
||
1956 |
" |
|
1957 |
#('Array' 'ArrayedCollection' 'ArrayOfFoo') longestCommonPrefix |
|
1958 |
#('Arra' 'ArrayedCollection' 'ArrayOfFoo') longestCommonPrefix |
|
1959 |
#('Arra' 'b' 'c') longestCommonPrefix |
|
1960 |
#( (1 2 3 4) (1 2 3) (1 2 3 7) (1 2 3 9 10 11)) longestCommonPrefix |
|
1961 |
" |
|
1962 |
||
1963 |
"Modified: 2.3.1997 / 00:21:41 / cg" |
|
1964 |
! |
|
1965 |
||
1966 |
longestCommonPrefixIgnoreCase:ignoreCase |
|
1967 |
"return the longest common prefix of my elements. |
|
1968 |
Typically used with string collections." |
|
1969 |
||
602 | 1970 |
|try allMatching matchLen| |
1971 |
||
1972 |
" |
|
1973 |
find the longest common prefix |
|
1974 |
" |
|
1975 |
matchLen := 0. |
|
1976 |
self do:[:aName | |
|
1246 | 1977 |
aName size > matchLen ifTrue:[ |
1978 |
matchLen := aName size. |
|
1979 |
try := aName |
|
1980 |
] |
|
602 | 1981 |
]. |
1982 |
||
1983 |
allMatching := true. |
|
1984 |
||
1985 |
[true] whileTrue:[ |
|
1246 | 1986 |
allMatching := true. |
1987 |
self do:[:aName | |
|
5532 | 1988 |
((ignoreCase not and:[aName startsWith:try]) |
1989 |
or:[ignoreCase and:[aName asLowercase startsWith:try asLowercase]]) ifFalse:[ |
|
1246 | 1990 |
allMatching := false |
1991 |
] |
|
1992 |
]. |
|
1993 |
allMatching ifTrue:[ |
|
1994 |
^ try |
|
1995 |
]. |
|
1996 |
matchLen := matchLen - 1. |
|
2434
0a84bd4173c2
longestCommonPrefix - failed if there was no common prefix at all.
Claus Gittinger <cg@exept.de>
parents:
2383
diff
changeset
|
1997 |
matchLen == 0 ifTrue:[^ '']. |
1246 | 1998 |
try := try copyTo:matchLen. |
602 | 1999 |
]. |
2000 |
^ try |
|
2001 |
||
2002 |
" |
|
5532 | 2003 |
#('Array' 'arrayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:true |
2004 |
#('Array' 'arrayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:false |
|
2005 |
#('Array' 'ArayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:false |
|
602 | 2006 |
" |
5557 | 2007 |
! |
2008 |
||
2009 |
size |
|
2010 |
"return the number of elements in the receiver. |
|
2011 |
This is usually redefined in subclasses for more performance." |
|
2012 |
||
2013 |
|count "{ Class: SmallInteger }" | |
|
2014 |
||
2015 |
count := 0. |
|
2016 |
self do:[:element | |
|
2017 |
count := count + 1 |
|
2018 |
]. |
|
2019 |
^ count |
|
602 | 2020 |
! ! |
2021 |
||
2022 |
!Collection methodsFor:'testing'! |
|
2023 |
||
2024 |
capacity |
|
2025 |
"return the number of elements, that the receiver is |
|
2026 |
prepared to take. For most collections, this is the actual |
|
2027 |
size. However, some have more space preallocated to allow |
|
2028 |
for faster adding of elements. |
|
2029 |
Not used by the system; added for ST-80 compatibility." |
|
2030 |
||
2031 |
^ self size |
|
2032 |
! |
|
2033 |
||
2034 |
includes:anElement |
|
2035 |
"return true, if an object equal to the argument, anObject is in the list. |
|
2036 |
This compares using #= (i.e. it does not look for the object itself, |
|
2037 |
instead, one that compares equal). |
|
2038 |
See #includesIdentical: when identity is asked for." |
|
2039 |
||
2040 |
self do:[:element | |
|
2041 |
(anElement = element) ifTrue:[^ true]. |
|
2042 |
]. |
|
2043 |
^ false |
|
2044 |
! |
|
2045 |
||
2046 |
includesAll:aCollection |
|
2047 |
"return true, if the the receiver includes all elements of |
|
2048 |
the argument, aCollection; false if any is missing. |
|
2049 |
Notice: this method has O-square runtime behavior and may be |
|
2050 |
slow for big receivers/args. Think about using a Set, |
|
2051 |
or Dictionary." |
|
2052 |
||
2053 |
aCollection do:[:element | |
|
2054 |
(self includes:element) ifFalse:[^ false]. |
|
2055 |
]. |
|
2056 |
^ true |
|
2057 |
||
2058 |
" |
|
2059 |
#(1 2 3 4 5 6 7) includesAll:#(1 2 3) |
|
2060 |
#('hello' 'there' 'world') includesAll:#('hello' 'world') |
|
2061 |
#(1 2 3 4 5 6 7) includesAll:#(7 8 9) |
|
2062 |
" |
|
2063 |
! |
|
2064 |
||
2065 |
includesAny:aCollection |
|
2066 |
"return true, if the the receiver includes any elements of |
|
2067 |
the argument, aCollection; false if it includes none. |
|
2068 |
Notice: this method has O-square runtime behavior and may be |
|
2069 |
slow for big receivers/args. Think about using a Set, |
|
2070 |
or Dictionary. Speedup is possible, by arrangy highly |
|
2071 |
probable elements towards the beginning of aCollection, |
|
2072 |
to avoid useless searches." |
|
2073 |
||
2074 |
aCollection do:[:element | |
|
2075 |
(self includes:element) ifTrue:[^ true]. |
|
2076 |
]. |
|
2077 |
^ false |
|
2078 |
||
2079 |
" |
|
2080 |
#(1 2 3 4 5 6 7) includesAny:#(1 2 3) |
|
2081 |
#('hello' 'there' 'world') includesAny:#('hello' 'world') |
|
2082 |
#(1 2 3 4 5 6 7) includesAny:#(7 8 9) |
|
2083 |
#(1 2 3 4 5 6 7) includesAny:#(8 9 10) |
|
2084 |
" |
|
2085 |
! |
|
2086 |
||
2087 |
includesIdentical:anElement |
|
2088 |
"return true, if the argument, anObject is in the list. |
|
2089 |
This compares using #== (i.e. object identity). |
|
2090 |
See #includes: when equality is asked for." |
|
2091 |
||
2092 |
self do:[:element | |
|
2093 |
(anElement == element) ifTrue:[^ true]. |
|
2094 |
]. |
|
2095 |
^ false |
|
2096 |
! |
|
2097 |
||
2098 |
isEmpty |
|
2099 |
"return true, if the receiver is empty" |
|
2100 |
||
2101 |
^ self size == 0 |
|
2102 |
! |
|
2103 |
||
2104 |
max |
|
2097 | 2105 |
"return the maximum value in the receiver collection, |
2106 |
using #> to compare elements." |
|
602 | 2107 |
|
2108 |
^ self inject:nil |
|
2097 | 2109 |
into:[:maxSoFar :this | |
2110 |
(maxSoFar isNil |
|
2111 |
or:[this > maxSoFar]) ifTrue:[this] |
|
2112 |
ifFalse:[maxSoFar]] |
|
602 | 2113 |
|
2114 |
" |
|
2115 |
#(15 1 -9 10 5) max |
|
2116 |
(1 to:15) max |
|
2117 |
" |
|
2097 | 2118 |
|
2119 |
"Modified: 8.1.1997 / 22:09:37 / cg" |
|
602 | 2120 |
! |
2121 |
||
2122 |
min |
|
2097 | 2123 |
"return the minimum value in the receiver collection, |
2124 |
using < to compare elements." |
|
602 | 2125 |
|
2126 |
^ self inject:nil |
|
2097 | 2127 |
into:[:minSoFar :this | |
2128 |
(minSoFar isNil |
|
2129 |
or:[this < minSoFar]) ifTrue:[this] |
|
2130 |
ifFalse:[minSoFar]] |
|
602 | 2131 |
|
2132 |
" |
|
2133 |
#(15 1 -9 10 5) min |
|
2134 |
(1 to:15) min |
|
2135 |
" |
|
2097 | 2136 |
|
2137 |
"Modified: 8.1.1997 / 22:09:49 / cg" |
|
602 | 2138 |
! |
2139 |
||
2140 |
notEmpty |
|
2141 |
"return true, if the receiver is not empty" |
|
2142 |
||
2143 |
^ self isEmpty not |
|
2144 |
! |
|
2145 |
||
2146 |
occurrencesOf:anElement |
|
2147 |
"return the number of occurrences of the argument, anElement in |
|
5048 | 2148 |
the receiver. Uses #= (i.e. equality) compare." |
602 | 2149 |
|
2150 |
|count "{ Class: SmallInteger }" | |
|
2151 |
||
2152 |
count := 0. |
|
2153 |
self do:[:element | |
|
5048 | 2154 |
(anElement = element) ifTrue:[ |
2155 |
count := count + 1 |
|
2156 |
]. |
|
602 | 2157 |
]. |
2158 |
^ count |
|
2159 |
! ! |
|
2160 |
||
4680 | 2161 |
!Collection methodsFor:'tracing'! |
2162 |
||
2163 |
traceInto:aRequestor level:level from:referrer |
|
2164 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
2165 |
||
2166 |
^ aRequestor traceCollection:self level:level from:referrer |
|
2167 |
||
2168 |
||
2169 |
! ! |
|
2170 |
||
2097 | 2171 |
!Collection class methodsFor:'documentation'! |
628 | 2172 |
|
2173 |
version |
|
5844 | 2174 |
^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.108 2001-04-13 16:57:35 stefan Exp $' |
628 | 2175 |
! ! |
602 | 2176 |
Collection initialize! |