Skip to contentMethod: getOutcome()
      1: package de.fhdw.gaming.ipspiel23.c4.domain.impl;
2: 
3: import java.util.Optional;
4: 
5: import de.fhdw.gaming.core.domain.AbstractPlayer;
6: import de.fhdw.gaming.core.domain.PlayerState;
7: 
8: /**
9:  * The mutable state of a player.
10:  */
11: class C4MutablePlayerState {
12:     /**
13:      * The current state of the player.
14:      */
15:     private PlayerState state;
16: 
17:     /**
18:      * The outcome of the player.
19:      */
20:     private Double outcome;
21: 
22:     /**
23:      * Creates a new instance of {@link C4MutablePlayerState}.
24:      * 
25:      * @param state The current state of the player.
26:      * @param outcome The outcome of the player.
27:      */
28:     public C4MutablePlayerState(final PlayerState state, final Double outcome) {
29:         this.state = state;
30:         this.outcome = outcome;
31:     }
32: 
33:     /**
34:      * Gets the current state of the player.
35:      */
36:     public PlayerState getState() {
37:         return state;
38:     }
39: 
40:     /**
41:      * Sets the current state of the player.
42:      * @param state the new state
43:      */
44:     public void setState(final PlayerState state) {
45:         this.state = state;
46:     }
47: 
48:     /**
49:      * Gets the outcome of the player.
50:      */
51:     public Optional<Double> getOutcome() {
52:•        if (outcome != null) {
53:             return Optional.of(outcome);
54:         }
55:         return AbstractPlayer.mapStateToOutcome(state);
56:     }
57: 
58:     /**
59:      * Sets the outcome of the player.
60:      * @param outcome the new outcome
61:      */
62:     public void setOutcome(final Double outcome) {
63:         this.outcome = outcome;
64:     }
65:     
66:     @Override
67:     public String toString() {
68:         final StringBuilder bob = new StringBuilder(64);
69:         bob.append("C4MutablePlayerState [state=").append(this.state)
70:             .append(", outcome=").append(this.getOutcome()).append(']');
71:         return bob.toString();
72:     }
73:     
74:     @Override
75:     public boolean equals(final Object object) {
76:         if (object == null) {
77:             return false;
78:         }
79:         if (!(object instanceof C4MutablePlayerState)) {
80:             return false;
81:         }
82:         final C4MutablePlayerState other = (C4MutablePlayerState) object;
83:         if (this.state != other.state) {
84:             return false;
85:         }
86:         return this.outcome == null && other.outcome == null
87:             || this.outcome != null && this.outcome.equals(other.outcome);
88:     }
89: 
90:     @Override
91:     public int hashCode() {
92:         int hash = 7;
93:         if (this.outcome != null) {
94:             hash = 31 * hash + this.outcome.hashCode();
95:         }
96:         hash = 31 * hash + this.state.hashCode();
97:         return hash;
98:     }
99: }