package geniusweb.inform; import java.util.Collections; import java.util.LinkedList; import java.util.List; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import geniusweb.actions.PartyId; import geniusweb.actions.Votes; /** * Informs party that it's time to Opt-in. */ public class OptIn implements Inform { private final List votes; /** * @param votes a list of votes. There may be only one votes per party. */ @JsonCreator public OptIn(@JsonProperty("votes") List votes) { this.votes = votes; List partyVotes = new LinkedList<>(); for (Votes vote : votes) { PartyId party = vote.getActor(); if (partyVotes.contains(party)) throw new IllegalArgumentException( "OptIn contains multiple Votes for party " + party); partyVotes.add(party); } } /** * @return list of votes that can be opted in to */ public List getVotes() { return Collections.unmodifiableList(votes); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((votes == null) ? 0 : votes.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; OptIn other = (OptIn) obj; if (votes == null) { if (other.votes != null) return false; } else if (!votes.equals(other.votes)) return false; return true; } @Override public String toString() { return "OptIn[" + votes + "]"; } }