author | Stefan Vogel <sv@exept.de> |
Fri, 11 Jul 2014 11:55:51 +0200 | |
changeset 16767 | 42a305a493e1 |
parent 16740 | 4d956eba7683 |
child 18120 | e3a375d5f6a8 |
child 21543 | 5be3bab4f1a8 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
379 | 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 |
" |
|
5792 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
154 | 14 |
LookupKey subclass:#Association |
1283 | 15 |
instanceVariableNames:'value' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Support' |
|
1 | 19 |
! |
20 |
||
68 | 21 |
!Association class methodsFor:'documentation'! |
1 | 22 |
|
82 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
379 | 26 |
All Rights Reserved |
82 | 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 |
||
68 | 37 |
documentation |
38 |
" |
|
92 | 39 |
Associations are a key-value pair; conceptionally, they are the elements of |
40 |
Dictionaries - storing value under the key. (However, the real implementation |
|
41 |
of Dictionary is different). |
|
154 | 42 |
Taken by itself, an association is not very useful. |
1 | 43 |
|
1283 | 44 |
[Instance variables:] |
68 | 45 |
|
1283 | 46 |
key <Object> the key (inherited) |
47 |
value <Object> the value |
|
48 |
||
1290 | 49 |
[author:] |
50 |
Claus Gittinger |
|
51 |
||
1283 | 52 |
[See also:] |
53 |
Dictionary IdentityDictionary |
|
68 | 54 |
" |
55 |
! ! |
|
1 | 56 |
|
57 |
!Association class methodsFor:'instance creation'! |
|
58 |
||
59 |
key:aKey value:aValue |
|
60 |
"return a new Association" |
|
61 |
||
62 |
^ self basicNew key:aKey value:aValue |
|
63 |
! ! |
|
64 |
||
65 |
!Association methodsFor:'accessing'! |
|
66 |
||
607 | 67 |
key:aKey value:aValue |
68 |
"set both the key and value of the receiver. |
|
69 |
Return the receiver" |
|
70 |
||
71 |
key := aKey. |
|
72 |
value := aValue |
|
73 |
! |
|
74 |
||
1 | 75 |
value |
76 |
"return the value of the association" |
|
77 |
||
78 |
^ value |
|
79 |
! |
|
80 |
||
81 |
value:anObject |
|
82 |
"set the value of the receiver to be anObject. |
|
83 |
Return the receiver" |
|
84 |
||
85 |
value := anObject |
|
86 |
! ! |
|
87 |
||
11908
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
88 |
!Association methodsFor:'collection mimicri'! |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
89 |
|
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
90 |
keysAndValuesDo:aBlock |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
91 |
"evaluate the argument, aBlock for each element in the collection. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
92 |
Pass both index and element to the block. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
93 |
Added here to allow for an association to be added via the comma operation |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
94 |
to an existing dictionary" |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
95 |
|
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
96 |
aBlock value:key value:value. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
97 |
|
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
98 |
" |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
99 |
|d1 d2| |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
100 |
|
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
101 |
d1 := Dictionary new. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
102 |
d1 at:#a put:'aaa'. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
103 |
d1 at:#b put:'bbb'. |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
104 |
d2 := d1 , (#c -> 'ccc'). |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
105 |
d2 |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
106 |
" |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
107 |
! ! |
1034accdce84
+ keysAndValuesDo: for collection mimicri
Claus Gittinger <cg@exept.de>
parents:
5793
diff
changeset
|
108 |
|
1 | 109 |
!Association methodsFor:'comparing'! |
110 |
||
111 |
= anAssociation |
|
68 | 112 |
"return true if the receiver equals the argument. |
154 | 113 |
Notice, that this compares both key AND value. |
114 |
Time will show if this is ok." |
|
43 | 115 |
|
16767 | 116 |
^ self species == anAssociation species |
117 |
and:[anAssociation key = key and:[anAssociation value = value]] |
|
54 | 118 |
! |
119 |
||
120 |
hash |
|
121 |
"return an integer useful for hashing on the receiver; |
|
122 |
redefined since = is redefined here." |
|
123 |
||
124 |
^ (key hash) bitXor:(value hash) |
|
1 | 125 |
! ! |
126 |
||
127 |
!Association methodsFor:'printing & storing'! |
|
128 |
||
14118
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
129 |
displayOn:aGCOrStream |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
130 |
"Compatibility |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
131 |
append a printed desription on some stream (Dolphin, Squeak) |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
132 |
OR: |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
133 |
display the receiver in a graphicsContext at 0@0 (ST80). |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
134 |
This method allows for any object to be displayed in some view |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
135 |
(although the fallBack is to display its printString ...)" |
607 | 136 |
|
14118
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
137 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
138 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
16740 | 139 |
(aGCOrStream isStream) ifFalse:[ |
14118
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
140 |
^ super displayOn:aGCOrStream |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
141 |
]. |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
142 |
|
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
143 |
key displayOn:aGCOrStream. |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
144 |
aGCOrStream nextPutAll:'->'. |
c4375f1867f6
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
12161
diff
changeset
|
145 |
value displayOn:aGCOrStream. |
607 | 146 |
! |
147 |
||
54 | 148 |
printOn:aStream |
12161 | 149 |
"append a printed representation of the receiver to aStream" |
1 | 150 |
|
54 | 151 |
key printOn:aStream. |
152 |
aStream nextPutAll:'->'. |
|
153 |
value printOn:aStream |
|
5234 | 154 |
! |
155 |
||
156 |
storeOn:aStream |
|
157 |
"append a string representing an expression to reconstruct the receiver |
|
158 |
to aStream." |
|
159 |
||
160 |
aStream nextPut:$(. |
|
161 |
key storeOn:aStream. |
|
162 |
aStream nextPutAll:'->'. |
|
163 |
value storeOn:aStream. |
|
164 |
aStream nextPut:$). |
|
165 |
||
166 |
"Created: / 3.2.2000 / 22:31:28 / cg" |
|
607 | 167 |
! ! |
1 | 168 |
|
1397 | 169 |
!Association methodsFor:'queries'! |
170 |
||
171 |
isAssociation |
|
172 |
"return true, if the receiver is some kind of association; |
|
173 |
true is returned here - the method is redefined from Object." |
|
174 |
||
175 |
^ true |
|
176 |
||
177 |
"Created: 14.5.1996 / 17:04:13 / cg" |
|
178 |
! ! |
|
179 |
||
629 | 180 |
!Association class methodsFor:'documentation'! |
181 |
||
182 |
version |
|
16767 | 183 |
^ '$Header: /cvs/stx/stx/libbasic/Association.st,v 1.26 2014-07-11 09:55:51 stefan Exp $' |
12161 | 184 |
! |
185 |
||
186 |
version_CVS |
|
16767 | 187 |
^ '$Header: /cvs/stx/stx/libbasic/Association.st,v 1.26 2014-07-11 09:55:51 stefan Exp $' |
629 | 188 |
! ! |
16740 | 189 |