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