implement a whole bunch of simple methods.

MathUtilities.java 6.6KB

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