source: src/main/java/genius/core/config/MultilateralTournamentConfiguration.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: 6.0 KB
Line 
1package genius.core.config;
2
3import java.io.File;
4import java.io.OutputStream;
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.List;
8
9import javax.xml.bind.JAXBException;
10import javax.xml.bind.annotation.XmlAccessType;
11import javax.xml.bind.annotation.XmlAccessorType;
12import javax.xml.bind.annotation.XmlElement;
13import javax.xml.bind.annotation.XmlElementRef;
14import javax.xml.bind.annotation.XmlElementWrapper;
15import javax.xml.bind.annotation.XmlRootElement;
16import javax.xml.bind.annotation.XmlSeeAlso;
17
18import genius.core.Deadline;
19import genius.core.persistent.PersistentDataType;
20import genius.core.repository.MultiPartyProtocolRepItem;
21import genius.core.repository.ParticipantRepItem;
22import genius.core.repository.PartyRepItem;
23import genius.core.repository.ProfileRepItem;
24import genius.core.repository.boa.BoaPartyRepItem;
25
26/**
27 * Implementation of MultilateralTournamentConfigurationInterface. This stores
28 * all information for a multilateral tournament. Can {@link #load(File)} and
29 * {@link #save(File)} to XML. Immutable.
30 *
31 * This object can also be deserialized. Therefore we set default values in
32 * optional fields
33 */
34@XmlRootElement
35@XmlAccessorType(XmlAccessType.FIELD)
36@XmlSeeAlso({ BoaPartyRepItem.class, PartyRepItem.class })
37public class MultilateralTournamentConfiguration
38 implements MultilateralTournamentConfigurationInterface {
39
40 @XmlElement(name = "deadline")
41 private Deadline deadline;
42
43 /**
44 * Holds the chosen protocol
45 */
46 @XmlElement
47 private MultiPartyProtocolRepItem protocolItem;
48
49 /**
50 * The mediator in use. ignored if protocol does not use mediator. Must be
51 * non-null if protocol needs mediator.
52 */
53 @XmlElement
54 private PartyRepItem mediator;
55
56 /**
57 * Holds the list of all chosen parties. Excludes mediator
58 */
59 @XmlElementWrapper(name = "partyRepItems")
60 @XmlElementRef
61 private List<ParticipantRepItem> partyItems;
62
63 /**
64 * Holds the list of chosen profiles
65 */
66 @XmlElementWrapper(name = "partyProfileItems")
67 @XmlElement(name = "item")
68 private List<ProfileRepItem> profileItems;
69
70 @XmlElementWrapper(name = "partyBItems")
71 @XmlElementRef
72 private List<? extends ParticipantRepItem> partyBItems = new ArrayList<>();
73
74 @XmlElementWrapper(name = "partyBProfiles")
75 @XmlElement(name = "item")
76 private List<? extends ProfileRepItem> profileBItems = new ArrayList<>();
77
78 /**
79 * Holds the number of "agents per session" as set in the GUI. This is the
80 * number of non-mediators in each session. This may be smaller than the
81 * number of available partyItems.
82 */
83 @XmlElement
84 private int numberOfPartiesPerSession;
85
86 /**
87 * Holds whether repetition is allowed or not;
88 */
89 @XmlElement
90 private boolean repetitionAllowed;
91
92 @XmlElement
93 private boolean isRandomSessionOrder;
94
95 @XmlElement
96 private int repeats = 1;
97
98 @XmlElement
99 private PersistentDataType persistentDataType;
100
101 @XmlElement
102 private boolean enablePrint;
103
104 /**
105 * Needed for the serializer.
106 */
107 @SuppressWarnings("unused")
108 private MultilateralTournamentConfiguration() {
109 }
110
111 public MultilateralTournamentConfiguration(
112 MultiPartyProtocolRepItem protocol, Deadline deadline2,
113 PartyRepItem mediator, List<ParticipantRepItem> parties,
114 List<ProfileRepItem> profiles, List<ParticipantRepItem> partiesB,
115 List<ProfileRepItem> profilesB, int nrepeats, int nparties,
116 boolean repeatParties, boolean isRandomSessionOrder,
117 PersistentDataType type, boolean enablePrint) {
118 this.protocolItem = protocol;
119 this.deadline = deadline2;
120 this.mediator = mediator;
121 this.partyItems = new ArrayList<>(parties);
122 this.profileItems = new ArrayList<>(profiles);
123 this.partyBItems = new ArrayList<>(partiesB);
124 this.profileBItems = new ArrayList<>(profilesB);
125 this.repeats = nrepeats;
126 this.numberOfPartiesPerSession = nparties;
127 this.repetitionAllowed = repeatParties;
128 this.isRandomSessionOrder = isRandomSessionOrder;
129 this.persistentDataType = type;
130 this.enablePrint = enablePrint;
131
132 }
133
134 @Override
135 public MultiPartyProtocolRepItem getProtocolItem() {
136 return protocolItem;
137 }
138
139 @Override
140 public PartyRepItem getMediator() {
141 return mediator;
142 }
143
144 @Override
145 public Deadline getDeadline() {
146 return deadline;
147 }
148
149 @Override
150 public List<ParticipantRepItem> getPartyItems() {
151 return Collections.unmodifiableList(partyItems);
152 }
153
154 @Override
155 public List<ProfileRepItem> getProfileItems() {
156 return Collections.unmodifiableList(profileItems);
157 }
158
159 @Override
160 public List<ParticipantRepItem> getPartyBItems() {
161 return Collections.unmodifiableList(partyBItems);
162 }
163
164 @Override
165 public List<ProfileRepItem> getProfileBItems() {
166 return Collections.unmodifiableList(profileBItems);
167 }
168
169 @Override
170 public int getRepeats() {
171 return repeats;
172 }
173
174 @Override
175 public int getNumPartiesPerSession() {
176 return numberOfPartiesPerSession;
177 }
178
179 @Override
180 public boolean isRepetitionAllowed() {
181 return repetitionAllowed;
182 }
183
184 @Override
185 public boolean isRandomSessionOrder() {
186 return isRandomSessionOrder;
187 }
188
189 /**
190 * Load a new {@link MultilateralTournamentConfiguration} from file.
191 *
192 * @param file
193 * the file to load from
194 * @return the new {@link MultilateralTournamentConfiguration}.
195 * @throws JAXBException
196 */
197 public static MultilateralTournamentConfiguration load(File file)
198 throws JAXBException {
199 return MultilateralTournamentsConfiguration.load(file).getTournaments()
200 .get(0);
201 }
202
203 /**
204 * Save this to output
205 *
206 * @param outstream
207 * the outputstream to write to
208 */
209 public void save(OutputStream outstream) {
210 List<MultilateralTournamentConfiguration> tournaments = new ArrayList<MultilateralTournamentConfiguration>();
211 tournaments.add(this);
212 new MultilateralTournamentsConfiguration(tournaments).save(outstream);
213 }
214
215 @Override
216 public PersistentDataType getPersistentDataType() {
217 return persistentDataType;
218 }
219
220 @Override
221 public boolean isPrintEnabled() {
222 return enablePrint;
223 }
224
225}
Note: See TracBrowser for help on using the repository browser.