author | Stefan Vogel <sv@exept.de> |
Wed, 21 Nov 2007 18:24:07 +0100 | |
changeset 1917 | 61c602336f3d |
parent 1916 | 9815828d0bf8 |
child 1922 | be14f1a04953 |
permissions | -rw-r--r-- |
480 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
908 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
480 | 14 |
OrderedCollection subclass:#List |
15 |
instanceVariableNames:'dependents' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Sequenceable' |
|
19 |
! |
|
20 |
||
21 |
!List class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1996 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
737 | 40 |
Lists are mostly like OrderedCollections, but keep their dependents |
480 | 41 |
locally (which is adding a bit of performance - not functionality). |
737 | 42 |
In addition, special change notifications are emitted, whenever |
43 |
a lists contents is changed. |
|
44 |
Some views (SelectionIn*View and DataSetView) react specially on |
|
45 |
on those messages and perform optimized updates. |
|
46 |
(the change messages pass the range-of-change as parameter). |
|
480 | 47 |
|
48 |
In ST/X, most functionality is already provided by OrderedCollection, |
|
49 |
so there is not much new stuff found here. |
|
50 |
It has been mostly provided, for ST-80 compatibility, |
|
51 |
where it adds sorting capabilities. |
|
52 |
||
53 |
[see also:] |
|
54 |
Array OrderedCollection |
|
55 |
||
56 |
[author:] |
|
57 |
Claus Gittinger |
|
58 |
" |
|
59 |
||
60 |
! ! |
|
61 |
||
62 |
!List methodsFor:'accessing'! |
|
63 |
||
577 | 64 |
at:anIndex put:anObject |
65 |
"set the element at index, to be anIndex. |
|
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
66 |
Return anObject (sigh). |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
67 |
In contrast to OrderedCollection, Lists allow putting an object |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
68 |
right after the last element and auto-grow in this case; |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
69 |
however, putting 2 or more indices after the last element is |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
70 |
reported as an error." |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
71 |
|
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
72 |
|idx "{ Class: SmallInteger }"| |
577 | 73 |
|
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
74 |
idx := anIndex + firstIndex - 1. |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
75 |
((anIndex < 1) or:[idx > lastIndex]) ifTrue:[ |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
76 |
idx == (lastIndex+1) ifTrue:[ |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
77 |
self makeRoomAtLast. |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
78 |
lastIndex := lastIndex + 1. |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
79 |
] ifFalse:[ |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
80 |
^ self subscriptBoundsError:anIndex |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
81 |
] |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
82 |
]. |
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
83 |
|
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
84 |
contentsArray basicAt:idx put:anObject. |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
85 |
dependents size ~~ 0 ifTrue:[self changed:#at: with:anIndex]. |
577 | 86 |
^ anObject |
87 |
||
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
88 |
"Modified: / 28.1.1998 / 16:44:49 / cg" |
577 | 89 |
! |
90 |
||
91 |
list |
|
92 |
^ self |
|
93 |
! ! |
|
94 |
||
95 |
!List methodsFor:'adding & removing'! |
|
96 |
||
97 |
add:anObject |
|
98 |
"add the argument, anObject to the end of the collection |
|
99 |
Return the argument, anObject." |
|
100 |
||
101 |
super add:anObject. |
|
611 | 102 |
dependents notNil ifTrue:[self changed:#insert: with:(self size)]. |
577 | 103 |
^ anObject |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
104 |
|
611 | 105 |
"Modified: / 29.1.1998 / 10:52:32 / cg" |
577 | 106 |
! |
107 |
||
108 |
add:anObject beforeIndex:index |
|
610 | 109 |
"add the argument, anObject to the end of the collection |
110 |
Return the argument, anObject." |
|
111 |
||
112 |
|idx physicalIndex| |
|
577 | 113 |
|
610 | 114 |
physicalIndex := index + firstIndex - 1. |
115 |
physicalIndex > lastIndex ifTrue:[ |
|
116 |
physicalIndex == (lastIndex+1) ifTrue:[ |
|
117 |
self addLast:anObject. |
|
118 |
^ self |
|
119 |
]. |
|
120 |
^ self subscriptBoundsError:index |
|
121 |
]. |
|
577 | 122 |
|
610 | 123 |
idx := self makeRoomAtIndex:physicalIndex. |
124 |
"/ notice: the above may change firstIndex |
|
125 |
contentsArray basicAt:idx put:anObject. |
|
126 |
||
613 | 127 |
dependents notNil ifTrue:[self changed:#insert: with:index]. |
610 | 128 |
^ anObject |
129 |
||
613 | 130 |
"Modified: / 2.2.1998 / 19:06:21 / cg" |
577 | 131 |
! |
132 |
||
133 |
addAll:aCollection beforeIndex:index |
|
134 |
"insert all elements of the argument |
|
135 |
Return the receiver." |
|
136 |
||
610 | 137 |
|count idx| |
577 | 138 |
|
610 | 139 |
count := aCollection size. |
140 |
idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. |
|
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
141 |
|
577 | 142 |
aCollection isSequenceable ifTrue:[ |
610 | 143 |
"/ we are lucky - that thing can count & do bulk copies |
144 |
"/ notice: the above may change firstIndex |
|
145 |
contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1. |
|
146 |
] ifFalse:[ |
|
147 |
"/ avoid zillions of change messages ... |
|
148 |
aCollection do:[:element | |
|
149 |
contentsArray at:idx put:element. |
|
150 |
idx := idx + 1. |
|
151 |
]. |
|
152 |
]. |
|
611 | 153 |
dependents notNil ifTrue:[ |
154 |
self changed: #insertCollection: with:(Array with:index with:(aCollection size)) |
|
155 |
] |
|
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
156 |
|
611 | 157 |
"Modified: / 29.1.1998 / 10:52:57 / cg" |
577 | 158 |
! |
159 |
||
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
160 |
addAll:aCollection from:startIndex to:endIndex beforeIndex:index |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
161 |
"insert elements start to stop from the argument |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
162 |
Return the receiver." |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
163 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
164 |
|count idx| |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
165 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
166 |
count := endIndex - startIndex + 1. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
167 |
idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
168 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
169 |
aCollection isSequenceable ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
170 |
"/ we are lucky - that thing can count & do bulk copies |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
171 |
"/ notice: the above may change firstIndex |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
172 |
contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:startIndex. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
173 |
] ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
174 |
self error:'collection must be sequenceable' |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
175 |
]. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
176 |
dependents notNil ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
177 |
self changed: #insertCollection: with:(Array with:index with:count) |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
178 |
] |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
179 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
180 |
"Modified: / 29.1.1998 / 10:52:57 / cg" |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
181 |
! |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
182 |
|
1142
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
183 |
addAllLast:aCollection |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
184 |
"add all elements of the argument, aCollection to the end of the collection. |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
185 |
Return the argument, aCollection." |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
186 |
|
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
187 |
self addAll:aCollection beforeIndex:self size + 1. |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
188 |
^ aCollection |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
189 |
! |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
190 |
|
577 | 191 |
addFirst:anObject |
192 |
"add the argument, anObject to the beginning of the collection. |
|
193 |
Return the argument, anObject." |
|
194 |
||
195 |
super addFirst:anObject. |
|
611 | 196 |
dependents notNil ifTrue:[self changed:#insert: with:1]. |
577 | 197 |
^ anObject |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
198 |
|
611 | 199 |
"Modified: / 29.1.1998 / 10:53:09 / cg" |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
200 |
! |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
201 |
|
632 | 202 |
clearContents |
203 |
"remove all elements from the collection but keep the contentsArray. |
|
204 |
Useful for huge lists, if the contents will be rebuild soon (using #add:) |
|
205 |
to a size which is similar to the lists current size. |
|
206 |
Returns the receiver." |
|
207 |
||
208 |
|prevSize| |
|
209 |
||
210 |
prevSize := self size. |
|
211 |
super clearContents. |
|
212 |
||
213 |
prevSize ~~ 0 ifTrue:[ |
|
214 |
dependents notNil ifTrue:[ |
|
215 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
216 |
] |
|
217 |
] |
|
218 |
! |
|
219 |
||
577 | 220 |
removeAll |
221 |
"remove all elements from the collection. |
|
222 |
Returns the receiver." |
|
223 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
224 |
|prevSize| |
577 | 225 |
|
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
226 |
prevSize := self size. |
577 | 227 |
super removeAll. |
228 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
229 |
prevSize ~~ 0 ifTrue:[ |
611 | 230 |
dependents notNil ifTrue:[ |
231 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
232 |
] |
|
577 | 233 |
] |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
234 |
|
611 | 235 |
"Modified: / 29.1.1998 / 10:53:28 / cg" |
577 | 236 |
! |
237 |
||
238 |
removeFirst |
|
239 |
"remove the first element from the collection; return the element." |
|
240 |
||
241 |
|deletedObject| |
|
242 |
||
243 |
deletedObject := super removeFirst. |
|
611 | 244 |
dependents notNil ifTrue:[self changed:#remove: with:1]. |
577 | 245 |
^ deletedObject |
246 |
||
611 | 247 |
"Modified: / 29.1.1998 / 10:53:36 / cg" |
577 | 248 |
! |
249 |
||
250 |
removeFirst:n |
|
251 |
"remove the first n elements from the collection; |
|
252 |
Return a collection containing the removed elements." |
|
253 |
||
254 |
|deletedObjects| |
|
255 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
256 |
deletedObjects := super removeFirst:n. |
611 | 257 |
dependents notNil ifTrue:[self changed:#removeFrom: with:(Array with:1 with:n)]. |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
258 |
^ deletedObjects |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
259 |
|
611 | 260 |
"Modified: / 29.1.1998 / 10:53:40 / cg" |
577 | 261 |
! |
262 |
||
1095 | 263 |
removeFirstIfAbsent:exceptionBlock |
264 |
"remove the first element from the collection; return the element. |
|
265 |
If there is no element in the receiver collection, return the value from |
|
266 |
exceptionBlock." |
|
267 |
||
268 |
self size > 0 ifTrue:[ ^ self removeFirst ]. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
269 |
^ exceptionBlock value |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
270 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
271 |
"Modified: / 21-10-2006 / 23:03:46 / cg" |
1095 | 272 |
! |
273 |
||
577 | 274 |
removeFromIndex:startIndex toIndex:stopIndex |
275 |
"remove the elements stored under startIndex up to and including |
|
742 | 276 |
the elements under stopIndex. |
277 |
Return the receiver. |
|
278 |
Returning the receiver here is a historic leftover - it may change." |
|
577 | 279 |
|
742 | 280 |
|ret| |
577 | 281 |
|
742 | 282 |
ret := super removeFromIndex:startIndex toIndex:stopIndex. |
611 | 283 |
dependents notNil ifTrue:[ |
742 | 284 |
self changed:#removeFrom: with:(Array with:startIndex with:stopIndex). |
611 | 285 |
]. |
742 | 286 |
^ ret |
577 | 287 |
|
611 | 288 |
"Modified: / 29.1.1998 / 10:54:03 / cg" |
577 | 289 |
! |
290 |
||
1095 | 291 |
removeIdentical:anObject ifAbsent:exceptionBlock |
292 |
"remove the first element which is identical to anObject; |
|
293 |
if found, remove and return it; |
|
294 |
if not, return the value from evaluating exceptionBlock. |
|
295 |
Uses identity compare (==) to search for the element." |
|
296 |
||
297 |
|index| |
|
298 |
||
299 |
index := self identityIndexOf:anObject. |
|
300 |
||
301 |
index == 0 ifTrue:[ ^ exceptionBlock value ]. |
|
302 |
self removeFromIndex:index toIndex:index. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
303 |
^ anObject |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
304 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
305 |
"Modified: / 21-10-2006 / 23:03:29 / cg" |
1095 | 306 |
! |
307 |
||
577 | 308 |
removeLast |
309 |
"remove the last element from the collection; return the element" |
|
310 |
||
311 |
|deletedObject| |
|
312 |
||
313 |
deletedObject := super removeLast. |
|
611 | 314 |
dependents notNil ifTrue:[self changed:#remove: with:(1 + self size)]. |
577 | 315 |
^ deletedObject |
316 |
||
611 | 317 |
"Modified: / 29.1.1998 / 10:54:15 / cg" |
577 | 318 |
! |
319 |
||
320 |
removeLast:n |
|
321 |
"remove the last n elements from the collection; |
|
322 |
Return a collection of removed elements." |
|
323 |
||
324 |
|deletedObjects stop| |
|
325 |
||
326 |
stop := self size. |
|
327 |
deletedObjects := super removeLast:n. |
|
611 | 328 |
dependents notNil ifTrue:[ |
329 |
self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop). |
|
330 |
]. |
|
577 | 331 |
^ deletedObjects |
332 |
||
611 | 333 |
"Modified: / 29.1.1998 / 10:54:25 / cg" |
1095 | 334 |
! |
335 |
||
336 |
removeLastIfAbsent:exceptionBlock |
|
337 |
"remove the last element from the collection; return the element. |
|
338 |
If there is no element in the receiver collection, return the value from |
|
339 |
exceptionBlock." |
|
340 |
||
341 |
self size > 0 ifTrue:[ ^ self removeLast ]. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
342 |
^ exceptionBlock value |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
343 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
344 |
"Modified: / 21-10-2006 / 23:03:53 / cg" |
1095 | 345 |
! |
346 |
||
347 |
reset |
|
348 |
"logically remove all elements from the collection. |
|
349 |
Thats almost the same as #removeAll, but keeps the contentsArray. |
|
350 |
Returns the receiver." |
|
351 |
||
352 |
|prevSize| |
|
353 |
||
354 |
prevSize := self size. |
|
355 |
super reset. |
|
356 |
||
357 |
prevSize ~~ 0 ifTrue:[ |
|
358 |
dependents notNil ifTrue:[ |
|
359 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
360 |
] |
|
361 |
]. |
|
577 | 362 |
! ! |
363 |
||
364 |
!List methodsFor:'converting'! |
|
365 |
||
366 |
asList |
|
367 |
^ self |
|
368 |
||
369 |
"Created: 14.2.1997 / 16:25:55 / cg" |
|
370 |
! ! |
|
371 |
||
810
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
372 |
!List methodsFor:'copying'! |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
373 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
374 |
skipInstvarIndexInDeepCopy:index |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
375 |
"a helper for deepCopy; only indices for which this method returns |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
376 |
false are copied in a deep copy." |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
377 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
378 |
index == 4 ifTrue:[ |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
379 |
^ true "/ skip dependents |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
380 |
]. |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
381 |
^ false |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
382 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
383 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
384 |
! ! |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
385 |
|
577 | 386 |
!List methodsFor:'dependents access'! |
387 |
||
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
388 |
addDependent:anObject |
1615 | 389 |
"make the argument, anObject be a dependent of the receiver." |
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
390 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
391 |
^ self addNonWeakDependent:anObject |
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
392 |
! |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
393 |
|
480 | 394 |
dependents |
395 |
"return the dependents of the receiver" |
|
396 |
||
584
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
397 |
^ dependents ? #() |
480 | 398 |
|
584
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
399 |
"Created: / 14.2.1997 / 16:05:49 / cg" |
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
400 |
"Modified: / 27.10.1997 / 19:37:33 / cg" |
480 | 401 |
! |
402 |
||
403 |
dependents:aCollection |
|
404 |
"set the dependents of the receiver" |
|
405 |
||
611 | 406 |
aCollection size == 0 ifTrue:[ |
407 |
dependents := nil |
|
408 |
] ifFalse:[ |
|
409 |
dependents := aCollection. |
|
410 |
]. |
|
480 | 411 |
|
611 | 412 |
"Created: / 14.2.1997 / 16:05:58 / cg" |
413 |
"Modified: / 29.1.1998 / 10:54:52 / cg" |
|
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
414 |
! |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
415 |
|
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
416 |
nonWeakDependents |
612
cc2d6bd50cdc
#nonWeakDependents always returns a collection.
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
417 |
"return a Collection of dependents - empty if there is none. |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
418 |
Since all dependencies are nonWeak in List, this is a dummy." |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
419 |
|
1604 | 420 |
^ dependents ? #() |
673 | 421 |
! |
422 |
||
423 |
nonWeakDependents:newDeps |
|
424 |
"return a Collection of dependents - empty if there is none. |
|
425 |
Since all dependencies are nonWeak in List, this is a dummy." |
|
426 |
||
427 |
^ self dependents:newDeps |
|
428 |
||
429 |
"Created: / 19.4.1996 / 10:29:43 / cg" |
|
430 |
"Modified: / 30.1.1998 / 14:06:12 / cg" |
|
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
431 |
! |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
432 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
433 |
removeDependent:anObject |
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
434 |
"make the argument, anObject be independent of the receiver. |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
435 |
Since all dependencies are nonWeak in Model, this is simply |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
436 |
forwarded to removeDependent:" |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
437 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
438 |
^ self removeNonWeakDependent:anObject |
480 | 439 |
! ! |
440 |
||
577 | 441 |
!List methodsFor:'filling & replacing'! |
442 |
||
908 | 443 |
contents:aCollection |
444 |
"replace all elements in the receiver by aCollection, |
|
445 |
Redefined - can be done faster" |
|
446 |
||
447 |
|oldSize newSize| |
|
448 |
||
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
449 |
aCollection isSequenceable ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
450 |
^ super contents:aCollection |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
451 |
]. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
452 |
|
908 | 453 |
oldSize := self size. |
454 |
newSize := aCollection size. |
|
455 |
||
456 |
newSize < oldSize ifTrue:[ |
|
457 |
self replaceFrom:1 to:newSize with:aCollection startingAt:1. |
|
458 |
self removeFromIndex:newSize+1 toIndex:oldSize. |
|
459 |
] ifFalse:[ |
|
460 |
newSize > oldSize ifTrue:[ |
|
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
461 |
oldSize == 0 ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
462 |
self addAll:aCollection |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
463 |
] ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
464 |
self replaceFrom:1 to:oldSize with:aCollection startingAt:1. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
465 |
self addAll:aCollection from:oldSize+1 to:newSize beforeIndex:oldSize+1 |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
466 |
] |
908 | 467 |
] ifFalse:[ |
1567 | 468 |
"/ same size |
469 |
oldSize ~~ 0 ifTrue:[ |
|
470 |
self replaceFrom:1 to:newSize with:aCollection startingAt:1. |
|
471 |
] |
|
908 | 472 |
] |
473 |
]. |
|
474 |
||
475 |
" |
|
476 |
|l| |
|
477 |
l := List new. |
|
478 |
l contents:#(1 2 3 4 5). |
|
479 |
l |
|
480 |
||
481 |
|l| |
|
482 |
l := List new. |
|
483 |
l addAll:#(1 2 3 4 5). |
|
484 |
l contents:#(10 20 30). |
|
485 |
l |
|
486 |
||
487 |
|l| |
|
488 |
l := List new. |
|
489 |
l addAll:#(1 2 3 4 5). |
|
490 |
l contents:#(10 20 30 40 50 60 70 80). |
|
491 |
l |
|
492 |
||
493 |
|l| |
|
494 |
l := List new. |
|
495 |
l addAll:#(1 2 3 4 5). |
|
496 |
l contents:#(10 20 30 40 50). |
|
497 |
l |
|
498 |
" |
|
499 |
! |
|
500 |
||
1033 | 501 |
list:aCollection |
502 |
"replace all elements in the receiver by aCollection. |
|
503 |
For compatibility with other smalltalks |
|
504 |
(allows List to be sometimes used as a ListPresenter in ported Dolphin apps)" |
|
505 |
||
506 |
self contents:aCollection |
|
507 |
||
508 |
" |
|
509 |
|l| |
|
510 |
l := List new. |
|
511 |
l list:#(1 2 3 4 5). |
|
512 |
l |
|
513 |
||
514 |
|l| |
|
515 |
l := List new. |
|
516 |
l addAll:#(1 2 3 4 5). |
|
517 |
l list:#(10 20 30). |
|
518 |
l |
|
519 |
||
520 |
|l| |
|
521 |
l := List new. |
|
522 |
l addAll:#(1 2 3 4 5). |
|
523 |
l list:#(10 20 30 40 50 60 70 80). |
|
524 |
l |
|
525 |
||
526 |
|l| |
|
527 |
l := List new. |
|
528 |
l addAll:#(1 2 3 4 5). |
|
529 |
l list:#(10 20 30 40 50). |
|
530 |
l |
|
531 |
" |
|
532 |
! |
|
533 |
||
577 | 534 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
535 |
"replace elements in the receiver between index start and stop, |
|
536 |
with elements taken from replacementCollection starting at repStart. |
|
537 |
Redefined - can be done faster" |
|
481 | 538 |
|
646 | 539 |
super replaceFrom:start to:stop with:aCollection startingAt:repStart. |
481 | 540 |
|
577 | 541 |
dependents notNil ifTrue:[ |
542 |
self changed:#replace: with:(Array with:start with:stop) |
|
543 |
]. |
|
544 |
||
646 | 545 |
"Modified: / 20.5.1998 / 15:20:17 / cg" |
481 | 546 |
! ! |
547 |
||
881 | 548 |
!List methodsFor:'testing'! |
549 |
||
550 |
isList |
|
551 |
"return true, if the receiver is some kind of list collection; |
|
552 |
true is returned here - the method is redefined from Object." |
|
553 |
||
554 |
^ true |
|
555 |
||
556 |
"Modified: / 11.2.2000 / 01:37:36 / cg" |
|
557 |
! ! |
|
558 |
||
480 | 559 |
!List class methodsFor:'documentation'! |
560 |
||
561 |
version |
|
1916
9815828d0bf8
Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents:
1778
diff
changeset
|
562 |
^ '$Header: /cvs/stx/stx/libbasic2/List.st,v 1.29 2007-11-21 17:24:03 stefan Exp $' |
480 | 563 |
! ! |