/
Association.class.st
96 lines (75 loc) · 2.33 KB
/
Association.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"
I represent a pair of associated objects--a key and a value. My instances can serve as entries in a dictionary.
Implementation notes:
Note that hash is not redefined even if the = was redefined because Association>>hash may cause extreme slowdowns in compiling Unicode methods. Association>>hash does not need to hash the value; it's slow and useless.
"
Class {
#name : #Association,
#superclass : #LookupKey,
#instVars : [
'value'
],
#category : #'Collections-Support-Associations'
}
{ #category : #'instance creation' }
Association class >> key: newKey value: newValue [
"Answer an instance of me with the arguments as the key and value of
the association."
^self basicNew key: newKey value: newValue
]
{ #category : #comparing }
Association >> = anAssociation [
^ super = anAssociation and: [value = anAssociation value]
]
{ #category : #testing }
Association >> analogousCodeTo: anAssociation [
^ self = anAssociation
]
{ #category : #'self evaluating' }
Association >> isSelfEvaluating [
^ self class == Association and: [self key isSelfEvaluating and: [self value isSelfEvaluating]]
]
{ #category : #accessing }
Association >> key: aKey value: anObject [
"Store the arguments as the variables of the receiver."
key := aKey.
value := anObject
]
{ #category : #comparing }
Association >> literalEqual: otherLiteral [
"Answer true if the receiver and otherLiteral represent the same literal.
Variable bindings are literally equals only if identical.
This is how variable sharing works, by preserving identity and changing only the value."
^self == otherLiteral
]
{ #category : #testing }
Association >> needsFullDefinition [
"Implemented here so we can use simple Associations as Bindings instead of LiteralVariable
subclasses"
^false
]
{ #category : #printing }
Association >> printOn: aStream [
super printOn: aStream.
aStream nextPutAll: '->'.
value printOn: aStream
]
{ #category : #printing }
Association >> storeOn: aStream [
"Store in the format (key->value)"
aStream nextPut: $(.
key storeOn: aStream.
aStream nextPutAll: '->'.
value storeOn: aStream.
aStream nextPut: $)
]
{ #category : #evaluating }
Association >> value [
"Answer the value of the receiver."
^value
]
{ #category : #accessing }
Association >> value: anObject [
"Store the argument, anObject, as the value of the receiver."
value := anObject
]