Magnitude.st
changeset 1 a27a279701f8
child 3 24d81bf47225
equal deleted inserted replaced
0:aa2498ef6470 1:a27a279701f8
       
     1 "
       
     2  COPYRIGHT (c) 1988-93 by Claus Gittinger
       
     3               All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 Object subclass:#Magnitude
       
    14        instanceVariableNames:''
       
    15        classVariableNames:''
       
    16        poolDictionaries:''
       
    17        category:'Magnitude-General'
       
    18 !
       
    19 
       
    20 Magnitude comment:'
       
    21 
       
    22 COPYRIGHT (c) 1988-93 by Claus Gittinger
       
    23               All Rights Reserved
       
    24 
       
    25 This is an abstract class definining common methods for
       
    26 Objects which can be compared by a kind of greater realation.
       
    27 
       
    28 %W% %E%
       
    29 '!
       
    30 
       
    31 !Magnitude methodsFor:'comparing'!
       
    32 
       
    33 > aMagnitude
       
    34     "Compare the receiver with the argument and return true if the
       
    35      receiver is greater than the argument. Otherwise return false."
       
    36 
       
    37     ^ self subclassResponsibility
       
    38 !
       
    39 
       
    40 = aMagnitude
       
    41     "Compare the receiver with the argument and return true if the
       
    42      receiver is equal to the argument. Otherwise return false."
       
    43 
       
    44     ^ self subclassResponsibility
       
    45 !
       
    46 
       
    47 <= aMagnitude
       
    48     "Compare the receiver with the argument and return true if the
       
    49      receiver is less than or equal to the argument. Otherwise return false."
       
    50 
       
    51     ^ (self > aMagnitude) not
       
    52 !
       
    53 
       
    54 < aMagnitude
       
    55     "Compare the receiver with the argument and return true if the
       
    56      receiver is less than the argument. Otherwise return false."
       
    57 
       
    58     ^ (aMagnitude > self)
       
    59 !
       
    60 
       
    61 >= aMagnitude
       
    62     "Compare the receiver with the argument and return true if the
       
    63      receiver is greater than or equal to the argument.
       
    64      Otherwise return false."
       
    65 
       
    66     ^ (aMagnitude > self) not
       
    67 ! !
       
    68 
       
    69 !Magnitude methodsFor:'testing'!
       
    70 
       
    71 between:min and:max
       
    72     "return whether the receiver is less than or equal to the argument max
       
    73      and greater than or equal to the argument min."
       
    74 
       
    75     (self < min) ifTrue:[^ false].
       
    76     (self > max) ifTrue:[^ false].
       
    77     ^ true
       
    78 !
       
    79 
       
    80 in:anInterval
       
    81     "return whether the receiver is within the interval bounds"
       
    82 
       
    83     (self < anInterval start) ifTrue:[^ false].
       
    84     (self > anInterval stop) ifTrue:[^ false].
       
    85     ^ true
       
    86 ! !
       
    87 
       
    88 !Magnitude methodsFor:'misc'!
       
    89 
       
    90 min:aMagnitude
       
    91     "return the receiver or the argument, whichever has lesser magnitude"
       
    92 
       
    93     (self < aMagnitude) ifTrue:[^ self].
       
    94     ^ aMagnitude
       
    95 !
       
    96 
       
    97 max:aMagnitude
       
    98     "return the receiver or the argument, whichever has greater magnitude"
       
    99 
       
   100     (self > aMagnitude) ifTrue:[^ self].
       
   101     ^ aMagnitude
       
   102 ! !