author | Claus Gittinger <cg@exept.de> |
Sun, 09 Nov 2008 12:26:59 +0100 | |
changeset 2054 | c78f3c579b5e |
parent 2008 | d4ee8f1da6bc |
child 2858 | aeacd9c755ae |
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 |
|
1922
be14f1a04953
#add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents:
1916
diff
changeset
|
109 |
"add the argument, anObject to the end of the collection. |
be14f1a04953
#add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents:
1916
diff
changeset
|
110 |
Return the receiver (sigh - ST-80 compatibility)." |
577 | 111 |
|
1922
be14f1a04953
#add:beforeIndex: - make immune against redefinition of #add: using
Stefan Vogel <sv@exept.de>
parents:
1916
diff
changeset
|
112 |
super add:anObject beforeIndex:index. |
613 | 113 |
dependents notNil ifTrue:[self changed:#insert: with:index]. |
577 | 114 |
! |
115 |
||
116 |
addAll:aCollection beforeIndex:index |
|
117 |
"insert all elements of the argument |
|
118 |
Return the receiver." |
|
119 |
||
610 | 120 |
|count idx| |
577 | 121 |
|
610 | 122 |
count := aCollection size. |
123 |
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
|
124 |
|
577 | 125 |
aCollection isSequenceable ifTrue:[ |
610 | 126 |
"/ we are lucky - that thing can count & do bulk copies |
127 |
"/ notice: the above may change firstIndex |
|
128 |
contentsArray replaceFrom:idx to:(idx + count - 1) with:aCollection startingAt:1. |
|
129 |
] ifFalse:[ |
|
130 |
"/ avoid zillions of change messages ... |
|
131 |
aCollection do:[:element | |
|
132 |
contentsArray at:idx put:element. |
|
133 |
idx := idx + 1. |
|
134 |
]. |
|
135 |
]. |
|
611 | 136 |
dependents notNil ifTrue:[ |
137 |
self changed: #insertCollection: with:(Array with:index with:(aCollection size)) |
|
138 |
] |
|
608
d7a0efe4105f
allow at:put:-ting right after the last element (VW compatbility)
Claus Gittinger <cg@exept.de>
parents:
606
diff
changeset
|
139 |
|
611 | 140 |
"Modified: / 29.1.1998 / 10:52:57 / cg" |
577 | 141 |
! |
142 |
||
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
143 |
addAll:aCollection from:startIndex to:endIndex beforeIndex:index |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
144 |
"insert elements start to stop from the argument |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
145 |
Return the receiver." |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
146 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
147 |
|count idx| |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
148 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
149 |
count := endIndex - startIndex + 1. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
150 |
idx := self makeRoomAtIndex:(index + firstIndex - 1) for:count. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
151 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
152 |
aCollection isSequenceable ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
153 |
"/ we are lucky - that thing can count & do bulk copies |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
154 |
"/ notice: the above may change firstIndex |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
155 |
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
|
156 |
] ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
157 |
self error:'collection must be sequenceable' |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
158 |
]. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
159 |
dependents notNil ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
160 |
self changed: #insertCollection: with:(Array with:index with:count) |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
161 |
] |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
162 |
|
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
163 |
"Modified: / 29.1.1998 / 10:52:57 / cg" |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
164 |
! |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
165 |
|
1142
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
166 |
addAllLast:aCollection |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
167 |
"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
|
168 |
Return the argument, aCollection." |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
169 |
|
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
170 |
self addAll:aCollection beforeIndex:self size + 1. |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
171 |
^ aCollection |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
172 |
! |
8b91f129aea7
addAllLast: - only one change message
Claus Gittinger <cg@exept.de>
parents:
1095
diff
changeset
|
173 |
|
577 | 174 |
addFirst:anObject |
175 |
"add the argument, anObject to the beginning of the collection. |
|
176 |
Return the argument, anObject." |
|
177 |
||
178 |
super addFirst:anObject. |
|
611 | 179 |
dependents notNil ifTrue:[self changed:#insert: with:1]. |
577 | 180 |
^ anObject |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
181 |
|
611 | 182 |
"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
|
183 |
! |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
184 |
|
632 | 185 |
clearContents |
186 |
"remove all elements from the collection but keep the contentsArray. |
|
187 |
Useful for huge lists, if the contents will be rebuild soon (using #add:) |
|
188 |
to a size which is similar to the lists current size. |
|
189 |
Returns the receiver." |
|
190 |
||
191 |
|prevSize| |
|
192 |
||
193 |
prevSize := self size. |
|
194 |
super clearContents. |
|
195 |
||
196 |
prevSize ~~ 0 ifTrue:[ |
|
197 |
dependents notNil ifTrue:[ |
|
198 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
199 |
] |
|
200 |
] |
|
201 |
! |
|
202 |
||
577 | 203 |
removeAll |
204 |
"remove all elements from the collection. |
|
205 |
Returns the receiver." |
|
206 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
207 |
|prevSize| |
577 | 208 |
|
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
209 |
prevSize := self size. |
577 | 210 |
super removeAll. |
211 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
212 |
prevSize ~~ 0 ifTrue:[ |
611 | 213 |
dependents notNil ifTrue:[ |
214 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
215 |
] |
|
577 | 216 |
] |
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
217 |
|
611 | 218 |
"Modified: / 29.1.1998 / 10:53:28 / cg" |
577 | 219 |
! |
220 |
||
221 |
removeFirst |
|
222 |
"remove the first element from the collection; return the element." |
|
223 |
||
224 |
|deletedObject| |
|
225 |
||
226 |
deletedObject := super removeFirst. |
|
611 | 227 |
dependents notNil ifTrue:[self changed:#remove: with:1]. |
577 | 228 |
^ deletedObject |
229 |
||
611 | 230 |
"Modified: / 29.1.1998 / 10:53:36 / cg" |
577 | 231 |
! |
232 |
||
233 |
removeFirst:n |
|
234 |
"remove the first n elements from the collection; |
|
235 |
Return a collection containing the removed elements." |
|
236 |
||
237 |
|deletedObjects| |
|
238 |
||
606
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
239 |
deletedObjects := super removeFirst:n. |
611 | 240 |
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
|
241 |
^ deletedObjects |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
242 |
|
611 | 243 |
"Modified: / 29.1.1998 / 10:53:40 / cg" |
577 | 244 |
! |
245 |
||
1095 | 246 |
removeFirstIfAbsent:exceptionBlock |
247 |
"remove the first element from the collection; return the element. |
|
248 |
If there is no element in the receiver collection, return the value from |
|
249 |
exceptionBlock." |
|
250 |
||
251 |
self size > 0 ifTrue:[ ^ self removeFirst ]. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
252 |
^ exceptionBlock value |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
253 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
254 |
"Modified: / 21-10-2006 / 23:03:46 / cg" |
1095 | 255 |
! |
256 |
||
577 | 257 |
removeFromIndex:startIndex toIndex:stopIndex |
258 |
"remove the elements stored under startIndex up to and including |
|
742 | 259 |
the elements under stopIndex. |
260 |
Return the receiver. |
|
261 |
Returning the receiver here is a historic leftover - it may change." |
|
577 | 262 |
|
742 | 263 |
|ret| |
577 | 264 |
|
2004
e9ee1c2930b0
dont send out change-notifications, if there was no change
ab
parents:
1922
diff
changeset
|
265 |
stopIndex < startIndex ifTrue:[^ self]. |
e9ee1c2930b0
dont send out change-notifications, if there was no change
ab
parents:
1922
diff
changeset
|
266 |
|
742 | 267 |
ret := super removeFromIndex:startIndex toIndex:stopIndex. |
611 | 268 |
dependents notNil ifTrue:[ |
742 | 269 |
self changed:#removeFrom: with:(Array with:startIndex with:stopIndex). |
611 | 270 |
]. |
742 | 271 |
^ ret |
577 | 272 |
|
611 | 273 |
"Modified: / 29.1.1998 / 10:54:03 / cg" |
577 | 274 |
! |
275 |
||
1095 | 276 |
removeIdentical:anObject ifAbsent:exceptionBlock |
277 |
"remove the first element which is identical to anObject; |
|
278 |
if found, remove and return it; |
|
279 |
if not, return the value from evaluating exceptionBlock. |
|
280 |
Uses identity compare (==) to search for the element." |
|
281 |
||
282 |
|index| |
|
283 |
||
284 |
index := self identityIndexOf:anObject. |
|
285 |
||
286 |
index == 0 ifTrue:[ ^ exceptionBlock value ]. |
|
287 |
self removeFromIndex:index toIndex:index. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
288 |
^ anObject |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
289 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
290 |
"Modified: / 21-10-2006 / 23:03:29 / cg" |
1095 | 291 |
! |
292 |
||
577 | 293 |
removeLast |
294 |
"remove the last element from the collection; return the element" |
|
295 |
||
296 |
|deletedObject| |
|
297 |
||
298 |
deletedObject := super removeLast. |
|
611 | 299 |
dependents notNil ifTrue:[self changed:#remove: with:(1 + self size)]. |
577 | 300 |
^ deletedObject |
301 |
||
611 | 302 |
"Modified: / 29.1.1998 / 10:54:15 / cg" |
577 | 303 |
! |
304 |
||
305 |
removeLast:n |
|
2054 | 306 |
"remove the last n elements from the receiver collection. |
307 |
Return a collection of removed elements." |
|
577 | 308 |
|
309 |
|deletedObjects stop| |
|
310 |
||
311 |
stop := self size. |
|
312 |
deletedObjects := super removeLast:n. |
|
611 | 313 |
dependents notNil ifTrue:[ |
314 |
self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop). |
|
315 |
]. |
|
577 | 316 |
^ deletedObjects |
317 |
||
611 | 318 |
"Modified: / 29.1.1998 / 10:54:25 / cg" |
1095 | 319 |
! |
320 |
||
321 |
removeLastIfAbsent:exceptionBlock |
|
322 |
"remove the last element from the collection; return the element. |
|
323 |
If there is no element in the receiver collection, return the value from |
|
324 |
exceptionBlock." |
|
325 |
||
326 |
self size > 0 ifTrue:[ ^ self removeLast ]. |
|
1778
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
327 |
^ exceptionBlock value |
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
328 |
|
1fc313500385
ca's ugly indentation removed
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
329 |
"Modified: / 21-10-2006 / 23:03:53 / cg" |
1095 | 330 |
! |
331 |
||
332 |
reset |
|
333 |
"logically remove all elements from the collection. |
|
334 |
Thats almost the same as #removeAll, but keeps the contentsArray. |
|
335 |
Returns the receiver." |
|
336 |
||
337 |
|prevSize| |
|
338 |
||
339 |
prevSize := self size. |
|
340 |
super reset. |
|
341 |
||
342 |
prevSize ~~ 0 ifTrue:[ |
|
343 |
dependents notNil ifTrue:[ |
|
344 |
self changed:#removeFrom: with:(Array with:1 with:prevSize) |
|
345 |
] |
|
346 |
]. |
|
577 | 347 |
! ! |
348 |
||
349 |
!List methodsFor:'converting'! |
|
350 |
||
351 |
asList |
|
352 |
^ self |
|
353 |
||
354 |
"Created: 14.2.1997 / 16:25:55 / cg" |
|
355 |
! ! |
|
356 |
||
810
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
357 |
!List methodsFor:'copying'! |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
358 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
359 |
skipInstvarIndexInDeepCopy:index |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
360 |
"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
|
361 |
false are copied in a deep copy." |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
362 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
363 |
index == 4 ifTrue:[ |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
364 |
^ true "/ skip dependents |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
365 |
]. |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
366 |
^ false |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
367 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
368 |
|
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
369 |
! ! |
b27913d14137
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
742
diff
changeset
|
370 |
|
577 | 371 |
!List methodsFor:'dependents access'! |
372 |
||
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
373 |
addDependent:anObject |
1615 | 374 |
"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
|
375 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
376 |
^ self addNonWeakDependent:anObject |
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
377 |
! |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
378 |
|
480 | 379 |
dependents |
380 |
"return the dependents of the receiver" |
|
381 |
||
584
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
382 |
^ dependents ? #() |
480 | 383 |
|
584
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
384 |
"Created: / 14.2.1997 / 16:05:49 / cg" |
319da69edba2
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
577
diff
changeset
|
385 |
"Modified: / 27.10.1997 / 19:37:33 / cg" |
480 | 386 |
! |
387 |
||
388 |
dependents:aCollection |
|
389 |
"set the dependents of the receiver" |
|
390 |
||
611 | 391 |
aCollection size == 0 ifTrue:[ |
392 |
dependents := nil |
|
393 |
] ifFalse:[ |
|
394 |
dependents := aCollection. |
|
395 |
]. |
|
480 | 396 |
|
611 | 397 |
"Created: / 14.2.1997 / 16:05:58 / cg" |
398 |
"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
|
399 |
! |
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
400 |
|
4419919ae433
shortCut change-messages if there are no dependents
Claus Gittinger <cg@exept.de>
parents:
584
diff
changeset
|
401 |
nonWeakDependents |
612
cc2d6bd50cdc
#nonWeakDependents always returns a collection.
Claus Gittinger <cg@exept.de>
parents:
611
diff
changeset
|
402 |
"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
|
403 |
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
|
404 |
|
1604 | 405 |
^ dependents ? #() |
673 | 406 |
! |
407 |
||
408 |
nonWeakDependents:newDeps |
|
409 |
"return a Collection of dependents - empty if there is none. |
|
410 |
Since all dependencies are nonWeak in List, this is a dummy." |
|
411 |
||
412 |
^ self dependents:newDeps |
|
413 |
||
414 |
"Created: / 19.4.1996 / 10:29:43 / cg" |
|
415 |
"Modified: / 30.1.1998 / 14:06:12 / cg" |
|
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
416 |
! |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
417 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
418 |
removeDependent:anObject |
1090
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
419 |
"make the argument, anObject be independent of the receiver. |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
420 |
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
|
421 |
forwarded to removeDependent:" |
979886a925c8
nonWeak dependents fix (aka: kludge)
Claus Gittinger <cg@exept.de>
parents:
1033
diff
changeset
|
422 |
|
1638
4ca339939383
dependents vs. weakDependents
Claus Gittinger <cg@exept.de>
parents:
1615
diff
changeset
|
423 |
^ self removeNonWeakDependent:anObject |
480 | 424 |
! ! |
425 |
||
577 | 426 |
!List methodsFor:'filling & replacing'! |
427 |
||
908 | 428 |
contents:aCollection |
429 |
"replace all elements in the receiver by aCollection, |
|
430 |
Redefined - can be done faster" |
|
431 |
||
432 |
|oldSize newSize| |
|
433 |
||
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
434 |
aCollection isSequenceable ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
435 |
^ super contents:aCollection |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
436 |
]. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
437 |
|
908 | 438 |
oldSize := self size. |
439 |
newSize := aCollection size. |
|
440 |
||
441 |
newSize < oldSize ifTrue:[ |
|
442 |
self replaceFrom:1 to:newSize with:aCollection startingAt:1. |
|
443 |
self removeFromIndex:newSize+1 toIndex:oldSize. |
|
444 |
] ifFalse:[ |
|
445 |
newSize > oldSize ifTrue:[ |
|
909
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
446 |
oldSize == 0 ifTrue:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
447 |
self addAll:aCollection |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
448 |
] ifFalse:[ |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
449 |
self replaceFrom:1 to:oldSize with:aCollection startingAt:1. |
c4f759a283cf
fixed #contents: (empty case)
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
450 |
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
|
451 |
] |
908 | 452 |
] ifFalse:[ |
1567 | 453 |
"/ same size |
454 |
oldSize ~~ 0 ifTrue:[ |
|
455 |
self replaceFrom:1 to:newSize with:aCollection startingAt:1. |
|
456 |
] |
|
908 | 457 |
] |
458 |
]. |
|
459 |
||
460 |
" |
|
461 |
|l| |
|
462 |
l := List new. |
|
463 |
l contents:#(1 2 3 4 5). |
|
464 |
l |
|
465 |
||
466 |
|l| |
|
467 |
l := List new. |
|
468 |
l addAll:#(1 2 3 4 5). |
|
469 |
l contents:#(10 20 30). |
|
470 |
l |
|
471 |
||
472 |
|l| |
|
473 |
l := List new. |
|
474 |
l addAll:#(1 2 3 4 5). |
|
475 |
l contents:#(10 20 30 40 50 60 70 80). |
|
476 |
l |
|
477 |
||
478 |
|l| |
|
479 |
l := List new. |
|
480 |
l addAll:#(1 2 3 4 5). |
|
481 |
l contents:#(10 20 30 40 50). |
|
482 |
l |
|
483 |
" |
|
484 |
! |
|
485 |
||
1033 | 486 |
list:aCollection |
487 |
"replace all elements in the receiver by aCollection. |
|
488 |
For compatibility with other smalltalks |
|
489 |
(allows List to be sometimes used as a ListPresenter in ported Dolphin apps)" |
|
490 |
||
491 |
self contents:aCollection |
|
492 |
||
493 |
" |
|
494 |
|l| |
|
495 |
l := List new. |
|
496 |
l list:#(1 2 3 4 5). |
|
497 |
l |
|
498 |
||
499 |
|l| |
|
500 |
l := List new. |
|
501 |
l addAll:#(1 2 3 4 5). |
|
502 |
l list:#(10 20 30). |
|
503 |
l |
|
504 |
||
505 |
|l| |
|
506 |
l := List new. |
|
507 |
l addAll:#(1 2 3 4 5). |
|
508 |
l list:#(10 20 30 40 50 60 70 80). |
|
509 |
l |
|
510 |
||
511 |
|l| |
|
512 |
l := List new. |
|
513 |
l addAll:#(1 2 3 4 5). |
|
514 |
l list:#(10 20 30 40 50). |
|
515 |
l |
|
516 |
" |
|
517 |
! |
|
518 |
||
577 | 519 |
replaceFrom:start to:stop with:aCollection startingAt:repStart |
520 |
"replace elements in the receiver between index start and stop, |
|
521 |
with elements taken from replacementCollection starting at repStart. |
|
522 |
Redefined - can be done faster" |
|
481 | 523 |
|
2008
d4ee8f1da6bc
changed #replaceFrom:to:with:startingAt:
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
524 |
stop < start ifTrue:[^ self]. |
2004
e9ee1c2930b0
dont send out change-notifications, if there was no change
ab
parents:
1922
diff
changeset
|
525 |
|
646 | 526 |
super replaceFrom:start to:stop with:aCollection startingAt:repStart. |
481 | 527 |
|
577 | 528 |
dependents notNil ifTrue:[ |
529 |
self changed:#replace: with:(Array with:start with:stop) |
|
530 |
]. |
|
531 |
||
646 | 532 |
"Modified: / 20.5.1998 / 15:20:17 / cg" |
481 | 533 |
! ! |
534 |
||
881 | 535 |
!List methodsFor:'testing'! |
536 |
||
537 |
isList |
|
538 |
"return true, if the receiver is some kind of list collection; |
|
539 |
true is returned here - the method is redefined from Object." |
|
540 |
||
541 |
^ true |
|
542 |
||
543 |
"Modified: / 11.2.2000 / 01:37:36 / cg" |
|
544 |
! ! |
|
545 |
||
480 | 546 |
!List class methodsFor:'documentation'! |
547 |
||
548 |
version |
|
2054 | 549 |
^ '$Header: /cvs/stx/stx/libbasic2/List.st,v 1.33 2008-11-09 11:26:59 cg Exp $' |
480 | 550 |
! ! |