Association.st
author claus
Thu, 02 Jun 1994 18:22:49 +0200
changeset 88 81dacba7a63a
parent 82 0147b4f725ae
child 92 0c73b48551ac
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (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.
"

Magnitude subclass:#Association
       instanceVariableNames:'key value'
       classVariableNames:''
       poolDictionaries:''
       category:'Collections-Support'
!

Association comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
              All Rights Reserved
'!

!Association class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (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.
"
!

version
"
$Header: /cvs/stx/stx/libbasic/Association.st,v 1.8 1994-06-02 11:18:29 claus Exp $
"
!

documentation
"
    Associations are a key-value pair; they are the elements of Dictionaries -
    storing value under the key. By itself, an Association is not very
    useful.

    Instance variables:

        key             <Object>        the key
        value           <Object>        the value
"
! !

!Association class methodsFor:'instance creation'!

key:aKey
    "return a new Association."

    ^ self basicNew key:aKey
!

key:aKey value:aValue
    "return a new Association"

    ^ self basicNew key:aKey value:aValue
! !

!Association methodsFor:'accessing'!

key
    "return the key of the association"

    ^ key
!

key:anObject
    "set the key of the receiver to be anObject.
     Return the receiver"

    key := anObject
!

value
    "return the value of the association"

    ^ value
!

value:anObject
    "set the value of the receiver to be anObject.
     Return the receiver"

    value := anObject
!

key:aKey value:aValue
    "set both the key and value of the receiver.
     Return the receiver"

    key := aKey.
    value := aValue
! !

!Association methodsFor:'comparing'!

= anAssociation
    "return true if the receiver equals the argument.
     Notice, that in contrast to the less/greater compares,
     this compares both key AND value."

    (anAssociation isKindOf:Association) ifTrue:[
        (anAssociation key = key) ifTrue:[
            ^ anAssociation value = value
        ]
    ].
    ^ false
!

hash
    "return an integer useful for hashing on the receiver;
     redefined since = is redefined here."

    ^ (key hash) bitXor:(value hash)
!

> anAssociation
    "return true, if the receivers KEY is greater 
     than the arguments key. The argument must be an association"

    ^ key > anAssociation key
! !

!Association methodsFor:'printing & storing'!

printOn:aStream
    "return a string containing a printable representation
     of the receiver"

    key printOn:aStream.
    aStream nextPutAll:'->'.
    value printOn:aStream
!

displayString
    "return a string containing a printable representation
     of the receiver for displaying - redefined to use display string on
     the components for nicer look"

    ^ key displayString , '->' , value displayString
! !