packages/DictionaryStack.st
author james
Wed, 09 Apr 2003 13:38:42 +0200
changeset 1231 2f3a15bfac92
child 1443 6dfdf336b472
permissions -rw-r--r--
initial checkin

"{ Package: 'stx:libbasic3' }"

"{ NameSpace: Packages }"

Object subclass:#DictionaryStack
	instanceVariableNames:'collection'
	classVariableNames:''
	poolDictionaries:''
	category:'Package-helpers'
!


!DictionaryStack class methodsFor:'instance creation'!

new
    ^ self basicNew initialize.
! !

!DictionaryStack methodsFor:'* As yet uncategorized *'!

collect:aBlock
    ^ collection values collect:aBlock
! !

!DictionaryStack methodsFor:'adding & removing'!

atKey:aSymbol 
    
    ^ collection at:aSymbol
!

atKey:aSymbol ifAbsent:aBlock
    
    ^ collection at:aSymbol ifAbsent:aBlock
!

pop
    collection removeKey:collection last key
!

pop:aNumber 

    aNumber timesRepeat:[ self pop].
!

popAt:aKey 
    collection removeKey:aKey.
!

popAt:aKey ifAbsent:aBlock
    collection removeKey:aKey ifAbsent:aBlock.
!

pull
    ^ self pop
!

pull:aNumber
    | col |
    col :=  collection last:aNumber.
    self pop:aNumber.
    ^ col
!

pullAt:aKey 
    ^ collection removeKey:aKey.
!

pullAt:aKey ifAbsent:aBlock
    ^ collection removeKey:aKey ifAbsent:aBlock.
!

push:aPackage 
    
    ^ collection at:aPackage name put:aPackage
!

removeKey:aSymbol 
    
    ^ collection removeKey:aSymbol
!

top
    ^ collection last value
! !

!DictionaryStack methodsFor:'enumerating'!

do:aBlock 
    "goes through all the objects in the collection"
    collection reverseDo:[:anAssociation | aBlock value:anAssociation value]
!

select:aBlock 
    ^ collection values select:aBlock
! !

!DictionaryStack methodsFor:'initialization'!

initialize
    collection := OrderedDictionary new.
! !

!DictionaryStack methodsFor:'queries'!

includes:aPackage
    ^ collection includes:aPackage
!

includesKey:aKey
    ^ (collection includesKey:aKey)
!

isEmpty
    ^ collection isEmpty
!

size
    ^ collection size
! !

!DictionaryStack class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic3/packages/DictionaryStack.st,v 1.1 2003-04-09 11:32:49 james Exp $'
! !