source: events/src/main/java/geniusweb/actions/Vote.java@ 53

Last change on this file since 53 was 52, checked in by ruud, 21 months ago

Fixed small issues in domaineditor.

File size: 2.7 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 Vote extends ActionWithBid {
13 private final Integer minPower;
14 private final Integer maxPower;
15
16 /**
17 * @param actor the {@link PartyId} that does the action
18 * @param bid the bid that is voted on
19 * @param minPower the minimum power this bid must get in order for the vote
20 * to be valid. Power is the sum of the powers of the
21 * parties that are in the deal. If power=1 for all
22 * participants (usually the default) power can be
23 * interpreted as number of votes
24 * @param maxPower the maximum power this bid must get in order for the vote
25 * to be valid. See {@link #minPower}
26 */
27 @JsonCreator
28 public Vote(@JsonProperty("actor") PartyId actor,
29 @JsonProperty("bid") Bid bid,
30 @JsonProperty("minPower") Integer minPower,
31 @JsonProperty("maxPower") Integer maxPower) {
32 super(actor, bid);
33 this.minPower = minPower;
34 this.maxPower = maxPower;
35 if (bid == null || minPower == null || minPower < 1 || maxPower == null
36 || maxPower < minPower) {
37 throw new IllegalArgumentException(
38 "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower");
39 }
40 }
41
42 /**
43 *
44 * @return the minimum power this bid must get in order for the vote to be
45 * valid.
46 */
47 public Integer getMinPower() {
48 return minPower;
49 }
50
51 /**
52 *
53 * @return the max power this bid must get in order for the vote to be
54 * valid.
55 */
56
57 public Integer getMaxPower() {
58 return maxPower;
59 }
60
61 @Override
62 public String toString() {
63 return "Vote[" + getActor() + "," + getBid() + "," + minPower + ","
64 + maxPower + "]";
65 }
66
67 @Override
68 public int hashCode() {
69 final int prime = 31;
70 int result = super.hashCode();
71 result = prime * result
72 + ((maxPower == null) ? 0 : maxPower.hashCode());
73 result = prime * result
74 + ((minPower == null) ? 0 : minPower.hashCode());
75 return result;
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj)
81 return true;
82 if (!super.equals(obj))
83 return false;
84 if (getClass() != obj.getClass())
85 return false;
86 Vote other = (Vote) obj;
87 if (maxPower == null) {
88 if (other.maxPower != null)
89 return false;
90 } else if (!maxPower.equals(other.maxPower))
91 return false;
92 if (minPower == null) {
93 if (other.minPower != null)
94 return false;
95 } else if (!minPower.equals(other.minPower))
96 return false;
97 return true;
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.