KeyedCollection.st
author Stefan Vogel <sv@exept.de>
Wed, 10 Jan 2018 22:55:27 +0100
changeset 22412 e2516a1b3b82
parent 21732 0fd83e26247f
child 23338 e2290d3eb871
permissions -rw-r--r--
#TUNING by stefan class: Character class changed: #utf8DecodeFrom:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
     1
"{ Encoding: utf8 }"
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
     2
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1998 by eXept Software AG
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
9482
7bebdb8e4c60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9480
diff changeset
    14
"{ Package: 'stx:libbasic' }"
8893
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
    15
19469
e43475084bb5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 17120
diff changeset
    16
"{ NameSpace: Smalltalk }"
e43475084bb5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 17120
diff changeset
    17
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Collection subclass:#KeyedCollection
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-Abstract'
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!KeyedCollection class methodsFor:'documentation'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1998 by eXept Software AG
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    Abstract superclass for collections which have a key->value mapping.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    This abstract class provides functionality common to those collections,
17120
246d9198d84e class: KeyedCollection
Claus Gittinger <cg@exept.de>
parents: 13045
diff changeset
    46
    without knowing how the concrete class implements things. 
246d9198d84e class: KeyedCollection
Claus Gittinger <cg@exept.de>
parents: 13045
diff changeset
    47
    Thus, all methods found here depend on some basic mechanisms 
246d9198d84e class: KeyedCollection
Claus Gittinger <cg@exept.de>
parents: 13045
diff changeset
    48
    to be defined in the concrete class. 
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    These basic methods are usually defined as #subclassResponsibility here.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    Some methods are also redefined for better performance.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    Subclasses should at least implement:
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
        at:ifAbsent:        - accessing elements
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        removeKey:ifAbsent  - removing
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        keysAndValuesDo:    - enumerating
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [author:]
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        Claus Gittinger
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
! !
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    62
!KeyedCollection class methodsFor:'instance creation'!
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    63
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    64
withAll:aDictionary
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    65
    "create a MethodDictionary from another Dictionary"
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    66
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    67
    |newDict|
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    68
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    69
    newDict := self new:aDictionary size.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    70
    aDictionary keysAndValuesDo:[:key :value |
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    71
        newDict at:key put:value.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    72
    ].
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    73
    ^ newDict
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    74
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    75
    "
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    76
        |d|
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    77
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    78
        d := Dictionary withKeys:#(a b c d e) andValues:#(1 2 3 4 5).
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    79
        KeyValueList withAll:d.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    80
    "
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    81
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    82
    "Created: / 17-03-2017 / 11:29:09 / stefan"
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    83
!
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    84
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    85
withAssociations:aCollectionOfAssociations
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    86
    "return a new instance where associations are taken from the argument"
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    87
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    88
    |newDict|
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    89
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
    90
    newDict := self new:aCollectionOfAssociations size.
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    91
    aCollectionOfAssociations do:[:assoc |
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    92
        newDict at:assoc key put:assoc value
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    93
    ].
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    94
    ^ newDict
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    95
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    96
    "
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    97
     KeyValueList withAssociations:{ #'one'->1 .
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    98
                                   #'two'->2 .
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
    99
                                   #'three'->3 .
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   100
                                   #'four'->4 }
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   101
    "
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   102
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   103
    "Created: / 16-03-2017 / 12:15:38 / stefan"
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   104
    "Modified: / 17-03-2017 / 11:30:55 / stefan"
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   105
!
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   106
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   107
withKeys:keyArray andValues:valueArray
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   108
    "return a new instance where keys and values are taken from
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   109
     the argumentArrays."
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   110
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   111
    |newColl sz "{ Class: SmallInteger }"|
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   112
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   113
    sz := keyArray size.
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   114
    newColl := self new:sz.
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   115
    1 to:sz do:[:index |
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   116
        newColl at:(keyArray at:index) put:(valueArray at:index).
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   117
    ].
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   118
    ^ newColl
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   119
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   120
    "Created: / 16-03-2017 / 11:06:51 / stefan"
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   121
    "Modified (format): / 16-03-2017 / 12:12:09 / stefan"
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   122
!
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   123
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   124
withKeysAndValues:anArray
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   125
    "return a new instance where keys and values are taken from alternating
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   126
     elements of anArray"
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   127
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   128
    |newDict sz "{ Class: SmallInteger }"|
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   129
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   130
    sz := anArray size.
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   131
    newDict := self new:sz.
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   132
    1 to:sz by:2 do:[:i |
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   133
        newDict at:(anArray at:i) put:(anArray at:i+1)
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   134
    ].
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   135
    ^ newDict
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   136
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   137
    "
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   138
     KeyValueList withKeysAndValues:#('one' 1 'two' 2 'three' 3 'four' 4)
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   139
    "
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   140
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   141
    "Created: / 16-03-2017 / 12:13:27 / stefan"
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   142
    "Modified: / 17-03-2017 / 11:32:42 / stefan"
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   143
! !
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   144
8893
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   145
!KeyedCollection class methodsFor:'queries'!
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   146
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   147
isAbstract
11222
7e8b37ffc6ca comment
Claus Gittinger <cg@exept.de>
parents: 10533
diff changeset
   148
    "Return if this class is an abstract class.
7e8b37ffc6ca comment
Claus Gittinger <cg@exept.de>
parents: 10533
diff changeset
   149
     True is returned for KeyedCollection here; false for subclasses.
19469
e43475084bb5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 17120
diff changeset
   150
     Abstract subclasses must redefine this again."
11222
7e8b37ffc6ca comment
Claus Gittinger <cg@exept.de>
parents: 10533
diff changeset
   151
8893
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   152
    ^ self == KeyedCollection
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   153
! !
99996b25482e +isAbstract
Claus Gittinger <cg@exept.de>
parents: 3615
diff changeset
   154
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
!KeyedCollection methodsFor:'accessing'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   157
associationAt:aKey 
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   158
    "return an association consisting of aKey and the element indexed 
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   159
     by aKey - 
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   160
     report an error, if no element is stored under aKey."
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   161
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   162
    ^ self associationAt:aKey ifAbsent:[self errorKeyNotFound:aKey]
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   163
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   164
    "Modified: / 16-03-2017 / 17:19:52 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   165
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   166
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   167
associationAt:aKey ifAbsent:exceptionBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   168
    "return an association consisting of aKey and the element indexed by aKey -
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   169
     return result of exceptionBlock if no element is stored under aKey.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   170
     Warning: this is a comatibility interface only, with a different semantic as
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   171
              the original ST80 implementation. The returned assoc is created on the fly,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   172
              and not the one stored in the receiver (there are not assocs there)"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   173
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   174
    |value|
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   175
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   176
    value := self at:aKey ifAbsent:[^ exceptionBlock value].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   177
    ^ Association key:aKey value:value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   178
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   179
    "Created: / 16-03-2017 / 17:17:05 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   180
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   181
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   182
associations
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   183
    "return an ordered collection containing the receiver's associations."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   184
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   185
    |coll|
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   186
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   187
    coll := OrderedCollection new.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   188
    self associationsDo:[:assoc | coll add:assoc].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   189
    ^ coll
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   190
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   191
    "Created: / 16-03-2017 / 17:30:47 / stefan"
21649
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   192
!
4a09b7965b34 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21369
diff changeset
   193
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
at:key
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    "return the value stored under akey.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
     Raise an error if not found"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    ^ self at:key ifAbsent:[self errorKeyNotFound:key].
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    "Modified: / 19.6.1998 / 00:48:27 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
at:key ifAbsent:exceptionBlock
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    "return the value stored under akey.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
     Return the value from evaluating exceptionBlock if not found"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    ^ self subclassResponsibility
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    "Created: / 19.6.1998 / 00:48:23 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   212
at:aKey ifAbsent:default update:aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   213
    "update the element stored under aKey with the result from
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   214
     evaluating aBlock with the previous stored value as argument, or with default,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   215
     if there was no such key initially.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   216
     Return the new value stored."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   217
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   218
    ^ self at:aKey put:(aBlock value:(self at:aKey ifAbsent:default))
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   219
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   220
    "Created: / 16-03-2017 / 17:28:15 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   221
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   222
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   223
at:aKey ifAbsentPut:valueBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   224
    "return the element indexed by aKey if present,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   225
     if not present, store the result of evaluating valueBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   226
     under aKey and return it.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   227
     WARNING: do not add elements while iterating over the receiver.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   228
              Iterate over a copy to do this."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   229
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   230
    ^ self at:aKey ifAbsent:[self at:aKey put:valueBlock value].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   231
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   232
    "Created: / 16-03-2017 / 17:23:07 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   233
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   234
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   235
at:aKey ifPresent:aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   236
    "try to retrieve the value stored at aKey.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   237
     If there is nothing stored under this key, do nothing.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   238
     Otherwise, evaluate aBlock, passing the retrieved value as argument."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   239
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   240
    |v|
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   241
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   242
    v := self at:aKey ifAbsent:[^ nil].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   243
    ^ aBlock value:v.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   244
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   245
    "Created: / 16-03-2017 / 17:11:27 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   246
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   247
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   248
at:aKey put:anObject
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   249
    "add the argument anObject under key, aKey to the receiver.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   250
     Return anObject (sigh).
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   251
     WARNING: do not add elements while iterating over the receiver.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   252
              Iterate over a copy to do this."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   253
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   254
    ^ self subclassResponsibility
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   255
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   256
    "Created: / 16-03-2017 / 17:33:12 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   257
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   258
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   259
at:aKey put:anObject ifPresent:aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   260
    "if the receiver contains an element stored under aKey,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   261
     retrieve it and evaluate aBlock passing the element as argument,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   262
     return the blocks value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   263
     If not, store aValue under the key.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   264
     Use this with an error-reporting block, to ensure that no keys are reused"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   265
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   266
    |value isAbsent|
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   267
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   268
    value := self at:aKey ifAbsentPut:[isAbsent := true. anObject].
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   269
    isAbsent notNil ifTrue:[
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   270
        ^ value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   271
    ].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   272
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   273
    ^ aBlock value:value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   274
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   275
    "Created: / 16-03-2017 / 17:38:00 / stefan"
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   276
    "Modified: / 17-03-2017 / 11:37:26 / stefan"
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   277
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   278
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   279
at:aKey update:aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   280
    "update the element stored under aKey with the result from
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   281
     evaluating aBlock with the previous stored value as argument.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   282
     Report an error if there was no such key initially.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   283
     Return the new value stored."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   284
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   285
    ^ self at:aKey put:(aBlock value:(self at:aKey))
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   286
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   287
    "Created: / 16-03-2017 / 17:29:22 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   288
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   289
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   290
keyAtEqualValue:value
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    "return the key under which value is stored.
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   292
     Raise an error if not found.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   293
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   294
     NOTICE:
21369
d7b0866974d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21368
diff changeset
   295
        The value is searched using equality compare"
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   297
    ^ self keyAtEqualValue:value ifAbsent:[self errorValueNotFound:value].
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   299
    "Created: / 07-02-2017 / 11:11:41 / cg"
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   302
keyAtEqualValue:value ifAbsent:exceptionBlock
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   303
    "return the key under which value is stored.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   304
     If not found, return the value from evaluating exceptionBlock.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   305
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   306
     NOTICE:
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   307
        The value is searched using equality compare"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   308
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   309
    self keysAndValuesDo:[:elKey :elValue |
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   310
        value = elValue ifTrue:[^ elKey]
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   311
    ].
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   312
    ^ exceptionBlock value
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   313
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   314
    "Created: / 07-02-2017 / 11:12:03 / cg"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   315
!
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   316
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   317
keyAtIdenticalValue:value
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
    "return the key under which value is stored.
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   319
     Raise an error if not found.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   320
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   321
     NOTICE:
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   322
        The value is searched using identity compare"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   323
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   324
    ^ self keyAtIdenticalValue:value ifAbsent:[self errorValueNotFound:value].
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   325
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   326
    "Created: / 07-02-2017 / 11:12:23 / cg"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   327
!
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   328
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   329
keyAtIdenticalValue:value ifAbsent:exceptionBlock
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   330
    "return the key under which value is stored.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   331
     If not found, return the value from evaluating exceptionBlock.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   332
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   333
     NOTICE:
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   334
        The value is searched using identity compare"
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
    self keysAndValuesDo:[:elKey :elValue |
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
        value == elValue ifTrue:[^ elKey]
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    ].
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    ^ exceptionBlock value
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   341
    "Created: / 07-02-2017 / 11:12:46 / cg"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   342
!
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   343
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   344
keyAtValue:value
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   345
    "return the key under which value is stored.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   346
     Raise an error if not found.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   347
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   348
     NOTICE:
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   349
        The value is searched using equality compare"
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   350
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   351
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   352
    ^ self keyAtEqualValue:value.
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   353
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   354
    "Created: / 19-06-1998 / 00:49:16 / cg"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   355
    "Modified (comment): / 07-02-2017 / 11:13:29 / cg"
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   356
    "Modified (comment): / 16-03-2017 / 18:00:28 / stefan"
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   357
!
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   358
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   359
keyAtValue:value ifAbsent:exceptionBlock
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   360
    "return the key under which value is stored.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   361
     If not found, return the value from evaluating exceptionBlock.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   362
     This is a slow access, since the receiver is searched sequentially.
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   363
     NOTICE:
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   364
        The value is searched using equality compare"
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   365
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   366
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   367
    ^ self keyAtEqualValue:value ifAbsent:exceptionBlock.
21368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   368
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   369
    "Created: / 19-06-1998 / 00:50:34 / cg"
1e4c41f4d3af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19844
diff changeset
   370
    "Modified: / 07-02-2017 / 11:13:20 / cg"
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   371
    "Modified (comment): / 16-03-2017 / 18:00:37 / stefan"
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
keys
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    "return a collection containing the keys of the receiver"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    |keyCollection|
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    keyCollection := OrderedCollection new.
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
    self keysDo:[:aKey |
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
        keyCollection add:aKey
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    ].
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
    ^ keyCollection
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
    "Modified: / 19.6.1998 / 00:48:27 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
    "Created: / 19.6.1998 / 00:51:49 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
! !
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
!KeyedCollection methodsFor:'enumerating'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   391
associationsDo:aBlock
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   392
    "perform the block for all associations in the collection.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   393
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   394
     See also:
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   395
        #do:              (which passes values to its block)
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   396
        #keysDo:          (which passes only keys to its block)
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   397
        #keysAndValuesDo: (which passes keys&values)
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   398
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   399
     This is much like #keysAndValuesDo:, but aBlock gets the
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   400
     key and value as a single association argument.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   401
     #keysAndValuesDo: and is a bit faster therefore (no intermediate objects).
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   402
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   403
     WARNING: do not add/remove elements while iterating over the receiver.
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   404
              Iterate over a copy to do this."
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   405
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   406
    self keysAndValuesDo:[:eachKey :eachValue|
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   407
        aBlock value:(Association key:eachKey value:eachValue).
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   408
    ].
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   409
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   410
    "Created: / 17-03-2017 / 11:05:29 / stefan"
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   411
!
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   412
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
do:aBlock
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
    "evaluate aBlock for each value"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
    self keysAndValuesDo:[:elKey :elValue | aBlock value:elValue]
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
    "Created: / 19.6.1998 / 00:56:24 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
keysAndValuesDo:aBlock
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
    "evaluate aBlock for each key and value"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    ^ self subclassResponsibility
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
    "Created: / 19.6.1998 / 00:56:52 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
! !
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
21655
058cafb6c2f6 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21653
diff changeset
   429
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
!KeyedCollection methodsFor:'removing'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
21732
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   432
removeAllKeys:aCollection
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   433
    "remove all keys of the argument, aCollection from the receiver.
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   434
     Raises an error, if some element-to-remove is not in the receiver."
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   435
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   436
    aCollection do:[:element | self removeKey:element].
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   437
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   438
    "Modified (comment): / 28-04-2017 / 13:36:15 / stefan"
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   439
!
0fd83e26247f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21655
diff changeset
   440
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
removeKey:aKey
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    "remove key (and the value stored under that key) from the
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
     receiver; raise an error if no such element is contained"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    ^ self removeKey:aKey ifAbsent:[self errorKeyNotFound:aKey]
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
    "Created: / 19.6.1998 / 00:53:25 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    "Modified: / 19.6.1998 / 00:54:02 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
removeKey:aKey ifAbsent:exceptionBlock
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
    "remove key (and the value stored under that key) from the
19844
9a7234d4b08c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19469
diff changeset
   453
     receiver; return the value which was stored previously there.
9a7234d4b08c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19469
diff changeset
   454
     If no such element is contained, return the value
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
     from evaluating exceptionBlock"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
    ^ self subclassResponsibility
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
    "Created: / 19.6.1998 / 00:53:58 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
! !
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
21653
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   462
!KeyedCollection methodsFor:'searching'!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   463
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   464
findFirst:aBlock ifNone:exceptionValue
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   465
    "find the index of the first element, for which evaluation of the argument, aBlock returns true;
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   466
     return its index or the value from exceptionValue if none detected.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   467
     This is much like #detect:ifNone:, however, here an INDEX is returned,
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   468
     while #detect:ifNone: returns the element.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   469
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   470
     Here we return the first key for which aBlock matches the value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   471
     Note that there is no order in a Dictionary, so any element is first."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   472
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   473
    self keysAndValuesDo:[:eachKey :eachValue| (aBlock value:eachValue) ifTrue:[^ eachKey]].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   474
    ^ exceptionValue value.
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   475
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   476
    "
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   477
        (KeyValueList withKeys:#('a' 'b' 'c') andValues:#('bla' 'hello' 'hallo'))
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   478
            findFirst:[:v| v first = $h].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   479
    "
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   480
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   481
    "Created: / 16-03-2017 / 17:46:02 / stefan"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   482
!
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   483
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   484
findFirstKey:aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   485
    "find and return the first key, for which evaluation of the argument, aBlock
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   486
     returns true; return nil if none is detected."
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   487
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   488
    self keysDo:[:key |
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   489
        (aBlock value:key) ifTrue:[^ key].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   490
    ].
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   491
    ^ nil
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   492
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   493
    "Created: 8.10.1996 / 22:01:31 / cg"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   494
    "Modified: 8.10.1996 / 22:02:03 / cg"
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   495
! !
baee5890dca8 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21649
diff changeset
   496
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
!KeyedCollection methodsFor:'testing'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
10533
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   499
includesIdenticalKey:aKey
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   500
    "return true, if the argument, aKey is a key in the receiver"
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   501
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   502
    self keysDo:[:elKey | aKey == elKey ifTrue:[^ true]].
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   503
    ^ false
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   504
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   505
    "Created: / 19.6.1998 / 00:55:05 / cg"
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   506
!
04130c197558 changed #includesIdenticalKey:
ca
parents: 9482
diff changeset
   507
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
includesKey:aKey
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    "return true, if the argument, aKey is a key in the receiver"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    self keysDo:[:elKey | aKey = elKey ifTrue:[^ true]].
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
    ^ false
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
    "Created: / 19.6.1998 / 00:55:05 / cg"
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
! !
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
!KeyedCollection class methodsFor:'documentation'!
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
version
19469
e43475084bb5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 17120
diff changeset
   520
    ^ '$Header$'
12667
4297ecfffa96 #values moved up
Claus Gittinger <cg@exept.de>
parents: 11222
diff changeset
   521
!
4297ecfffa96 #values moved up
Claus Gittinger <cg@exept.de>
parents: 11222
diff changeset
   522
4297ecfffa96 #values moved up
Claus Gittinger <cg@exept.de>
parents: 11222
diff changeset
   523
version_CVS
19469
e43475084bb5 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 17120
diff changeset
   524
    ^ '$Header$'
3615
c0f82feaf6a7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
! !
17120
246d9198d84e class: KeyedCollection
Claus Gittinger <cg@exept.de>
parents: 13045
diff changeset
   526