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