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 |
|
---|
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. If power=1 for all participants (usually the
|
---|
22 | * default) power can be interpreted as number of votes
|
---|
23 | */
|
---|
24 | @JsonCreator
|
---|
25 | public Vote(@JsonProperty("actor") PartyId id, @JsonProperty("bid") Bid bid,
|
---|
26 | @JsonProperty("minPower") Integer minPower) {
|
---|
27 | super(id, bid);
|
---|
28 | this.minPower = minPower;
|
---|
29 | if (bid == null || minPower == null || minPower < 1) {
|
---|
30 | throw new IllegalArgumentException(
|
---|
31 | "Vote must have non-null bid and minVotes, and minVotes must be >=1");
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | *
|
---|
37 | * @return the minimum number of votes this bid must get in order for the
|
---|
38 | * vote to be valid.
|
---|
39 | */
|
---|
40 | public Integer getMinPower() {
|
---|
41 | return minPower;
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public String toString() {
|
---|
46 | return "Vote[" + getActor() + "," + getBid() + "," + minPower + "]";
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public int hashCode() {
|
---|
51 | final int prime = 31;
|
---|
52 | int result = super.hashCode();
|
---|
53 | result = prime * result
|
---|
54 | + ((minPower == null) ? 0 : minPower.hashCode());
|
---|
55 | return result;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public boolean equals(Object obj) {
|
---|
60 | if (this == obj)
|
---|
61 | return true;
|
---|
62 | if (!super.equals(obj))
|
---|
63 | return false;
|
---|
64 | if (getClass() != obj.getClass())
|
---|
65 | return false;
|
---|
66 | Vote other = (Vote) obj;
|
---|
67 | if (minPower == null) {
|
---|
68 | if (other.minPower != null)
|
---|
69 | return false;
|
---|
70 | } else if (!minPower.equals(other.minPower))
|
---|
71 | return false;
|
---|
72 | return true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | }
|
---|