1 | package genius.core.config;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.OutputStream;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import javax.xml.bind.JAXBException;
|
---|
10 | import javax.xml.bind.annotation.XmlAccessType;
|
---|
11 | import javax.xml.bind.annotation.XmlAccessorType;
|
---|
12 | import javax.xml.bind.annotation.XmlElement;
|
---|
13 | import javax.xml.bind.annotation.XmlElementRef;
|
---|
14 | import javax.xml.bind.annotation.XmlElementWrapper;
|
---|
15 | import javax.xml.bind.annotation.XmlRootElement;
|
---|
16 | import javax.xml.bind.annotation.XmlSeeAlso;
|
---|
17 |
|
---|
18 | import genius.core.Deadline;
|
---|
19 | import genius.core.persistent.PersistentDataType;
|
---|
20 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
21 | import genius.core.repository.ParticipantRepItem;
|
---|
22 | import genius.core.repository.PartyRepItem;
|
---|
23 | import genius.core.repository.ProfileRepItem;
|
---|
24 | import 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 })
|
---|
37 | public 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 | }
|
---|