Advertisement
dejvidecz

Untitled

May 5th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import com.google.common.base.Predicate;
  2. import com.google.common.collect.ImmutableList;
  3. import java.util.Iterator;
  4.  
  5.  
  6.  
  7. class HorizontalFlip implements ActuatorVisitor {
  8.  
  9. @Override
  10. public Actuator visitUp(Up actuator) {
  11. return new Up();
  12. }
  13.  
  14. @Override
  15. public Actuator visitDown(Down actuator) {
  16. return new Down();
  17. }
  18.  
  19. @Override
  20. public Actuator visitLeft(Left actuator) {
  21. return new Right();
  22. }
  23.  
  24. @Override
  25. public Actuator visitRight(Right actuator) {
  26. return new Left();
  27. }
  28.  
  29. @Override
  30. public Actuator visitParallellyComposingActuator(ParallellyComposingActuator actuator) {
  31.  
  32. return new Actuator() {
  33.  
  34. @Override
  35. public Actuator accept(ActuatorVisitor v) {
  36. return new ParallellyComposingActuator(actuator.motors);
  37. }
  38.  
  39. @Override
  40. public void actuate(Movable movable) {
  41. for (Actuator m1 : actuator.motors) {
  42. Actuator flip = m1.accept(new HorizontalFlip());
  43. flip.actuate(movable);
  44. }
  45. }
  46. };
  47. }
  48.  
  49. @Override
  50. public Actuator visitAmplifyingActuator(AmplifyingActuator actuator) {
  51. return new Actuator() {
  52.  
  53. @Override
  54. public Actuator accept(ActuatorVisitor v) {
  55. return new AmplifyingActuator(actuator.motor, actuator.factor);
  56. }
  57.  
  58. @Override
  59. public void actuate(Movable movable) {
  60. for (int i = 0; i < actuator.factor; i++) {
  61. actuator.motor.accept(new HorizontalFlip()).actuate(movable);
  62. }
  63. }
  64. };
  65. }
  66.  
  67. @Override
  68. public Actuator visitSequentiallyComposingActuator(SequentiallyComposingActuator actuator) {
  69. return new Actuator() {
  70.  
  71. @Override
  72. public Actuator accept(ActuatorVisitor v) {
  73. return new SequentiallyComposingActuator(actuator.iterable);
  74. }
  75.  
  76. @Override
  77. public void actuate(Movable movable) {
  78. Pair<Predicate<Movable>, Actuator> act;
  79. while (actuator.iterable.iterator().hasNext()) {
  80. act = actuator.iterable.iterator().next();
  81. while (act.first.apply(movable)) {
  82. act.second.accept(new HorizontalFlip()).actuate(movable);
  83. }
  84. }
  85.  
  86. }
  87. };
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement