source: events/src/main/java/geniusweb/actions/VoteWithValue.java@ 46

Last change on this file since 46 was 46, checked in by bart, 3 years ago

refactor to help reusing partiesserver

File size: 3.6 KB
Line 
1package geniusweb.actions;
2
3import com.fasterxml.jackson.annotation.JsonCreator;
4import com.fasterxml.jackson.annotation.JsonProperty;
5
6import geniusweb.issuevalue.Bid;
7
8/**
9 * A vote is an indication by a party that it conditionally accepts a bid. It's
10 * then up to the protocol to determine the outcome.
11 */
12public class VoteWithValue extends ActionWithBid {
13 private final Integer minPower;
14 private final Integer maxPower;
15 private final Integer value;
16
17 /**
18 * @param id the {@link PartyId} that does the action
19 * @param bid the bid that is voted on
20 * @param minPower the minimum power this bid must get in order for the vote
21 * to be valid. Power is the sum of the powers of the
22 * parties that are in the deal. If power=1 for all
23 * participants (usually the default) power can be
24 * interpreted as number of votes
25 * @param maxPower the maximum power this bid must get in order for the vote
26 * to be valid. See {@link #minPower}
27 * @param value the value for this vote. An integer in [1,100]. Higher
28 * means that the actor likes this bid better. Note: value 0
29 * is reserved for "unacceptable" and therefore can not be
30 * used as a valid value.
31 */
32 @JsonCreator
33 public VoteWithValue(@JsonProperty("actor") PartyId id,
34 @JsonProperty("bid") Bid bid,
35 @JsonProperty("minPower") Integer minPower,
36 @JsonProperty("maxPower") Integer maxPower,
37 @JsonProperty("value") Integer value) {
38 super(id, bid);
39 this.minPower = minPower;
40 this.maxPower = maxPower;
41 this.value = value;
42 if (value < 1 || value > 100)
43 throw new IllegalArgumentException(
44 "value must be in [1,100] but got " + value);
45 if (bid == null || minPower == null || minPower < 1 || maxPower == null
46 || maxPower < minPower) {
47 throw new IllegalArgumentException(
48 "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower");
49 }
50 }
51
52 /**
53 *
54 * @return the minimum power this bid must get in order for the vote to be
55 * valid.
56 */
57 public Integer getMinPower() {
58 return minPower;
59 }
60
61 /**
62 *
63 * @return the max power this bid must get in order for the vote to be
64 * valid.
65 */
66 public Integer getMaxPower() {
67 return maxPower;
68 }
69
70 /**
71 *
72 * @return the value for this vote. An integer in [1,100]. Higher means that
73 * the actor likes this bid better.
74 *
75 */
76 public Integer getValue() {
77 return value;
78 }
79
80 @Override
81 public String toString() {
82 return "VoteWithValue[" + getActor() + "," + getBid() + "," + minPower
83 + "," + maxPower + "," + value + "]";
84 }
85
86 @Override
87 public int hashCode() {
88 final int prime = 31;
89 int result = super.hashCode();
90 result = prime * result
91 + ((maxPower == null) ? 0 : maxPower.hashCode());
92 result = prime * result
93 + ((minPower == null) ? 0 : minPower.hashCode());
94 result = prime * result + ((value == null) ? 0 : value.hashCode());
95 return result;
96 }
97
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj)
101 return true;
102 if (!super.equals(obj))
103 return false;
104 if (getClass() != obj.getClass())
105 return false;
106 VoteWithValue other = (VoteWithValue) obj;
107 if (maxPower == null) {
108 if (other.maxPower != null)
109 return false;
110 } else if (!maxPower.equals(other.maxPower))
111 return false;
112 if (minPower == null) {
113 if (other.minPower != null)
114 return false;
115 } else if (!minPower.equals(other.minPower))
116 return false;
117 if (value == null) {
118 if (other.value != null)
119 return false;
120 } else if (!value.equals(other.value))
121 return false;
122 return true;
123 }
124
125}
Note: See TracBrowser for help on using the repository browser.