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