Source for file Magnitude.class.php

Documentation is available at Magnitude.class.php

  1. <?php
  2. /**
  3. * @since 5/4/05
  4. * @package harmoni.primitives.magnitudes
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: Magnitude.class.php,v 1.5 2007/09/04 20:25:27 adamfranco Exp $
  10. *
  11. * @link http://harmoni.sourceforge.net/
  12. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  13. */
  14. require_once(dirname(__FILE__)."/../Objects/SObject.class.php");
  15.  
  16. /**
  17. * Magnitude has methods for dealing with linearly ordered collections.
  18. *
  19. * Subclasses represent dates, times, and numbers.
  20. *
  21. * Example for interval-testing (answers a Boolean):
  22. * $seven->between($five, $ten);
  23. *
  24. * No instance-variables.
  25. *
  26. * @since 5/4/05
  27. * @package harmoni.primitives.magnitudes
  28. *
  29. * @copyright Copyright &copy; 2005, Middlebury College
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  31. *
  32. * @version $Id: Magnitude.class.php,v 1.5 2007/09/04 20:25:27 adamfranco Exp $
  33. *
  34. * @link http://harmoni.sourceforge.net/
  35. * @author Adam Franco <adam AT adamfranco DOT com> <afranco AT middlebury DOT edu>
  36. */
  37. class Magnitude
  38. extends SObject
  39. {
  40.  
  41. /**
  42. * Test if this is less than aMagnitude.
  43. *
  44. * @param object Magnitude $aMagnitude
  45. * @return boolean
  46. * @access public
  47. * @since 5/4/05
  48. */
  49. function isLessThan ( $aMagnitude ) {
  50. die("Method ".__FUNCTION__." in class ".__CLASS__
  51. ." should have been overridden by a child class.");
  52. }
  53. /**
  54. * Test if this is equal to aMagnitude.
  55. *
  56. * @param object Magnitude $aMagnitude
  57. * @return boolean
  58. * @access public
  59. * @since 5/4/05
  60. */
  61. function isEqualTo ( $aMagnitude ) {
  62. die("Method ".__FUNCTION__." in class ".__CLASS__
  63. ." should have been overridden by a child class.");
  64. }
  65. /**
  66. * Test if this is greater than aMagnitude.
  67. *
  68. * @param object Magnitude $aMagnitude
  69. * @return boolean
  70. * @access public
  71. * @since 5/3/05
  72. */
  73. function isGreaterThan ( $aMagnitude ) {
  74. return $aMagnitude->isLessThan($this);
  75. }
  76. /**
  77. * Test if this is greater than aMagnitude.
  78. *
  79. * @param object Magnitude $aMagnitude
  80. * @return boolean
  81. * @access public
  82. * @since 5/3/05
  83. */
  84. function isLessThanOrEqualTo ( $aMagnitude ) {
  85. return ! $this->isGreaterThan($aMagnitude);
  86. }
  87. /**
  88. * Test if this is greater than aMagnitude.
  89. *
  90. * @param object Magnitude $aMagnitude
  91. * @return boolean
  92. * @access public
  93. * @since 5/3/05
  94. */
  95. function isGreaterThanOrEqualTo ( $aMagnitude ) {
  96. return ! $this->isLessThan($aMagnitude);
  97. }
  98. /**
  99. * Answer whether the receiver is less than or equal to the argument, max,
  100. * and greater than or equal to the argument, min.
  101. *
  102. * @param object Magnitude $min
  103. * @param object Magnitude $max
  104. * @return boolean
  105. * @access public
  106. * @since 5/4/05
  107. */
  108. function isBetween ( $min, $max ) {
  109. return ($this->isGreaterThanOrEqualTo($min) && $this->isLessThanOrEqualTo($max));
  110. }
  111. /**
  112. * Answer the receiver or the argument, whichever has the greater
  113. * magnitude.
  114. *
  115. * @param object Magnitude $aMagnitude
  116. * @return object Magnitude
  117. * @access public
  118. * @since 5/4/05
  119. */
  120. function max ( $aMagnitude ) {
  121. if ($this->isGreaterThan($aMagnitude))
  122. return $this;
  123. else
  124. return $aMagnitude;
  125. }
  126. /**
  127. * Answer the receiver or the argument, whichever has the lesser
  128. * magnitude.
  129. *
  130. * @param object Magnitude $aMagnitude
  131. * @return object Magnitude
  132. * @access public
  133. * @since 5/4/05
  134. */
  135. function min ( $aMagnitude ) {
  136. if ($this->isLessThan($aMagnitude))
  137. return $this;
  138. else
  139. return $aMagnitude;
  140. }
  141. }
  142.  
  143. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:56 -0400 by phpDocumentor 1.3.0RC3