source: src/main/java/genius/gui/boaparties/BoaPartyModel.java

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

Initial import : Genius 9.0.0

File size: 3.7 KB
Line 
1package genius.gui.boaparties;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.boaframework.AcceptanceStrategy;
7import genius.core.boaframework.OMStrategy;
8import genius.core.boaframework.OfferingStrategy;
9import genius.core.boaframework.OpponentModel;
10import genius.core.exceptions.InstantiateException;
11import genius.core.list.ImmutableList;
12import genius.core.repository.RepositoryFactory;
13import genius.core.repository.boa.BoaPartyRepItem;
14import genius.core.repository.boa.BoaRepository;
15import genius.core.repository.boa.BoaWithSettingsRepItem;
16import genius.gui.panels.TextModel;
17
18/**
19 * Stores the settings to create a new {@link BoaPartyRepItem} for editing in a
20 * GUI.
21 */
22public class BoaPartyModel {
23 private TextModel nameModel;
24
25 private BoaComponentModel<OfferingStrategy> offeringModel;
26
27 private BoaComponentModel<AcceptanceStrategy> acceptanceModel;
28
29 private BoaComponentModel<OpponentModel> opponentModel;
30
31 private BoaComponentModel<OMStrategy> omStrategiesModel;
32
33 /**
34 * Create Boa Party model with an initial value from an existingItem
35 *
36 * @param existingItem
37 * an existing {@link BoaPartyRepItem}
38 * @throws InstantiateException
39 * if problem with repository
40 */
41 public BoaPartyModel(BoaPartyRepItem existingItem) throws InstantiateException {
42 nameModel = new TextModel(existingItem.getName());
43 initModels(existingItem);
44 }
45
46 /**
47 * Load the models with the available values from the repos.
48 *
49 * @throws InstantiateException
50 * if repository does not have some type of BOA component
51 *
52 */
53 private void initModels(BoaPartyRepItem party) throws InstantiateException {
54 BoaRepository repo = RepositoryFactory.getBoaRepository();
55 if (repo.getAcceptanceConditions().isEmpty() || repo.getBiddingStrategies().isEmpty()
56 || repo.getOpponentModels().isEmpty() || repo.getOpponentModelStrategies().isEmpty()) {
57 throw new InstantiateException(
58 "boarepository is invalid. editor requires at least one valid component of each type in the repository");
59 }
60 offeringModel = new BoaComponentModel<OfferingStrategy>(party.getOfferingStrategy());
61 acceptanceModel = new BoaComponentModel<AcceptanceStrategy>(party.getAcceptanceStrategy());
62 opponentModel = new BoaComponentModel<OpponentModel>(party.getOpponentModel());
63 omStrategiesModel = new BoaComponentModel<OMStrategy>(party.getOmStrategy());
64 }
65
66 public TextModel getNameModel() {
67 return nameModel;
68 }
69
70 public BoaComponentModel<OfferingStrategy> getOfferingModel() {
71 return offeringModel;
72 }
73
74 public BoaComponentModel<AcceptanceStrategy> getAcceptanceModel() {
75 return acceptanceModel;
76 }
77
78 public BoaComponentModel<OpponentModel> getOpponentModel() {
79 return opponentModel;
80 }
81
82 public BoaComponentModel<OMStrategy> getOmStrategiesModel() {
83 return omStrategiesModel;
84 }
85
86 @Override
87 public String toString() {
88 return "BOA:" + nameModel.getText();
89 }
90
91 /**
92 *
93 * @return list of all boacomponent-plus-setting combinations specified by
94 * this model. FIXME prevent generation of excessive lists. Use
95 * {@link ImmutableList}
96 */
97 public List<BoaPartyRepItem> getValues() {
98 List<BoaPartyRepItem> items = new ArrayList<>();
99 int serial = 0;
100 String name = nameModel.getText();
101
102 for (BoaWithSettingsRepItem<OfferingStrategy> value1 : offeringModel.getValues()) {
103 for (BoaWithSettingsRepItem<AcceptanceStrategy> value2 : acceptanceModel.getValues()) {
104 for (BoaWithSettingsRepItem<OpponentModel> value3 : opponentModel.getValues()) {
105 for (BoaWithSettingsRepItem<OMStrategy> value4 : omStrategiesModel.getValues()) {
106 items.add(new BoaPartyRepItem(name + (serial == 0 ? "" : serial), value1, value2, value3,
107 value4));
108 serial++;
109 }
110 }
111 }
112 }
113
114 return items;
115 }
116
117}
Note: See TracBrowser for help on using the repository browser.