package geniusweb.actions; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; 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. */ @JsonTypeName("votewithvalue") public class VoteWithValue extends ActionWithBid { private final Integer minPower; private final Integer maxPower; private final Integer value; /** * @param id 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} * @param value the value for this vote. An integer in [1,100]. Higher * means that the actor likes this bid better. Note: value 0 * is reserved for "unacceptable" and therefore can not be * used as a valid value. */ @JsonCreator public VoteWithValue(@JsonProperty("actor") PartyId id, @JsonProperty("bid") Bid bid, @JsonProperty("minPower") Integer minPower, @JsonProperty("maxPower") Integer maxPower, @JsonProperty("value") Integer value) { super(id, bid); this.minPower = minPower; this.maxPower = maxPower; this.value = value; if (value < 1 || value > 100) throw new IllegalArgumentException( "value must be in [1,100] but got " + value); 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; } /** * * @return the value for this vote. An integer in [1,100]. Higher means that * the actor likes this bid better. * */ public Integer getValue() { return value; } @Override public String toString() { return "VoteWithValue[" + getActor() + "," + getBid() + "," + minPower + "," + maxPower + "," + value + "]"; } @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()); result = prime * result + ((value == null) ? 0 : value.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; VoteWithValue other = (VoteWithValue) 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; if (value == null) { if (other.value != null) return false; } else if (!value.equals(other.value)) return false; return true; } }