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 |
"
|
|
12 |
|
5792
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
154
|
15 |
LookupKey subclass:#Association
|
1283
|
16 |
instanceVariableNames:'value'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Collections-Support'
|
1
|
20 |
!
|
|
21 |
|
68
|
22 |
!Association class methodsFor:'documentation'!
|
1
|
23 |
|
82
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
379
|
27 |
All Rights Reserved
|
82
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
68
|
38 |
documentation
|
|
39 |
"
|
92
|
40 |
Associations are a key-value pair; conceptionally, they are the elements of
|
|
41 |
Dictionaries - storing value under the key. (However, the real implementation
|
|
42 |
of Dictionary is different).
|
154
|
43 |
Taken by itself, an association is not very useful.
|
1
|
44 |
|
1283
|
45 |
[Instance variables:]
|
68
|
46 |
|
1283
|
47 |
key <Object> the key (inherited)
|
|
48 |
value <Object> the value
|
|
49 |
|
1290
|
50 |
[author:]
|
|
51 |
Claus Gittinger
|
|
52 |
|
1283
|
53 |
[See also:]
|
|
54 |
Dictionary IdentityDictionary
|
68
|
55 |
"
|
|
56 |
! !
|
1
|
57 |
|
|
58 |
!Association class methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
key:aKey value:aValue
|
|
61 |
"return a new Association"
|
|
62 |
|
|
63 |
^ self basicNew key:aKey value:aValue
|
|
64 |
! !
|
|
65 |
|
|
66 |
!Association methodsFor:'accessing'!
|
|
67 |
|
607
|
68 |
key:aKey value:aValue
|
|
69 |
"set both the key and value of the receiver.
|
|
70 |
Return the receiver"
|
|
71 |
|
|
72 |
key := aKey.
|
|
73 |
value := aValue
|
|
74 |
!
|
|
75 |
|
1
|
76 |
value
|
|
77 |
"return the value of the association"
|
|
78 |
|
|
79 |
^ value
|
|
80 |
!
|
|
81 |
|
|
82 |
value:anObject
|
|
83 |
"set the value of the receiver to be anObject.
|
|
84 |
Return the receiver"
|
|
85 |
|
|
86 |
value := anObject
|
|
87 |
! !
|
|
88 |
|
|
89 |
!Association methodsFor:'comparing'!
|
|
90 |
|
|
91 |
= anAssociation
|
68
|
92 |
"return true if the receiver equals the argument.
|
154
|
93 |
Notice, that this compares both key AND value.
|
|
94 |
Time will show if this is ok."
|
43
|
95 |
|
154
|
96 |
self species == anAssociation species ifTrue:[
|
379
|
97 |
(anAssociation key = key) ifTrue:[
|
|
98 |
^ anAssociation value = value
|
|
99 |
]
|
1
|
100 |
].
|
|
101 |
^ false
|
54
|
102 |
!
|
|
103 |
|
|
104 |
hash
|
|
105 |
"return an integer useful for hashing on the receiver;
|
|
106 |
redefined since = is redefined here."
|
|
107 |
|
|
108 |
^ (key hash) bitXor:(value hash)
|
1
|
109 |
! !
|
|
110 |
|
|
111 |
!Association methodsFor:'printing & storing'!
|
|
112 |
|
607
|
113 |
displayString
|
|
114 |
"return a string containing a printable representation
|
|
115 |
of the receiver for displaying - redefined to use display string on
|
|
116 |
the components for nicer look"
|
|
117 |
|
|
118 |
^ key displayString , '->' , value displayString
|
|
119 |
!
|
|
120 |
|
54
|
121 |
printOn:aStream
|
1
|
122 |
"return a string containing a printable representation
|
|
123 |
of the receiver"
|
|
124 |
|
54
|
125 |
key printOn:aStream.
|
|
126 |
aStream nextPutAll:'->'.
|
|
127 |
value printOn:aStream
|
5234
|
128 |
!
|
|
129 |
|
|
130 |
storeOn:aStream
|
|
131 |
"append a string representing an expression to reconstruct the receiver
|
|
132 |
to aStream."
|
|
133 |
|
|
134 |
aStream nextPut:$(.
|
|
135 |
key storeOn:aStream.
|
|
136 |
aStream nextPutAll:'->'.
|
|
137 |
value storeOn:aStream.
|
|
138 |
aStream nextPut:$).
|
|
139 |
|
|
140 |
"Created: / 3.2.2000 / 22:31:28 / cg"
|
607
|
141 |
! !
|
1
|
142 |
|
1397
|
143 |
!Association methodsFor:'queries'!
|
|
144 |
|
|
145 |
isAssociation
|
|
146 |
"return true, if the receiver is some kind of association;
|
|
147 |
true is returned here - the method is redefined from Object."
|
|
148 |
|
|
149 |
^ true
|
|
150 |
|
|
151 |
"Created: 14.5.1996 / 17:04:13 / cg"
|
|
152 |
! !
|
|
153 |
|
629
|
154 |
!Association class methodsFor:'documentation'!
|
|
155 |
|
|
156 |
version
|
5793
|
157 |
^ '$Header: /cvs/stx/stx/libbasic/Association.st,v 1.21 2001-01-26 15:33:54 cg Exp $'
|
629
|
158 |
! !
|