Source for file Integer.class.php

Documentation is available at Integer.class.php

  1. <?php
  2.  
  3. /**
  4. * @since 7/14/05
  5. * @package harmoni.primitives.numbers
  6. *
  7. * @copyright Copyright &copy; 2005, Middlebury College
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  9. *
  10. * @version $Id: Integer.class.php,v 1.6 2007/09/04 20:25:28 adamfranco Exp $
  11. */
  12.  
  13. require_once(dirname(__FILE__)."/Number.class.php");
  14.  
  15. /**
  16. * A simple Integer data type.
  17. *
  18. * @package harmoni.primitives.numbers
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: Integer.class.php,v 1.6 2007/09/04 20:25:28 adamfranco Exp $
  24. */
  25. class Integer
  26. extends Number
  27. {
  28. /*******************************************************
  29. * Class Methods - Instance Creation
  30. *********************************************************/
  31.  
  32.  
  33. /**
  34. * Answer a new object with the value specified
  35. *
  36. * @param mixed $value
  37. * @param optional string $class The class to instantiate. Do NOT use outside
  38. * of this package.
  39. * @return object Integer
  40. * @access public
  41. * @since 7/14/05
  42. */
  43. function withValue ( $value, $class = 'Integer') {
  44. return parent::withValue($value, $class);
  45. }
  46.  
  47. /**
  48. * Answer a new object with the value specified
  49. *
  50. * @param string $string a string representation of the object
  51. * @return object Double
  52. * @access public
  53. * @since 3/14/06
  54. */
  55. function fromString ($string, $class = 'Integer') {
  56. return parent::fromString($string, $class);
  57. }
  58.  
  59. /**
  60. * Answer a new object with the value zero
  61. *
  62. * @param optional string $class The class to instantiate. Do NOT use outside
  63. * of this package.
  64. * @return object Integer
  65. * @access public
  66. * @since 7/14/05
  67. */
  68. function zero ( $class = 'Integer') {
  69. return parent::zero($class);
  70. }
  71. /*******************************************************
  72. * Instance Methods - Arithmatic
  73. *********************************************************/
  74.  
  75. /**
  76. * Answer the sum of the receiver and aNumber.
  77. *
  78. * @param object Number $aNumber
  79. * @return object Number
  80. * @access public
  81. * @since 7/14/05
  82. */
  83. function plus ( $aNumber ) {
  84. if (!(strtolower($class) == strtolower('Integer')
  85. || is_subclass_of(new $class, 'Integer')))
  86. {
  87. $obj = Integer::withValue($this->value() + $aNumber->value());
  88. return $obj;
  89. } else {
  90. $obj = Float::withValue($this->value() + $aNumber->value());
  91. return $obj;
  92. }
  93. }
  94. /**
  95. * Answer the result of multiplying the receiver and aNumber.
  96. *
  97. * @param object Number $aNumber
  98. * @return object Number
  99. * @access public
  100. * @since 7/14/05
  101. */
  102. function multipliedBy ( $aNumber ) {
  103. if (!(strtolower($class) == strtolower('Integer')
  104. || is_subclass_of(new $class, 'Integer')))
  105. {
  106. $obj = Integer::withValue($this->value() * $aNumber->value());
  107. return $obj;
  108. } else {
  109. $obj = Float::withValue($this->value() * $aNumber->value());
  110. return $obj;
  111. }
  112. }
  113. /**
  114. * Answer the result of dividing the receiver and aNumber.
  115. *
  116. * @param object Number $aNumber
  117. * @return object Number
  118. * @access public
  119. * @since 7/14/05
  120. */
  121. function dividedBy ( $aNumber ) {
  122. $obj = Float::withValue($this->value() / $aNumber->value());
  123. return $obj;
  124. }
  125. /*******************************************************
  126. * Instance Methods - Private
  127. *********************************************************/
  128.  
  129. /**
  130. * Set the internal value to a PHP primitive.
  131. *
  132. * @param mixed $value
  133. * @return void
  134. * @access private
  135. * @since 7/14/05
  136. */
  137. function _setValue ( $value ) {
  138. $this->_value = intval($value);
  139. }
  140. }

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