package geniusweb.actions; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import geniusweb.issuevalue.Bid; /** * A vote is an indication by a party that it conditionally accepts a bid. It's * then up to the protocol to determine the outcome. */ public class Vote extends ActionWithBid { private final Integer minPower; private final Integer maxPower; /** * @param actor the {@link PartyId} that does the action * @param bid the bid that is voted on * @param minPower the minimum power this bid must get in order for the vote * to be valid. Power is the sum of the powers of the * parties that are in the deal. If power=1 for all * participants (usually the default) power can be * interpreted as number of votes * @param maxPower the maximum power this bid must get in order for the vote * to be valid. See {@link #minPower} */ @JsonCreator public Vote(@JsonProperty("actor") PartyId actor, @JsonProperty("bid") Bid bid, @JsonProperty("minPower") Integer minPower, @JsonProperty("maxPower") Integer maxPower) { super(actor, bid); this.minPower = minPower; this.maxPower = maxPower; if (bid == null || minPower == null || minPower < 1 || maxPower == null || maxPower < minPower) { throw new IllegalArgumentException( "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower"); } } /** * * @return the minimum power this bid must get in order for the vote to be * valid. */ public Integer getMinPower() { return minPower; } /** * * @return the max power this bid must get in order for the vote to be * valid. */ public Integer getMaxPower() { return maxPower; } @Override public String toString() { return "Vote[" + getActor() + "," + getBid() + "," + minPower + "," + maxPower + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((maxPower == null) ? 0 : maxPower.hashCode()); result = prime * result + ((minPower == null) ? 0 : minPower.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; Vote other = (Vote) obj; if (maxPower == null) { if (other.maxPower != null) return false; } else if (!maxPower.equals(other.maxPower)) return false; if (minPower == null) { if (other.minPower != null) return false; } else if (!minPower.equals(other.minPower)) return false; return true; } }