1 | package genius.core.session;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import genius.core.actions.Action;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Represents a single round in a negotiation session. A round is a part of a
|
---|
10 | * negotiation where all participants can respond to the current state of the
|
---|
11 | * negotiation. A {@link Round} consists of {@link Turn} which may or may not
|
---|
12 | * have an {@link Action}. Rounds are contained in the {@link Session} object. A
|
---|
13 | * party can have multiple turns in a single round.
|
---|
14 | *
|
---|
15 | * @author David Festen
|
---|
16 | */
|
---|
17 | public class Round {
|
---|
18 | /**
|
---|
19 | * holds the {@link Turn} objects of this round
|
---|
20 | */
|
---|
21 | private List<Turn> turns;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Creates a new instance of the {@link Round} object.
|
---|
25 | */
|
---|
26 | public Round() {
|
---|
27 | turns = new ArrayList<Turn>();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Creates a new instance of the {@link Round} object. This version of the
|
---|
32 | * constructor creates a shallow copy of the turns.
|
---|
33 | *
|
---|
34 | * @param round
|
---|
35 | * An existing round object.
|
---|
36 | */
|
---|
37 | public Round(Round round) {
|
---|
38 | turns = round.getTurns();
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Gets the turns in this round. See the {@link Turn} object for more
|
---|
43 | * information.
|
---|
44 | *
|
---|
45 | * @return copy of the {@link Turn} objects in this round
|
---|
46 | */
|
---|
47 | public synchronized List<Turn> getTurns() {
|
---|
48 | return new ArrayList<Turn>(turns);
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Gets the actions in done in this round. If a turn is not executed, it
|
---|
53 | * shouldn't have an action. This means that in practice, you can use this
|
---|
54 | * method if you want to know the executed actions of this turn, even while
|
---|
55 | * it is still busy.
|
---|
56 | *
|
---|
57 | * @return A list of all actions done this turn.
|
---|
58 | */
|
---|
59 | public synchronized List<Action> getActions() {
|
---|
60 | List<Action> actions = new ArrayList<Action>(turns.size());
|
---|
61 | for (Turn turn : turns)
|
---|
62 | if (turn.getAction() != null)
|
---|
63 | actions.add(turn.getAction());
|
---|
64 |
|
---|
65 | // return the actions
|
---|
66 | return actions;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Add a turn to this round. See {@link Turn} for more information.
|
---|
71 | *
|
---|
72 | * @param turn
|
---|
73 | * the turn to add.
|
---|
74 | */
|
---|
75 | public synchronized void addTurn(Turn turn) {
|
---|
76 | turns.add(turn);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * get the last item of the {@link #getActions()} list, which in practice
|
---|
81 | * should be the most recent action of this round.
|
---|
82 | *
|
---|
83 | * @return The most recently executed action in this round. Null if no
|
---|
84 | * action has been executed yet.
|
---|
85 | */
|
---|
86 | public synchronized Action getMostRecentAction() {
|
---|
87 | List<Action> actions = getActions();
|
---|
88 | if (actions.isEmpty())
|
---|
89 | return null;
|
---|
90 | return actions.get(actions.size() - 1);
|
---|
91 | }
|
---|
92 | }
|
---|