1 | package geniusweb.domaineditor.model.profile;
|
---|
2 |
|
---|
3 | import java.math.BigDecimal;
|
---|
4 |
|
---|
5 | import geniusweb.domaineditor.model.NumberValueSetModel;
|
---|
6 | import geniusweb.profile.utilityspace.NumberValueSetUtilities;
|
---|
7 | import geniusweb.profile.utilityspace.ValueSetUtilities;
|
---|
8 | import tudelft.utilities.listener.DefaultListenable;
|
---|
9 | import tudelft.utilities.logging.Reporter;
|
---|
10 | import tudelft.utilities.mvc.model.NumberModel;
|
---|
11 | import tudelft.utilities.mvc.model.RestrictedNumberModel;
|
---|
12 | import tudelft.utilities.mvc.model.events.Event;
|
---|
13 | import tudelft.utilities.mvc.panels.PopupReporter;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Contains info for a {@link NumberValueSetUtilities}
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public class NumberValueSetUtilitiesModel extends DefaultListenable<Event>
|
---|
20 | implements ValueSetUtilitiesModel {
|
---|
21 |
|
---|
22 | private static final BigDecimal DEFAULT = new BigDecimal("0.5");
|
---|
23 | // this reporter in theory is never used.
|
---|
24 | // it's connected to values that never change
|
---|
25 | private final static Reporter dummylog = new PopupReporter(null);
|
---|
26 | private final static NumberModel LOW = new NumberModel(BigDecimal.ZERO,
|
---|
27 | dummylog);
|
---|
28 | private final static NumberModel HIGH = new NumberModel(BigDecimal.ONE,
|
---|
29 | dummylog);
|
---|
30 | private final NumberModel lowValue;
|
---|
31 | private final RestrictedNumberModel lowUtility;
|
---|
32 | private final NumberModel highValue;
|
---|
33 | private final RestrictedNumberModel highUtility;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | *
|
---|
37 | * @param lowValue
|
---|
38 | * @param lowUtility a {@link RestrictedNumberModel} with min=0, max=100
|
---|
39 | * @param highValue
|
---|
40 | * @param highUtility a {@link RestrictedNumberModel} with min=0, max=100
|
---|
41 | */
|
---|
42 | NumberValueSetUtilitiesModel(NumberModel lowValue,
|
---|
43 | RestrictedNumberModel lowUtility, NumberModel highValue,
|
---|
44 | RestrictedNumberModel highUtility) {
|
---|
45 | this.lowValue = lowValue;
|
---|
46 | this.lowUtility = lowUtility;
|
---|
47 | this.highValue = highValue;
|
---|
48 | this.highUtility = highUtility;
|
---|
49 | }
|
---|
50 |
|
---|
51 | NumberValueSetUtilitiesModel(NumberValueSetModel valuesmodel,
|
---|
52 | Reporter log) {
|
---|
53 | this(valuesmodel.getLow(),
|
---|
54 | new RestrictedNumberModel(DEFAULT, LOW, HIGH, log),
|
---|
55 | valuesmodel.getHigh(),
|
---|
56 | new RestrictedNumberModel(DEFAULT, LOW, HIGH, log));
|
---|
57 | }
|
---|
58 |
|
---|
59 | public NumberModel getLowValue() {
|
---|
60 | return lowValue;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public RestrictedNumberModel getLowUtility() {
|
---|
64 | return lowUtility;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public NumberModel getHighValue() {
|
---|
68 | return highValue;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public RestrictedNumberModel getHighUtility() {
|
---|
72 | return highUtility;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public NumberValueSetUtilities getCurrentValue()
|
---|
77 | throws IllegalStateException {
|
---|
78 | return new NumberValueSetUtilities(lowValue.getValue(),
|
---|
79 | lowUtility.getValue(), highValue.getValue(),
|
---|
80 | highUtility.getValue());
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public void setCurrentValue(ValueSetUtilities obj)
|
---|
85 | throws IllegalArgumentException {
|
---|
86 | if (!(obj instanceof NumberValueSetUtilities))
|
---|
87 | throw new IllegalArgumentException(
|
---|
88 | "Expected instance of NumberValueSetUtilities but got "
|
---|
89 | + obj);
|
---|
90 | NumberValueSetUtilities utils = (NumberValueSetUtilities) obj;
|
---|
91 | // FIXME this may fail if new lowvalue > old highvalue
|
---|
92 | lowValue.setValue(utils.getLowValue());
|
---|
93 | lowUtility.setValue(utils.getLowUtility());
|
---|
94 | highValue.setValue(utils.getHighValue());
|
---|
95 | highUtility.setValue(utils.getHighUtility());
|
---|
96 | }
|
---|
97 | }; |
---|