diff -r acf2c31e22d4 -r 40cabcdcd2be samples/composition/src-api2.0/org/apidesign/math/Arithmetica.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/composition/src-api2.0/org/apidesign/math/Arithmetica.java Thu Oct 30 21:30:10 2014 +0100 @@ -0,0 +1,30 @@ +package org.apidesign.math; + +/** Class to simplify arithmetical operations, improved version to compute + * the sum for ranges. + * + * @author Jaroslav Tulach + * @version 2.0 + */ +public class Arithmetica { + public int sumTwo(int one, int second) { + return one + second; + } + + public int sumAll(int... numbers) { + if (numbers.length == 0) { + return 0; + } + int sum = numbers[0]; + for (int i = 1; i < numbers.length; i++) { + sum = sumTwo(sum, numbers[i]); + } + return sum; + } + +// BEGIN: design.composition.arith2.0 + public int sumRange(int from, int to) { + return (from + to) * (Math.abs(to - from) + 1) / 2; + } +// END: design.composition.arith2.0 +}