|
Class: MappedCollection
Object
|
+--Collection
|
+--MappedCollection
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.25
date: 2019/08/12 08:48:19
- user: cg
- file: MappedCollection.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
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.
The valueDomain of the map must be the keyDomain of the domain collection.
i.e.
mappedCollection at:k ==> domain at:(map at:k)
instance creation
-
collection: domainCollection map: mapCollection
-
return a new MappedCollection
-
new
-
report an error; mappedCollections may not be created using new
accessing
-
at: key
-
retrieve an element
-
at: key put: anObject
-
store an element
-
contents
-
return the contents as a bag
adding & removing
-
add: anObject
-
report an error; mappedCollections cannot add elements (without a key)
copying-private
-
postCopy
-
enumerating
-
do: aBlock
-
evaluate the argument, aBlock for each element
private
-
setCollection: domainCollection map: mapCollection
-
queries
-
isFixedSize
-
return true if the receiver cannot grow
-
size
-
return the number of elements in the receiver
-
species
-
return the type of collection to be returned by collect, select etc.
-
speciesForAdding
-
like species, but redefined for collections which cannot grow easily.
Used by functions which create a growing collection
(see collect:with:, for example)
|mapped keyMapping|
keyMapping := Dictionary new
at:'uno' put:1;
at:'due' put:2;
at:'tre' put:3;
at:'quattro' put:4;
yourself.
mapped := MappedCollection
collection:#(one two three four)
map:keyMapping.
mapped at:'tre'.
mapped select:[:each| each ~= 'two']
|
|