eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Magnitude':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Magnitude


Inheritance:

   Object
   |
   +--Magnitude
      |
      +--AbstractTime
      |
      +--ArithmeticValue
      |
      +--Character
      |
      +--Date
      |
      +--LookupKey
      |
      +--MiniLogger::Severity
      |
      +--SyntaxElement

Package:
stx:libbasic
Category:
Magnitude-General
Version:
rev: 1.35 date: 2017/06/19 13:04:52
user: mawalch
file: Magnitude.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


This is an abstract class defining common methods for
Objects which can be compared by a kind of less-than relation.


Class protocol:

queries
o  isAbstract
Return if this class is an abstract class.
True is returned for Magnitude here; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

Compatibility-Squeak
o  min: aMin max: aMax
similar to clampBetween:and:

comparing
o  < aMagnitude
Compare the receiver with the argument and return true if the
receiver is less than the argument. Otherwise return false.

** This method raises an error - it must be redefined in concrete classes **

o  <= aMagnitude
return true, if the argument is greater or equal than the receiver

o  = aMagnitude
Compare the receiver with the argument and return true if the
receiver is equal to the argument. Otherwise return false.

** This method raises an error - it must be redefined in concrete classes **

o  > aMagnitude
return true, if the argument is less than the receiver

o  >= aMagnitude
return true, if the argument is less or equal than the receiver

o  clampBetween: min and: max
return the receiver if it is between min .. max,
or min if it is less than min, or max if it is greater than max.
This is only a lazy-typers helper for: ((something min:max) max:min)
usage example(s):
     1 clampBetween:2 and:5  
     3 clampBetween:2 and:5  
     6 clampBetween:2 and:5  

o  compare: arg ifLess: lessBlock ifEqual: equalBlock ifGreater: greaterBlock
three-way compare - thanks to Self for this idea.
Can be redefined in subclasses to do it with a single comparison if
comparison is expensive.

o  compareWith: arg
Compare the receiver with the argument and return 1 if the receiver is
greater, 0 if equal and -1 if less than the argument.
usage example(s):
     100 compareWith: 101

o  hash
instances, for which #= answers true must answer the same hash

** This method raises an error - it must be redefined in concrete classes **

o  max: aMagnitude
return the receiver or the argument, whichever has greater magnitude
usage example(s):
     1 max: 2
     1 max: 2.0
     2.0 max: 1.0
     2.0 max: 2

o  min: aMagnitude
return the receiver or the argument, whichever has lesser magnitude
usage example(s):
     1 min: 2
     1 min: 2.0
     2.0 min: 1.0
     2.0 min: 2

iteration
o  downTo: stop by: step do: aBlock
For each element of the interval from the receiver down to the argument stop,
decrementing by step, evaluate aBlock, passing the number as argument.
usage example(s):
     10 downTo:1 by:2 do:[:i | Transcript showCR:i].

o  downTo: stop do: aBlock
For each element of the interval from the receiver down to the argument stop,
evaluate aBlock, passing the number as argument.
usage example(s):
     10 downTo:1 do:[:i | Transcript showCR:i].
     $d downTo:$a do:[:i | Transcript showCR:i].

o  to: stop by: incr do: aBlock
For each element of the interval from the receiver up to the argument stop, incrementing
by step, evaluate aBlock passing the element as argument.

Not all Magnitudes do implement #negative and #+ however,
so should this method go to ArithmethicValue?

Only use #<, to speed up things (for subclasses only defining #<)
usage example(s):
     1 to:10 do:[:i | Transcript showCR:i].
     1 to:10 by:2 do:[:i | Transcript showCR:i].
     $a to:$z by:2 do:[:i | Transcript showCR:i].
     10 to:1 by:-1 do:[:i | Transcript showCR:i].

o  to: stop by: incr doWithBreak: aBlock
For each element of the interval from the receiver up to the argument stop, incrementing
by step, evaluate aBlock passing the element as argument.
Pass a break argument, to allow for premature exit of the loop.
usage example(s):
     1 to:100 by:5 doWithBreak:[:index :break |
        Transcript showCR:index printString.
        index > 50 ifTrue:[
            break value
        ].
     ]

o  to: stop by: incr doWithExit: aBlock
For each element of the interval from the receiver up to the argument stop, incrementing
by step, evaluate aBlock passing the element as argument.
Pass a break argument, to allow for premature exit of the loop.
usage example(s):
     1 to:100 by:5 doWithExit:[:index :exit |
        Transcript showCR:index printString.
        index > 50 ifTrue:[
            exit value:nil
        ].
     ]

o  to: stop count: aBlock
same as (self to:stop) count:aBlock
usage example(s):
     1 to:10 count:[:n | n even]

o  to: stop do: aBlock
For each element of the interval from the receiver up to the argument stop,
evaluate aBlock, passing the number as argument.
usage example(s):
     1 to:10 do:[:i | Transcript showCR:i].
     1 to:10 by:2 do:[:i | Transcript showCR:i].
     10 to:1 by:-1 do:[:i | Transcript showCR:i].

o  to: stop do: aBlock separatedBy: actionBetween
For each element of the interval from the receiver up to the argument stop,
evaluate aBlock, passing the number as argument.
Between each, evaluate actionBetween (but not before the first and not after the last)
usage example(s):
     1 to:10 
        do:[:i | Transcript show:i] 
        separatedBy:[ Transcript show:', '].

o  to: stop doWithBreak: aBlock
For each element of the interval from the receiver up to the argument stop,
evaluate aBlock, passing the number as argument.
Pass a break argument, to allow for premature exit of the loop.
usage example(s):
     1 to:10 doWithBreak:[:index :break |
        Transcript showCR:index printString.
        index > 5 ifTrue:[
            break value
        ].
     ]

o  to: stop doWithExit: aBlock
For each element of the interval from the receiver up to the argument stop,
evaluate aBlock, passing the number as argument.
Passes an additional exit object, which can be used to leave
the loop early, by sending it a #value: message.
Returns nil or the value passed to the exit>>value: message.

Notice, that this is different to a return statement in the block,
which returns from the enclosed method, NOT only from the block.
usage example(s):
     1 to:10 doWithExit:[:index :exit |
        index == 5 ifTrue:[
            exit value:nil
        ].
        Transcript showCR:index.
     ].

testing
o  between: min and: max
return true if the receiver is greater than or equal to the argument min
and less than or equal to the argument max
usage example(s):
     1.2 between:1 and:2
     (3/2) between:1 and:2
     (3/2) between:0 and:1

o  in: anInterval
return whether the receiver is within the interval bounds
usage example(s):
     1.2 in:(1 to: 2)
     (3/2) in:(1 to: 2)
     (3/2) in:(0 to: 1)



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Thu, 19 Jul 2018 06:10:33 GMT