1 | package genius.core.boaframework;
|
---|
2 |
|
---|
3 | import java.io.Serializable;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * In a BOAagent each component should be able to store data to be used in the next
|
---|
7 | * negotiation session. Unfortunately, the ANAC2013 implementation only allows us to
|
---|
8 | * store a single object. Therefore, this object packs the object of each of the three
|
---|
9 | * BOA components (bidding strategy, etc.) together as a single object.
|
---|
10 | *
|
---|
11 | * @author Mark Hendrikx
|
---|
12 | */
|
---|
13 | public class SessionData implements Serializable {
|
---|
14 |
|
---|
15 | private static final long serialVersionUID = -2269008062554989046L;
|
---|
16 |
|
---|
17 | /** Object saved by the bidding strategy. */
|
---|
18 | private Serializable biddingStrategyData;
|
---|
19 | /** Object saved by the opponent model. */
|
---|
20 | private Serializable opponentModelData;
|
---|
21 | /** Object saved by the acceptance strategy. */
|
---|
22 | private Serializable acceptanceStrategyData;
|
---|
23 | /** Boolean used to mark that the object changed to avoid writing the same object to file. */
|
---|
24 | private boolean changed;
|
---|
25 |
|
---|
26 | public SessionData() {
|
---|
27 | biddingStrategyData = null;
|
---|
28 | opponentModelData = null;
|
---|
29 | acceptanceStrategyData = null;
|
---|
30 | changed = false;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Returns the data stored by the given BOA component.
|
---|
35 | * @param type of the BOA component.
|
---|
36 | * @return component saved by this BOA component, null is no object saved.
|
---|
37 | */
|
---|
38 | public Serializable getData(BoaType type) {
|
---|
39 | Serializable result = null;
|
---|
40 | if (type == BoaType.BIDDINGSTRATEGY) {
|
---|
41 | result = biddingStrategyData;
|
---|
42 | } else if (type == BoaType.OPPONENTMODEL) {
|
---|
43 | result = opponentModelData;
|
---|
44 | } else if (type == BoaType.ACCEPTANCESTRATEGY) {
|
---|
45 | result = acceptanceStrategyData;
|
---|
46 | }
|
---|
47 | return result;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Method used to set the data to be saved by a BOA component.
|
---|
52 | * This method should not be called directly, use the storeData()
|
---|
53 | * and loadDate() of the component instead.
|
---|
54 | *
|
---|
55 | * @param component from which the data is to be saved.
|
---|
56 | * @param data to be saved.
|
---|
57 | */
|
---|
58 | public void setData(BoaType component, Serializable data) {
|
---|
59 | if (component == BoaType.BIDDINGSTRATEGY) {
|
---|
60 | biddingStrategyData = data;
|
---|
61 | } else if (component == BoaType.OPPONENTMODEL) {
|
---|
62 | opponentModelData = data;
|
---|
63 | } else if (component == BoaType.ACCEPTANCESTRATEGY) {
|
---|
64 | acceptanceStrategyData = data;
|
---|
65 | }
|
---|
66 | changed = true;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * @return true if save was saved by a component.
|
---|
71 | */
|
---|
72 | public boolean isEmpty() {
|
---|
73 | return biddingStrategyData == null && opponentModelData == null && acceptanceStrategyData == null;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * @return true if object was after its creation.
|
---|
78 | */
|
---|
79 | public boolean isChanged() {
|
---|
80 | return changed;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Sets that all changes have been processed.
|
---|
85 | */
|
---|
86 | public void changesCommitted() {
|
---|
87 | changed = false;
|
---|
88 | }
|
---|
89 | } |
---|