1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
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 |
|
|
13 |
Object subclass:#Association
|
|
14 |
instanceVariableNames:'key value'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
Association comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
Associations are a key-value pair; they are the elements of Dictionaries -
|
|
26 |
storing value under the key. By itself, an Association is not very
|
|
27 |
useful.
|
|
28 |
|
|
29 |
Instance variables:
|
|
30 |
|
|
31 |
key <Object> the key
|
|
32 |
value <Object> the value
|
|
33 |
|
|
34 |
%W% %E%
|
|
35 |
'!
|
|
36 |
|
|
37 |
!Association class methodsFor:'instance creation'!
|
|
38 |
|
|
39 |
key:aKey
|
|
40 |
"return a new Association."
|
|
41 |
|
|
42 |
^ self basicNew key:aKey
|
|
43 |
!
|
|
44 |
|
|
45 |
key:aKey value:aValue
|
|
46 |
"return a new Association"
|
|
47 |
|
|
48 |
^ self basicNew key:aKey value:aValue
|
|
49 |
! !
|
|
50 |
|
|
51 |
!Association methodsFor:'accessing'!
|
|
52 |
|
|
53 |
key
|
|
54 |
"return the key of the association"
|
|
55 |
|
|
56 |
^ key
|
|
57 |
!
|
|
58 |
|
|
59 |
key:anObject
|
|
60 |
"set the key of the receiver to be anObject.
|
|
61 |
Return the receiver"
|
|
62 |
|
|
63 |
key := anObject
|
|
64 |
!
|
|
65 |
|
|
66 |
value
|
|
67 |
"return the value of the association"
|
|
68 |
|
|
69 |
^ value
|
|
70 |
!
|
|
71 |
|
|
72 |
value:anObject
|
|
73 |
"set the value of the receiver to be anObject.
|
|
74 |
Return the receiver"
|
|
75 |
|
|
76 |
value := anObject
|
|
77 |
!
|
|
78 |
|
|
79 |
key:aKey value:aValue
|
|
80 |
"set both the key and value of the receiver.
|
|
81 |
Return the receiver"
|
|
82 |
|
|
83 |
key := aKey.
|
|
84 |
value := aValue
|
|
85 |
! !
|
|
86 |
|
|
87 |
!Association methodsFor:'comparing'!
|
|
88 |
|
|
89 |
= anAssociation
|
|
90 |
(anAssociation isKindOf:Association) ifTrue:[
|
|
91 |
(anAssociation key = key) ifTrue:[
|
|
92 |
^ anAssociation value = value
|
|
93 |
]
|
|
94 |
].
|
|
95 |
^ false
|
|
96 |
! !
|
|
97 |
|
|
98 |
!Association methodsFor:'printing & storing'!
|
|
99 |
|
|
100 |
printString
|
|
101 |
"return a string containing a printable representation
|
|
102 |
of the receiver"
|
|
103 |
|
|
104 |
^ key printString , '->' , value printString
|
|
105 |
!
|
|
106 |
|
|
107 |
displayString
|
|
108 |
"return a string containing a printable representation
|
|
109 |
of the receiver for displaying"
|
|
110 |
|
|
111 |
^ key displayString , '->' , value displayString
|
|
112 |
! !
|