implementationJPeano.tex 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. \begin{tomcode3}[label=code:implementationJPeano,caption=Implémentation Java utilisée]
  2. static class JNat { }
  3. static class Jsuc extends JNat {
  4. public JNat n;
  5. public Jsuc() { }
  6. public Jsuc(JNat n) { this.n = n; }
  7. public boolean equals(Object o) {
  8. if(o instanceof Jsuc) {
  9. Jsuc obj = (Jsuc) o;
  10. return n.equals(obj.n);
  11. }
  12. return false;
  13. }
  14. }
  15. static class Jzero extends JNat {
  16. public Jzero() {}
  17. public boolean equals(Object o) {
  18. if(o instanceof Jzero) {
  19. return true;
  20. }
  21. return false;
  22. }
  23. }
  24. static class JNatList { }
  25. static class JconcJNat extends JNatList {
  26. public JNat head;
  27. public JNatList tail;
  28. public JconcJNat() { head = null; tail = null; }
  29. public JconcJNat(JNat h, JNatList ntail) {
  30. head = h;
  31. tail = ntail;
  32. }
  33. public boolean isEmpty() {
  34. return (head == null && tail == null);
  35. }
  36. public boolean equals(Object o) {
  37. if (o instanceof JconcJNat) {
  38. JconcJNat obj = (JconcJNat) o;
  39. if (this.isEmpty() && obj.isEmpty()) {
  40. return true;
  41. } else if (!this.isEmpty() && !obj.isEmpty()) {
  42. return
  43. head.equals(obj.head) && tail.equals(obj.tail);
  44. }
  45. }
  46. return false;
  47. }
  48. }
  49. \end{tomcode3}