1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
48
|
3 |
All Rights Reserved
|
1
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
19
|
13 |
Collection subclass:#MappedCollection
|
1
|
14 |
instanceVariableNames:'domain map'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
42
|
17 |
category:'Collections-Sequenceable'
|
1
|
18 |
!
|
|
19 |
|
|
20 |
MappedCollection comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
48
|
22 |
All Rights Reserved
|
36
|
23 |
|
84
|
24 |
$Header: /cvs/stx/stx/libbasic2/MappedCollection.st,v 1.10 1995-08-10 13:18:08 claus Exp $
|
28
|
25 |
'!
|
|
26 |
|
|
27 |
!MappedCollection class methodsFor:'documentation'!
|
1
|
28 |
|
31
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
48
|
32 |
All Rights Reserved
|
31
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
84
|
45 |
$Header: /cvs/stx/stx/libbasic2/MappedCollection.st,v 1.10 1995-08-10 13:18:08 claus Exp $
|
|
46 |
$Revision: 1.10 $
|
31
|
47 |
"
|
|
48 |
!
|
|
49 |
|
28
|
50 |
documentation
|
|
51 |
"
|
|
52 |
MappedCollections represent collections of objects that are indirectly indexed by names.
|
|
53 |
There are really two collections involved: domain and a map. The map maps
|
|
54 |
between external names and indices into domain, which contains the
|
|
55 |
real association. In order to work properly, the domain and map objects must
|
|
56 |
be instances of a subclass of SequenceableCollection or Dictionary.
|
|
57 |
"
|
|
58 |
! !
|
1
|
59 |
|
|
60 |
!MappedCollection class methodsFor:'instance creation'!
|
|
61 |
|
|
62 |
collection:domainCollection map:mapCollection
|
|
63 |
"return a new MappedCollection"
|
|
64 |
|
|
65 |
^ super new setCollection:domainCollection map:mapCollection
|
|
66 |
!
|
|
67 |
|
|
68 |
new
|
|
69 |
"report an error; mappedCollections may not be created using new"
|
|
70 |
|
|
71 |
self error:'use collection:map: to create a MappedCollection'
|
|
72 |
! !
|
|
73 |
|
|
74 |
!MappedCollection methodsFor:'accessing'!
|
|
75 |
|
|
76 |
at:key
|
|
77 |
^ domain at:(map at:key)
|
|
78 |
!
|
|
79 |
|
|
80 |
at:key put:anObject
|
|
81 |
^ domain at:(map at:key) put:anObject
|
|
82 |
!
|
|
83 |
|
|
84 |
contents
|
|
85 |
|contents|
|
|
86 |
contents := Bag new.
|
49
|
87 |
map do:[:key | contents add:(domain at:key)].
|
1
|
88 |
^ contents
|
|
89 |
!
|
|
90 |
|
|
91 |
add:anObject
|
|
92 |
self shouldNotImplement
|
|
93 |
! !
|
|
94 |
|
|
95 |
!MappedCollection methodsFor:'testing'!
|
|
96 |
|
|
97 |
size
|
|
98 |
"return the number of elements in the receiver"
|
|
99 |
|
|
100 |
^ map size
|
|
101 |
! !
|
|
102 |
|
42
|
103 |
!MappedCollection methodsFor:'copying'!
|
|
104 |
|
|
105 |
postCopy
|
|
106 |
domain := domain copy.
|
|
107 |
map := map copy
|
|
108 |
! !
|
|
109 |
|
1
|
110 |
!MappedCollection methodsFor:'enumerating'!
|
|
111 |
|
|
112 |
do:aBlock
|
|
113 |
"evaluate the argument, aBlock for each element"
|
|
114 |
|
|
115 |
map do:[:mapValue | aBlock value:(domain at:mapValue)].
|
|
116 |
!
|
|
117 |
|
|
118 |
collect:aBlock
|
|
119 |
"for each element in the receiver, evaluate the argument, aBlock
|
|
120 |
and return a new collection with the results"
|
|
121 |
|
|
122 |
|newCollection|
|
|
123 |
|
|
124 |
newCollection := self species new:self size.
|
|
125 |
self do:[:each | newCollection add:(aBlock value:each)].
|
|
126 |
^ newCollection
|
|
127 |
!
|
|
128 |
|
|
129 |
select:aBlock
|
|
130 |
"return a new collection with all elements from the receiver, for which
|
|
131 |
the argument aBlock evaluates to true"
|
|
132 |
|
|
133 |
|newCollection|
|
|
134 |
|
|
135 |
newCollection := self species new:self size.
|
|
136 |
self do:[:each |
|
48
|
137 |
(aBlock value:each) ifTrue:[newCollection add:each].
|
1
|
138 |
].
|
|
139 |
^ newCollection
|
|
140 |
! !
|
|
141 |
|
|
142 |
!MappedCollection methodsFor:'private'!
|
|
143 |
|
|
144 |
setCollection:domainCollection map:mapCollection
|
|
145 |
domain := domainCollection.
|
|
146 |
map := mapCollection
|
48
|
147 |
! !
|
|
148 |
|
|
149 |
!MappedCollection methodsFor:'queries'!
|
1
|
150 |
|
|
151 |
species
|
|
152 |
^ domain species
|
|
153 |
! !
|