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
|
|
14 |
instanceVariableNames:'value'
|
1
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
Association comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
379
|
22 |
All Rights Reserved
|
92
|
23 |
|
379
|
24 |
$Header: /cvs/stx/stx/libbasic/Association.st,v 1.11 1995-08-10 12:25:56 claus Exp $
|
68
|
25 |
'!
|
1
|
26 |
|
68
|
27 |
!Association class methodsFor:'documentation'!
|
1
|
28 |
|
82
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
379
|
32 |
All Rights Reserved
|
82
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
379
|
45 |
$Header: /cvs/stx/stx/libbasic/Association.st,v 1.11 1995-08-10 12:25:56 claus Exp $
|
|
46 |
$Revision: 1.11 $
|
82
|
47 |
"
|
|
48 |
!
|
|
49 |
|
68
|
50 |
documentation
|
|
51 |
"
|
92
|
52 |
Associations are a key-value pair; conceptionally, they are the elements of
|
|
53 |
Dictionaries - storing value under the key. (However, the real implementation
|
|
54 |
of Dictionary is different).
|
154
|
55 |
Taken by itself, an association is not very useful.
|
1
|
56 |
|
68
|
57 |
Instance variables:
|
|
58 |
|
379
|
59 |
key <Object> the key (inherited)
|
|
60 |
value <Object> the value
|
68
|
61 |
"
|
|
62 |
! !
|
1
|
63 |
|
|
64 |
!Association class methodsFor:'instance creation'!
|
|
65 |
|
|
66 |
key:aKey value:aValue
|
|
67 |
"return a new Association"
|
|
68 |
|
|
69 |
^ self basicNew key:aKey value:aValue
|
|
70 |
! !
|
|
71 |
|
|
72 |
!Association methodsFor:'accessing'!
|
|
73 |
|
|
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 |
key:aKey value:aValue
|
|
88 |
"set both the key and value of the receiver.
|
|
89 |
Return the receiver"
|
|
90 |
|
|
91 |
key := aKey.
|
|
92 |
value := aValue
|
|
93 |
! !
|
|
94 |
|
|
95 |
!Association methodsFor:'comparing'!
|
|
96 |
|
|
97 |
= anAssociation
|
68
|
98 |
"return true if the receiver equals the argument.
|
154
|
99 |
Notice, that this compares both key AND value.
|
|
100 |
Time will show if this is ok."
|
43
|
101 |
|
154
|
102 |
self species == anAssociation species ifTrue:[
|
379
|
103 |
(anAssociation key = key) ifTrue:[
|
|
104 |
^ anAssociation value = value
|
|
105 |
]
|
1
|
106 |
].
|
|
107 |
^ false
|
54
|
108 |
!
|
|
109 |
|
|
110 |
hash
|
|
111 |
"return an integer useful for hashing on the receiver;
|
|
112 |
redefined since = is redefined here."
|
|
113 |
|
|
114 |
^ (key hash) bitXor:(value hash)
|
1
|
115 |
! !
|
|
116 |
|
|
117 |
!Association methodsFor:'printing & storing'!
|
|
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
|
1
|
126 |
!
|
|
127 |
|
|
128 |
displayString
|
|
129 |
"return a string containing a printable representation
|
54
|
130 |
of the receiver for displaying - redefined to use display string on
|
|
131 |
the components for nicer look"
|
1
|
132 |
|
|
133 |
^ key displayString , '->' , value displayString
|
|
134 |
! !
|