source: src/main/java/genius/core/session/Turn.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.7 KB
Line 
1package genius.core.session;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Collection;
6
7import genius.core.actions.Action;
8import genius.core.parties.NegotiationParty;
9
10/**
11 * Represents a single turn in the negotiation session. A turn refers to the
12 * opportunity of one {@link NegotiationParty} to make a response to the current
13 * state of the negotiation.{@link Turn} objects are contained in {@link Round}
14 * objects which are in their turn contained in a {@link Session} object. A
15 * single Turn is executed by a single
16 * {@link genius.core.parties.NegotiationParty}. A party is however, allowed to
17 * have multiple turns in a single round.
18 *
19 * @author David Festen
20 * @author W.Pasman #1067
21 */
22public class Turn {
23 /**
24 * Holds a list of action classes which can be executed this turn
25 */
26 private final ArrayList<Class<? extends Action>> validActions;
27
28 /**
29 * The party which should execute this turn
30 */
31 private NegotiationParty party;
32
33 /**
34 * After the party executed the turn, this holds the action executed. Null
35 * until an action was executed.
36 */
37 private Action action = null;
38
39 /**
40 * Initializes a new instance of the turn class. See also the {@link Turn}
41 * class itself for more information on usage.
42 *
43 * @param party
44 * The party that should execute this turn
45 */
46 public Turn(NegotiationParty party) {
47 if (party == null)
48 throw new NullPointerException("party =null");
49 this.party = party;
50 this.validActions = new ArrayList<Class<? extends Action>>();
51 }
52
53 /**
54 * Initializes a new instance of the turn class. See also the {@link Turn}
55 * class itself for more information on usage.
56 *
57 * @param party
58 * The party that should execute this turn
59 * @param validActions
60 * Valid {@link Action} classes that can be executed this turn
61 */
62 @SafeVarargs
63 public Turn(NegotiationParty party, final Class<? extends Action>... validActions) {
64 if (party == null)
65 throw new NullPointerException("party =null");
66 this.party = party;
67 this.validActions = new ArrayList<Class<? extends Action>>(Arrays.asList(validActions));
68 }
69
70 /**
71 * Initializes a new instance of the turn class. See also the {@link Turn}
72 * class itself for more information on usage.
73 *
74 * @param party
75 * The party that should execute this turn
76 * @param validActions
77 * Valid {@link Action} classes that can be executed this turn
78 */
79 public Turn(NegotiationParty party, Collection<Class<? extends Action>> validActions) {
80 this.party = party;
81 this.validActions = new ArrayList<Class<? extends Action>>(validActions);
82 }
83
84 /**
85 * Get the party which should execute this turn
86 *
87 * @return the {@link genius.core.parties.NegotiationParty} that should do
88 * this turn.
89 */
90 public NegotiationParty getParty() {
91 return party;
92 }
93
94 /**
95 * Get (copy of) all valid actions for this turn.
96 *
97 * @return the list of {@link Action} classes valid this turn
98 */
99 public ArrayList<Class<? extends Action>> getValidActions() {
100 return new ArrayList<Class<? extends Action>>(validActions);
101 }
102
103 /**
104 * Gets the action executed this turn
105 *
106 * @return The executed action or {@code Null} if turn not done yet.
107 */
108 public Action getAction() {
109 return action;
110 }
111
112 /**
113 * Sets the action executed this turn.
114 *
115 * @param action
116 * The action that was executed. Can be null. Not clear what that
117 * means.
118 */
119 public void setAction(Action action) {
120 this.action = action;
121 }
122
123 @Override
124 public String toString() {
125 return "Turn[party:" + party + " allowed:" + validActions + "]";
126 }
127}
Note: See TracBrowser for help on using the repository browser.