|
Class: Association
Object
|
+--Magnitude
|
+--LookupKey
|
+--Association
|
+--Class::SimulatedClassPool::SimulatedVariableBinding
- Package:
- stx:libbasic
- Category:
- Collections-Support
- Version:
- rev:
1.31
date: 2024/03/21 17:09:47
- user: cg
- file: Association.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Associations are a key-value pair; conceptionally, they are the elements of
Dictionaries - storing value under the key. (However, the real implementation
of Dictionary is different).
Taken by itself, an association is not very useful.
[Instance variables:]
key <Object> the key (inherited)
value <Object> the value
copyrightCOPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
key: aKey value: aValue
-
return a new Association
accessing
-
key: aKey value: aValue
-
set both the key and value of the receiver.
Return the receiver
-
value
-
return the value of the association
-
value: anObject
-
set the value of the receiver to be anObject.
Return the receiver
collection mimicri
-
keysAndValuesDo: aBlock
-
evaluate the argument, aBlock for each element in the collection.
Pass both index and element to the block.
Added here to allow for an association to be added via the comma operation
to an existing dictionary
Usage example(s):
(#c -> 'ccc') keysAndValuesDo:[:k :v | Transcript showCR: e'k:{k} v:{v}']
(#a -> 10),(#b -> 20) keysAndValuesDo:[:k :v | Transcript showCR: e'k:{k} v:{v}']
|
comparing
-
= anAssociation
-
return true if the receiver equals the argument.
Notice, that this compares both key AND value.
Time will show if this is ok.
-
hash
-
return an integer useful for hashing on the receiver;
redefined since = is redefined here.
converting
-
, anAssociation
-
Answer a Dictionary with of the receiver and the argument as its elements.
Usage example(s):
(#a -> 1), (#b -> 2)
(#a -> 1), (#b -> 2) , (#c -> 3)
(#a -> 1), (#b -> 2) , (#c -> 3) , (#d -> 4)
|
printing & storing
-
displayOn: aGCOrStream
-
Compatibility
append a printed desription on some stream (Dolphin, Squeak)
OR:
display the receiver in a graphicsContext at 0@0 (ST80).
This method allows for any object to be displayed in some view
(although the fallBack is to display its printString ...)
-
printOn: aStream
-
append a printed representation of the receiver to aStream
-
storeOn: aStream
-
append a string representing an expression to reconstruct the receiver
to aStream.
queries
-
isAssociation
-
return true, if the receiver is some kind of association;
true is returned here - the method is redefined from Object.
|