if no unit is given in the readString, assume seconds.
"
COPYRIGHT (c) 1993 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.
"
"{ Package: 'stx:libbasic2' }"
Collection subclass:#MappedCollection
instanceVariableNames:'domain map'
classVariableNames:''
poolDictionaries:''
category:'Collections-Sequenceable'
!
!MappedCollection class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1993 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.
"
!
documentation
"
MappedCollections represent collections of objects that are indirectly indexed by names.
There are really two collections involved: domain and a map. The map maps
between external names and indices into domain, which contains the
real association. In order to work properly, the domain and map objects must
be instances of a subclass of SequenceableCollection or Dictionary.
[author:]
Claus Gittinger
"
! !
!MappedCollection class methodsFor:'instance creation'!
collection:domainCollection map:mapCollection
"return a new MappedCollection"
^ super new setCollection:domainCollection map:mapCollection
!
new
"report an error; mappedCollections may not be created using new"
self error:'use collection:map: to create a MappedCollection'
! !
!MappedCollection methodsFor:'accessing'!
at:key
"retrieve an element"
^ domain at:(map at:key)
"Modified: 2.8.1996 / 21:04:01 / cg"
!
at:key put:anObject
"store an element"
^ domain at:(map at:key) put:anObject
"Modified: 2.8.1996 / 21:04:06 / cg"
!
contents
"return the contents as a bag"
|contents|
contents := Bag new.
map do:[:key | contents add:(domain at:key)].
^ contents
"Modified: 2.8.1996 / 21:04:10 / cg"
! !
!MappedCollection methodsFor:'adding & removing'!
add:anObject
"report an error; mappedCollections cannot add elements (without a key)"
self shouldNotImplement
"Modified: 2.8.1996 / 21:03:57 / cg"
! !
!MappedCollection methodsFor:'copying'!
postCopy
domain := domain copy.
map := map copy
! !
!MappedCollection methodsFor:'enumerating'!
collect:aBlock
"for each element in the receiver, evaluate the argument, aBlock
and return a new collection with the results"
|newCollection|
newCollection := self species new:self size.
self do:[:each | newCollection add:(aBlock value:each)].
^ newCollection
!
do:aBlock
"evaluate the argument, aBlock for each element"
map do:[:mapValue | aBlock value:(domain at:mapValue)].
!
select:aBlock
"return a new collection with all elements from the receiver, for which
the argument aBlock evaluates to true"
|newCollection|
newCollection := self species new:self size.
self do:[:each |
(aBlock value:each) ifTrue:[newCollection add:each].
].
^ newCollection
! !
!MappedCollection methodsFor:'private'!
setCollection:domainCollection map:mapCollection
domain := domainCollection.
map := mapCollection
! !
!MappedCollection methodsFor:'queries'!
size
"return the number of elements in the receiver"
^ map size
!
species
^ domain species
! !
!MappedCollection class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libbasic2/MappedCollection.st,v 1.18 2000-08-22 13:57:10 cg Exp $'
! !