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

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

Major update. Changes in json serialization, maven dependencies and BOA. Fix in stand-alone runner.

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 id 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 id, @JsonProperty("bid") Bid bid,
29 @JsonProperty("minPower") Integer minPower,
30 @JsonProperty("maxPower") Integer maxPower) {
31 super(id, bid);
32 this.minPower = minPower;
33 this.maxPower = maxPower;
34 if (bid == null || minPower == null || minPower < 1 || maxPower == null
35 || maxPower < minPower) {
36 throw new IllegalArgumentException(
37 "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower");
38 }
39 }
40
41 /**
42 *
43 * @return the minimum power this bid must get in order for the vote to be
44 * valid.
45 */
46 public Integer getMinPower() {
47 return minPower;
48 }
49
50 /**
51 *
52 * @return the max power this bid must get in order for the vote to be
53 * valid.
54 */
55
56 public Integer getMaxPower() {
57 return maxPower;
58 }
59
60 @Override
61 public String toString() {
62 return "Vote[" + getActor() + "," + getBid() + "," + minPower + ","
63 + maxPower + "]";
64 }
65
66 @Override
67 public int hashCode() {
68 final int prime = 31;
69 int result = super.hashCode();
70 result = prime * result
71 + ((maxPower == null) ? 0 : maxPower.hashCode());
72 result = prime * result
73 + ((minPower == null) ? 0 : minPower.hashCode());
74 return result;
75 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj)
80 return true;
81 if (!super.equals(obj))
82 return false;
83 if (getClass() != obj.getClass())
84 return false;
85 Vote other = (Vote) obj;
86 if (maxPower == null) {
87 if (other.maxPower != null)
88 return false;
89 } else if (!maxPower.equals(other.maxPower))
90 return false;
91 if (minPower == null) {
92 if (other.minPower != null)
93 return false;
94 } else if (!minPower.equals(other.minPower))
95 return false;
96 return true;
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.