Advertisement
Guest User

Untitled

a guest
May 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package expression.generic;
  2.  
  3. import expression.*;
  4. import expression.exceptions.ExpressionCheckedParser;
  5. import expression.exceptions.ParseException;
  6.  
  7. import java.math.BigInteger;
  8.  
  9. public class GenericTabulator implements Tabulator {
  10.  
  11. Calculator<Integer> integerCalculator = new IntegerCalculator();
  12. Calculator<Double> doubleCalculator = new DoubleCalculator();
  13. Calculator<BigInteger> bigIntegerCalculator = new BigIntegerCalculator();
  14. Calculator<Integer> uncheckedIntegerCalculator = new UncheckedIntegerCalculator();
  15. Calculator<Byte> byteCalculator = new ByteCalculator();
  16. Calculator<Float> floatCalculator = new FloatCalculator();
  17.  
  18. private Calculator<?> parseType(String mode) {
  19. switch (mode) {
  20. case "i":
  21. return integerCalculator;
  22. case "u":
  23. return uncheckedIntegerCalculator;
  24. case "d":
  25. return doubleCalculator;
  26. case "bi":
  27. return bigIntegerCalculator;
  28. case "b":
  29. return byteCalculator;
  30. case "f":
  31. return floatCalculator;
  32. }
  33. return null;
  34. }
  35.  
  36. public Object[][][] tabulate(String mode, String expression, int x1, int x2, int y1, int y2, int z1, int z2) throws ParseException {
  37. Object[][][] result = new Object[x2 - x1 + 2][y2 - y1 + 2][z2 - z1 + 2];
  38. ExpressionCheckedParser parser = new ExpressionCheckedParser();
  39. Calculator<?> calculator = parseType(mode);
  40. for (int i = x1; i <= x2; i++) {
  41. for (int j = y1; j <= y2; j++) {
  42. for (int k = z1; k <= z2; k++) {
  43. try {
  44. TripleExpression parsed = parser.parse(expression);
  45. result[i - x1][j - y1][k - z1] = parsed.evaluate(i, j, k, calculator);
  46. } catch (Exception e) {
  47. result[i - x1][j - y1][k - z1] = null;
  48. }
  49. }
  50. }
  51. }
  52. return result;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement