home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_200
/
232_01
/
interval.st
< prev
next >
Wrap
Text File
|
1987-06-17
|
2KB
|
58 lines
Class Interval :SequenceableCollection
| lower upper step current |
[
from: lowerBound to: upperBound by: stepSize
current <- lower <- lowerBound.
upper <- upperBound.
step <- stepSize
| size
^ ((step strictlyPositive)
ifTrue: [upper < lower]
ifFalse: [lower < upper] )
ifTrue: [ 0 ]
ifFalse: [upper - lower // step + 1]
| inRange: value
^ (step strictlyPositive)
ifTrue: [(value >= lower) and: [value <= upper]]
ifFalse: [(value >= upper) and: [value <= lower]]
| first
current <- lower.
^ (self inRange: current) ifTrue: [current]
| next
current <- current + step.
^ (self inRange: current) ifTrue: [current]
| at: index ifAbsent: exceptionBlock | val |
val <- lower + (step * (index - 1)).
^ (self inRange: val)
ifTrue: [ val ]
ifFalse: [exceptionBlock value]
| printString
^ 'Interval ', lower printString , ' to ',
upper printString , ' by ' , step printString
| coerce: newcollection
^ newcollection asArray
| at: index put: val
^ self error: 'cannot store into Interval'
| add: val
^ self error: 'cannot store into Interval'
| removeKey: key ifAbsent: exceptionBlock
self error: 'cannot remove from Interval'.
^ exceptionBlock value
|
deepCopy
^ lower to: upper by: step
|
shallowCopy
^ lower to: upper by: step
]