4331
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2016 by Claus Gittinger / 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 |
"
|
3690
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
AutoResizingOrderedCollection subclass:#AutoResizingOrderedCollectionWithDefault
|
|
17 |
instanceVariableNames:'defaultValue'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Collections-Sequenceable'
|
|
21 |
!
|
|
22 |
|
|
23 |
!AutoResizingOrderedCollectionWithDefault class methodsFor:'documentation'!
|
|
24 |
|
4331
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2016 by Claus Gittinger / 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 |
|
3690
|
39 |
documentation
|
|
40 |
"
|
|
41 |
I am an ordered collection which automatically resizes if elements
|
|
42 |
are added beyond the size.
|
4136
|
43 |
I.e. if #at:put: is sent for indexes > the current size, the receiver grows to
|
3690
|
44 |
the required index and missing fields are implicitly filled with a default value.
|
|
45 |
Queries for non-existing elements are anwered with the default value.
|
4136
|
46 |
|
|
47 |
[see also:]
|
|
48 |
OrderedCollection
|
|
49 |
Array
|
|
50 |
SparseArray
|
3690
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
examples
|
|
55 |
"
|
|
56 |
|coll|
|
|
57 |
|
|
58 |
coll := AutoResizingOrderedCollectionWithDefault newWithDefaultValue:99.
|
|
59 |
coll at:4 put:'four'.
|
|
60 |
coll at:8 put:'eight'.
|
|
61 |
coll at:9
|
|
62 |
"
|
|
63 |
! !
|
|
64 |
|
|
65 |
!AutoResizingOrderedCollectionWithDefault methodsFor:'accessing'!
|
|
66 |
|
|
67 |
at:index
|
|
68 |
"fetch an object at index.
|
|
69 |
If index is beyond the actual size, return the default value
|
|
70 |
(i.e. this is an alias for at:index ifAbsent:[default value])"
|
|
71 |
|
|
72 |
index > self size ifTrue:[^ defaultValue].
|
|
73 |
^ super at:index
|
|
74 |
!
|
|
75 |
|
|
76 |
at:index put:anObject
|
|
77 |
"store an object at index.
|
|
78 |
If required, grow the receiver to ensure that index is valid"
|
|
79 |
|
|
80 |
|oldSize|
|
|
81 |
|
|
82 |
index > (oldSize := self size) ifTrue:[
|
|
83 |
self grow:index.
|
|
84 |
self from:oldSize+1 to:index put:defaultValue.
|
|
85 |
].
|
|
86 |
super at:index put:anObject
|
|
87 |
! !
|
|
88 |
|
|
89 |
!AutoResizingOrderedCollectionWithDefault methodsFor:'initialization'!
|
|
90 |
|
|
91 |
setDefaultValue:v
|
|
92 |
defaultValue := v
|
|
93 |
! !
|
|
94 |
|
|
95 |
!AutoResizingOrderedCollectionWithDefault class methodsFor:'documentation'!
|
|
96 |
|
|
97 |
version
|
|
98 |
^ '$Header$'
|
|
99 |
!
|
|
100 |
|
|
101 |
version_CVS
|
|
102 |
^ '$Header$'
|
|
103 |
! !
|
|
104 |
|