Count.st


Model subclass: #Count
	instanceVariableNames: 'value resetValue '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Counts'!

!Count methodsFor: 'initialize-release'!

initialize "Initialize my value to the reset value"

self reset! !

!Count methodsFor: 'accessing'!

id "Return my Identification number " ^1!

resetValue "Return my resetValue "

^resetValue!

resetValue: aValue "Set my resetValue to aValue"

resetValue := aValue. self changed: #resetValue!

value "Return my value " ^value!

value: aValue "Set my value to aValue. Notify dependents I've changed. "

value := aValue. self changed: #value! !

!Count methodsFor: 'counting'!

decrement "Decrement my value. Subclasses must implement."!

increment "Increment my value. Subclasses must implement."!

reset "Restore my value to its original state."

self value: resetValue! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Count class instanceVariableNames: ''!

!Count class methodsFor: 'instance-creation'!

new "Create a new one of me and initialize it"

^super new initialize! ! Count subclass: #DateCount instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Counts'!

!DateCount methodsFor: 'initialize-release'!

initialize resetValue := Date today. super initialize! !

!DateCount methodsFor: 'counting'!

decrement "Decrement my value to the preceeding date."

^self value: (value subtractDays: 1)!

increment "Increment my value to the next date."

^self value: (value addDays: 1)! ! Count subclass: #SequenceCount instanceVariableNames: 'sequence position ' classVariableNames: '' poolDictionaries: '' category: 'Counts'!

!SequenceCount methodsFor: 'initialize-release'!

initialize "Initialize the sequence and the sequence pointer. I can't initialize my resetValue because the sequence is empty"

position := 1. sequence := OrderedCollection new. super initialize!

initializeResetValue sequence isEmpty ifTrue: [^nil]. resetValue := sequence first. self reset! !

!SequenceCount methodsFor: 'counting'!

decrement "If my sequence is empty, don't do anytihng. Otherwise, back up my index pointer. Don't go past the first item in the sequence."

sequence isEmpty ifTrue: [^self]. position := position - 1 max: 1. self value: (sequence at: position)!

increment "If my sequence is empty, don't do anytihng. Otherwise, advance my index pointer. Don't go past the last item in the sequence."

sequence isEmpty ifTrue: [^self]. position := position + 1 min: sequence size. self value: (sequence at: position)!

reset "Reset my index pointer, then perform my generalization's reset method."

position := 1. super reset! !

!SequenceCount methodsFor: 'sequence accessing'!

setSequence: aCollection "Set my sequence to aCollection. Now I can initialize my resetValue"

sequence := aCollection. self initializeResetValue! ! Count subclass: #IntegerCount instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Counts'!

!IntegerCount methodsFor: 'initialize-release'!

initialize resetValue := 0. super initialize! !

!IntegerCount methodsFor: 'counting'!

decrement "Decrement myself ."

self value: value - 1!

increment "Increment myself ."

self value: value + 1! !

!IntegerCount methodsFor: 'converting'!

asBase: aBase "Return a string representing my value in the number base, aBase."

^value printStringRadix: aBase! ! Count subclass: #ASCIICount instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Counts'!

!ASCIICount methodsFor: 'prototypes'!

class "Answer the object which is the receiver's class."

self primitiveFailed!

doesNotUnderstand: aMessage "The default behavior is to create a Notifier containing the appropriate message and to allow the user to open a Debugger. Subclasses can override this message in order to modify this behavior."

(Object canUnderstand: aMessage selector) ifTrue: [self class copy: aMessage selector from: Object. ^self perform: aMessage selector withArguments: aMessage arguments].

^Object messageNotUnderstoodSignal raiseRequestWith: aMessage errorString: 'Message not understood: ' , aMessage selector! !

!ASCIICount methodsFor: 'initialize-release'!

initialize resetValue := $a. super initialize! !

!ASCIICount methodsFor: 'counting'!

decrement "Set my value to the character with the previous ASCII value. Check for invalid values and use wraparound when the value becomes unprintable."

| newAsciiValue | newAsciiValue := value asInteger < 33 ifTrue: [126] ifFalse: [value asInteger - 1]. ^self value: (Character value: newAsciiValue)! increment "Set my value to the character with the next ASCII value. Check for invalid values and use wraparound when the value becomes unprintable." | newAsciiValue | newAsciiValue := value asInteger > 125 ifTrue: [33] ifFalse: [value asInteger + 1]. ^self value: (Character value: newAsciiValue)! !


News Page | CS2390 Sum'97 Home Page | MMC-CaMILE | STABLE
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 7/16/97; 10:15:26 AM