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