Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package expression.generic;
- import expression.*;
- import expression.exceptions.ExpressionCheckedParser;
- import expression.exceptions.ParseException;
- import java.math.BigInteger;
- public class GenericTabulator implements Tabulator {
- Calculator<Integer> integerCalculator = new IntegerCalculator();
- Calculator<Double> doubleCalculator = new DoubleCalculator();
- Calculator<BigInteger> bigIntegerCalculator = new BigIntegerCalculator();
- Calculator<Integer> uncheckedIntegerCalculator = new UncheckedIntegerCalculator();
- Calculator<Byte> byteCalculator = new ByteCalculator();
- Calculator<Float> floatCalculator = new FloatCalculator();
- private Calculator<?> parseType(String mode) {
- switch (mode) {
- case "i":
- return integerCalculator;
- case "u":
- return uncheckedIntegerCalculator;
- case "d":
- return doubleCalculator;
- case "bi":
- return bigIntegerCalculator;
- case "b":
- return byteCalculator;
- case "f":
- return floatCalculator;
- }
- return null;
- }
- public Object[][][] tabulate(String mode, String expression, int x1, int x2, int y1, int y2, int z1, int z2) throws ParseException {
- Object[][][] result = new Object[x2 - x1 + 2][y2 - y1 + 2][z2 - z1 + 2];
- ExpressionCheckedParser parser = new ExpressionCheckedParser();
- Calculator<?> calculator = parseType(mode);
- for (int i = x1; i <= x2; i++) {
- for (int j = y1; j <= y2; j++) {
- for (int k = z1; k <= z2; k++) {
- try {
- TripleExpression parsed = parser.parse(expression);
- result[i - x1][j - y1][k - z1] = parsed.evaluate(i, j, k, calculator);
- } catch (Exception e) {
- result[i - x1][j - y1][k - z1] = null;
- }
- }
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement