VirtualDictionary.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4549 a9d2d65fda08
child 5387 64a6ef96c06f
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:

"{ Encoding: utf8 }"

"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

Collection subclass:#VirtualDictionary
	instanceVariableNames:'fetchBlock'
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Unordered'
!

!VirtualDictionary class methodsFor:'documentation'!

documentation
"
    a collection which looks like a (read-only) dictionary to the outside,
    but invokes a pluggable fetchBlock to retrieve keys.

    [author:]
        cg

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!VirtualDictionary methodsFor:'accessing'!

at:aKey
    ^ self at:aKey ifAbsent:nil
!

at:aKey ifAbsent:exceptionValue
    |value|

    value := fetchBlock value:aKey.
    value isNil ifTrue:[
        ^ exceptionValue value
    ].
    ^ value
!

fetchBlock:something
    fetchBlock := something.
! !

!VirtualDictionary methodsFor:'queries'!

includesKey:aKey
    ^ (fetchBlock value:aKey) notNil
! !

!VirtualDictionary class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !