Environment050.java

Package: environment/
File: Environment050.java

  1. package environment;
  2.  
  3. import coupling.interaction.Interaction;
  4. import coupling.interaction.Interaction040;
  5. import existence.Existence0501;
  6. import existence.Existence050;
  7.  
  8. public class Environment050 implements Environment {
  9.  
  10. private Existence050 existence;
  11.  
  12. public Environment050(Existence050 existence){
  13. this.existence = existence;
  14. init();
  15. }
  16.  
  17. protected void init(){
  18. this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E1 + this.getExistence().LABEL_R1, -1);
  19. Interaction040 i12 = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E1 + this.getExistence().LABEL_R2, 1);
  20. this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E2 + this.getExistence().LABEL_R1, -1);
  21. Interaction040 i22 = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E2 + this.getExistence().LABEL_R2, 1);
  22. this.getExistence().addOrGetAbstractExperience(i12);
  23. this.getExistence().addOrGetAbstractExperience(i22);
  24. }
  25.  
  26. protected Existence050 getExistence(){
  27. return this.existence;
  28. }
  29.  
  30. private Interaction previousInteraction;
  31. protected void setPreviousInteraction(Interaction previousInteraction){
  32. this.previousInteraction = previousInteraction;
  33. }
  34. protected Interaction getPreviousInteraction(){
  35. return this.previousInteraction;
  36. }
  37.  
  38. private Interaction penultimateInteraction;
  39. protected void setPenultimateInteraction(Interaction penultimateInteraction){
  40. this.penultimateInteraction = penultimateInteraction;
  41. }
  42. protected Interaction getPenultimateInteraction(){
  43. return this.penultimateInteraction;
  44. }
  45.  
  46. @Override
  47. public Interaction enact(Interaction intendedInteraction) {
  48. Interaction enactedInteraction = null;
  49.  
  50. if (intendedInteraction.getLabel().contains(this.getExistence().LABEL_E1)){
  51. if ( this.getPreviousInteraction() != null &&
  52. (this.getPenultimateInteraction() == null || this.getPenultimateInteraction().getLabel().contains(this.getExistence().LABEL_E2)) &&
  53. this.getPreviousInteraction().getLabel().contains(this.getExistence().LABEL_E1))
  54. enactedInteraction = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E1 + this.getExistence().LABEL_R2, 0);
  55. else
  56. enactedInteraction = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E1 + this.getExistence().LABEL_R1, 0);
  57. }
  58. else{
  59. if (this.getPreviousInteraction() != null &&
  60. (this.getPenultimateInteraction() == null || this.getPenultimateInteraction().getLabel().contains(this.getExistence().LABEL_E1)) &&
  61. this.getPreviousInteraction().getLabel().contains(this.getExistence().LABEL_E2))
  62. enactedInteraction = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E2 + this.getExistence().LABEL_R2, 0);
  63. else
  64. enactedInteraction = this.getExistence().addOrGetPrimitiveInteraction(this.getExistence().LABEL_E2 + this.getExistence().LABEL_R1, 0);
  65. }
  66.  
  67. this.setPenultimateInteraction(this.getPreviousInteraction());
  68. this.setPreviousInteraction(enactedInteraction);
  69.  
  70. return enactedInteraction;
  71. }
  72. }
  73.  

See public discussions about this page or start a new discussion by clicking on the Google+ Share button. Please type the #IDEALMOOCEnvironment050 hashtag in your post: