MathUtilities.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. * Created by dan on 6/14/17.
  3. */
  4. public class MathUtilities {
  5. /**
  6. * @param baseValue starting value
  7. * @param difference value to add to starting value
  8. * @return sum of `baseValue` and `difference`
  9. */
  10. public Integer add(int baseValue, int difference) {
  11. return baseValue + difference;
  12. }
  13. /**
  14. * @param baseValue starting value
  15. * @param difference value to add to starting value
  16. * @return sum of `baseValue` and `difference`
  17. */
  18. public Long add(long baseValue, long difference) {
  19. return baseValue + difference;
  20. }
  21. /**
  22. * @param baseValue starting value
  23. * @param difference value to add to starting value
  24. * @return sum of `baseValue` and `difference`
  25. */
  26. public Short add(short baseValue, short difference) {
  27. short sum = (short)(baseValue + difference);
  28. return sum;
  29. }
  30. /**
  31. * @param baseValue starting value
  32. * @param difference value to add to starting value
  33. * @return sum of `baseValue` and `difference`
  34. */
  35. public Byte add(byte baseValue, byte difference) {
  36. byte sum = (byte)(baseValue + difference);
  37. return sum;
  38. }
  39. /**
  40. * @param baseValue starting value
  41. * @param difference value to add to starting value
  42. * @return sum of `baseValue` and `difference`
  43. */
  44. public Float add(float baseValue, float difference) {
  45. float sum = (float)(baseValue + difference);
  46. return sum;
  47. }
  48. /**
  49. * @param baseValue starting value
  50. * @param difference value to add to starting value
  51. * @return sum of `baseValue` and `difference`
  52. */
  53. public Double add(double baseValue, double difference) {
  54. double sum = (double)(baseValue + difference);
  55. return sum;
  56. }
  57. /**
  58. * @param baseValue starting value
  59. * @param difference value to subtract from starting value
  60. * @return difference between `baseValue` and `difference`
  61. */
  62. public Integer subtract(int baseValue, int difference) {
  63. return baseValue - difference;
  64. }
  65. /**
  66. * @param baseValue starting value
  67. * @param difference value to subtract from starting value
  68. * @return difference between `baseValue` and `difference`
  69. */
  70. public Long subtract(long baseValue, long difference) {
  71. return baseValue - difference;
  72. }
  73. /**
  74. * @param baseValue starting value
  75. * @param difference value to subtract from starting value
  76. * @return difference between `baseValue` and `difference`
  77. */
  78. public Short subtract(short baseValue, short difference) {
  79. return (short)(baseValue - difference);
  80. }
  81. /**
  82. * @param baseValue starting value
  83. * @param difference value to subtract from starting value
  84. * @return difference between `baseValue` and `difference`
  85. */
  86. public Byte subtract(byte baseValue, byte difference) {
  87. return (byte)(baseValue - difference);
  88. }
  89. /**
  90. * @param baseValue starting value
  91. * @param difference value to subtract from starting value
  92. * @return difference between `baseValue` and `difference`
  93. */
  94. public Float subtract(float baseValue, float difference) {
  95. return (float)(baseValue - difference);
  96. }
  97. /**
  98. * @param baseValue starting value
  99. * @param difference value to subtract from starting value
  100. * @return difference between `baseValue` and `difference`
  101. */
  102. public Double subtract(double baseValue, double difference) {
  103. return (double)(baseValue - difference);
  104. }
  105. /**
  106. * @param dividend value to be divided
  107. * @param divisor value to divide by
  108. * @return division of `dividend` by `divisor
  109. */
  110. public Integer divide(int dividend, int divisor) {
  111. return dividend / divisor;
  112. }
  113. /**
  114. * @param dividend value to be divided
  115. * @param divisor value to divide by
  116. * @return division of `dividend` by `divisor
  117. */
  118. public Long divide(long dividend, long divisor) {
  119. return dividend / divisor;
  120. }
  121. /**
  122. * @param dividend value to be divided
  123. * @param divisor value to divide by
  124. * @return division of `dividend` by `divisor
  125. */
  126. public Short divide(short dividend, short divisor) {
  127. return (short)(dividend / divisor);
  128. }
  129. /**
  130. * @param dividend value to be divided
  131. * @param divisor value to divide by
  132. * @return division of `dividend` by `divisor
  133. */
  134. public Byte divide(byte dividend, byte divisor) {
  135. return (byte)(dividend / divisor);
  136. }
  137. /**
  138. * @param dividend value to be divided
  139. * @param divisor value to divide by
  140. * @return division of `dividend` by `divisor
  141. */
  142. public Float divide(float dividend, float divisor) {
  143. return (float)(dividend / divisor);
  144. }
  145. /**
  146. * @param dividend value to be divided
  147. * @param divisor value to divide by
  148. * @return division of `dividend` by `divisor
  149. */
  150. public Double divide(double dividend, double divisor) {
  151. return (double)(dividend / divisor);
  152. }
  153. /**
  154. * @param multiplicand value to be multiplied
  155. * @param multiplier value to multiply by
  156. * @return product of `multiplicand` by `multiplier`
  157. */
  158. public Integer multiply(int multiplicand, int multiplier) {
  159. return multiplicand * multiplier;
  160. }
  161. /**
  162. * @param multiplicand value to be multiplied
  163. * @param multiplier value to multiply by
  164. * @return product of `multiplicand` by `multiplier`
  165. */
  166. public Long multiply(long multiplicand, long multiplier) {
  167. return multiplicand * multiplier;
  168. }
  169. /**
  170. * @param multiplicand value to be multiplied
  171. * @param multiplier value to multiply by
  172. * @return product of `multiplicand` by `multiplier`
  173. */
  174. public Short multiply(short multiplicand, short multiplier) {
  175. return (short)(multiplicand * multiplier);
  176. }
  177. /**
  178. * @param multiplicand value to be multiplied
  179. * @param multiplier value to multiply by
  180. * @return product of `multiplicand` by `multiplier`
  181. */
  182. public Byte multiply(byte multiplicand, byte multiplier) {
  183. return (byte)(multiplicand * multiplier);
  184. }
  185. /**
  186. * @param multiplicand value to be multiplied
  187. * @param multiplier value to multiply by
  188. * @return product of `multiplicand` by `multiplier`
  189. */
  190. public Float multiply(float multiplicand, float multiplier) {
  191. return (float)(multiplicand * multiplier);
  192. }
  193. /**
  194. * @param multiplicand value to be multiplied
  195. * @param multiplier value to multiply by
  196. * @return product of `multiplicand` by `multiplier`
  197. */
  198. public Double multiply(double multiplicand, double multiplier) {
  199. return (double)(multiplicand * multiplier);
  200. }
  201. /**
  202. * @return true
  203. */
  204. public Boolean returnTrue() {
  205. return true;
  206. }
  207. /**
  208. * @return false
  209. */
  210. public Boolean returnFalse() {
  211. return false;
  212. }
  213. }