MappedCollection.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 02:18:58 +0100
changeset 123 4a1b75bf25a8
parent 112 3e18f2cfe430
child 131 19e548711b65
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
     3
	      All Rights Reserved
1
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
claus
parents:
diff changeset
    12
19
c25a529288cf *** empty log message ***
claus
parents: 2
diff changeset
    13
Collection subclass:#MappedCollection
123
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    14
	 instanceVariableNames:'domain map'
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    15
	 classVariableNames:''
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    16
	 poolDictionaries:''
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    17
	 category:'Collections-Sequenceable'
1
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
28
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    20
!MappedCollection class methodsFor:'documentation'!
1
claus
parents:
diff changeset
    21
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    22
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    23
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
    25
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    26
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    27
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    28
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    30
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    31
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    32
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    33
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    34
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
    35
28
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    36
documentation
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    37
"
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    38
    MappedCollections represent collections of objects that are indirectly indexed by names.
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    39
    There are really two collections involved: domain and a map.  The map maps
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    40
    between external names and indices into domain, which contains the
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    41
    real association.  In order to work properly, the domain and map objects must
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    42
    be instances of a subclass of SequenceableCollection or Dictionary. 
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    43
"
123
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    44
!
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    45
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    46
version
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    47
    ^ '$Header: /cvs/stx/stx/libbasic2/MappedCollection.st,v 1.13 1995-11-23 01:18:58 cg Exp $'
28
350f8e9493a4 *** empty log message ***
claus
parents: 19
diff changeset
    48
! !
1
claus
parents:
diff changeset
    49
claus
parents:
diff changeset
    50
!MappedCollection class methodsFor:'instance creation'!
claus
parents:
diff changeset
    51
claus
parents:
diff changeset
    52
collection:domainCollection map:mapCollection
claus
parents:
diff changeset
    53
    "return a new MappedCollection"
claus
parents:
diff changeset
    54
claus
parents:
diff changeset
    55
    ^ super new setCollection:domainCollection map:mapCollection
claus
parents:
diff changeset
    56
!
claus
parents:
diff changeset
    57
claus
parents:
diff changeset
    58
new
claus
parents:
diff changeset
    59
    "report an error; mappedCollections may not be created using new"
claus
parents:
diff changeset
    60
claus
parents:
diff changeset
    61
    self error:'use collection:map: to create a MappedCollection'
claus
parents:
diff changeset
    62
! !
claus
parents:
diff changeset
    63
claus
parents:
diff changeset
    64
!MappedCollection methodsFor:'accessing'!
claus
parents:
diff changeset
    65
123
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    66
add:anObject
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    67
    self shouldNotImplement
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    68
!
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    69
1
claus
parents:
diff changeset
    70
at:key
claus
parents:
diff changeset
    71
    ^ domain at:(map at:key)
claus
parents:
diff changeset
    72
!
claus
parents:
diff changeset
    73
claus
parents:
diff changeset
    74
at:key put:anObject
claus
parents:
diff changeset
    75
    ^ domain at:(map at:key) put:anObject
claus
parents:
diff changeset
    76
!
claus
parents:
diff changeset
    77
claus
parents:
diff changeset
    78
contents
claus
parents:
diff changeset
    79
    |contents|
claus
parents:
diff changeset
    80
    contents := Bag new.
49
ec5828a97593 *** empty log message ***
claus
parents: 48
diff changeset
    81
    map do:[:key | contents add:(domain at:key)].
1
claus
parents:
diff changeset
    82
    ^ contents
claus
parents:
diff changeset
    83
! !
claus
parents:
diff changeset
    84
42
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    85
!MappedCollection methodsFor:'copying'!
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    86
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    87
postCopy
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    88
    domain := domain copy.
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    89
    map := map copy
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    90
! !
506596f9a1a8 *** empty log message ***
claus
parents: 36
diff changeset
    91
1
claus
parents:
diff changeset
    92
!MappedCollection methodsFor:'enumerating'!
claus
parents:
diff changeset
    93
claus
parents:
diff changeset
    94
collect:aBlock
claus
parents:
diff changeset
    95
    "for each element in the receiver, evaluate the argument, aBlock
claus
parents:
diff changeset
    96
     and return a new collection with the results"
claus
parents:
diff changeset
    97
claus
parents:
diff changeset
    98
    |newCollection|
claus
parents:
diff changeset
    99
claus
parents:
diff changeset
   100
    newCollection := self species new:self size.
claus
parents:
diff changeset
   101
    self do:[:each | newCollection add:(aBlock value:each)].
claus
parents:
diff changeset
   102
    ^ newCollection
claus
parents:
diff changeset
   103
!
claus
parents:
diff changeset
   104
123
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   105
do:aBlock
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   106
    "evaluate the argument, aBlock for each element"
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   107
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   108
    map do:[:mapValue | aBlock value:(domain at:mapValue)].
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   109
!
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   110
1
claus
parents:
diff changeset
   111
select:aBlock
claus
parents:
diff changeset
   112
    "return a new collection with all elements from the receiver, for which
claus
parents:
diff changeset
   113
     the argument aBlock evaluates to true"
claus
parents:
diff changeset
   114
claus
parents:
diff changeset
   115
    |newCollection|
claus
parents:
diff changeset
   116
claus
parents:
diff changeset
   117
    newCollection := self species new:self size.
claus
parents:
diff changeset
   118
    self do:[:each |
48
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
   119
	(aBlock value:each) ifTrue:[newCollection add:each].
1
claus
parents:
diff changeset
   120
    ].
claus
parents:
diff changeset
   121
    ^ newCollection
claus
parents:
diff changeset
   122
! !
claus
parents:
diff changeset
   123
claus
parents:
diff changeset
   124
!MappedCollection methodsFor:'private'!
claus
parents:
diff changeset
   125
claus
parents:
diff changeset
   126
setCollection:domainCollection map:mapCollection
claus
parents:
diff changeset
   127
    domain := domainCollection.
claus
parents:
diff changeset
   128
    map := mapCollection
48
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
   129
! !
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
   130
18b9353c9d07 *** empty log message ***
claus
parents: 42
diff changeset
   131
!MappedCollection methodsFor:'queries'!
1
claus
parents:
diff changeset
   132
claus
parents:
diff changeset
   133
species
claus
parents:
diff changeset
   134
    ^ domain species
claus
parents:
diff changeset
   135
! !
123
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   136
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   137
!MappedCollection methodsFor:'testing'!
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   138
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   139
size
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   140
    "return the number of elements in the receiver"
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   141
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   142
    ^ map size
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   143
! !
4a1b75bf25a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   144