You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB

  1. /*!! Program*/
  2. /*!
  3. Conditional
  4. ===========
  5. */
  6. /*!- Header*/
  7. package program;
  8. import expression.Expression;
  9. /*! A `Conditional` consists of the `condition` expression and the two programs `thenCase` and `elseCase` with the
  10. intended semantics of execution the `elseCase` if the `expression` evaluates to 0 and the `thenCase` otherwise. */
  11. public class Conditional extends Program {
  12. public final Expression condition;
  13. public final Program thenCase;
  14. public final Program elseCase;
  15. public Conditional(Expression condition, Program thenCase, Program elseCase) {
  16. this.condition = condition;
  17. this.thenCase = thenCase;
  18. this.elseCase = elseCase;
  19. }
  20. /*!- generated equals implementation */
  21. @Override
  22. public boolean equals(Object o) {
  23. if (this == o) return true;
  24. if (o == null || getClass() != o.getClass()) return false;
  25. Conditional that = (Conditional) o;
  26. if (!condition.equals(that.condition)) return false;
  27. if (!thenCase.equals(that.thenCase)) return false;
  28. return elseCase.equals(that.elseCase);
  29. }
  30. /*!- String serialization*/
  31. @Override
  32. public String toString() {
  33. return "if (" + condition + ") then { " + thenCase + " } else { " + elseCase + " }";
  34. }
  35. }