source: events/src/main/java/geniusweb/inform/OptIn.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.6 KB
Line 
1package geniusweb.inform;
2
3import java.util.Collections;
4import java.util.LinkedList;
5import java.util.List;
6
7import com.fasterxml.jackson.annotation.JsonCreator;
8import com.fasterxml.jackson.annotation.JsonProperty;
9
10import geniusweb.actions.PartyId;
11import geniusweb.actions.Votes;
12
13/**
14 * Informs party that it's time to Opt-in.
15 */
16public class OptIn implements Inform {
17
18 private final List<Votes> votes;
19
20 /**
21 * @param votes a list of votes. There may be only one votes per party.
22 */
23 @JsonCreator
24 public OptIn(@JsonProperty("votes") List<Votes> votes) {
25 this.votes = votes;
26
27 List<PartyId> partyVotes = new LinkedList<>();
28 for (Votes vote : votes) {
29 PartyId party = vote.getActor();
30 if (partyVotes.contains(party))
31 throw new IllegalArgumentException(
32 "OptIn contains multiple Votes for party " + party);
33 partyVotes.add(party);
34 }
35 }
36
37 /**
38 * @return list of votes that can be opted in to
39 */
40 public List<Votes> getVotes() {
41 return Collections.unmodifiableList(votes);
42 }
43
44 @Override
45 public int hashCode() {
46 final int prime = 31;
47 int result = 1;
48 result = prime * result + ((votes == null) ? 0 : votes.hashCode());
49 return result;
50 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (this == obj)
55 return true;
56 if (obj == null)
57 return false;
58 if (getClass() != obj.getClass())
59 return false;
60 OptIn other = (OptIn) obj;
61 if (votes == null) {
62 if (other.votes != null)
63 return false;
64 } else if (!votes.equals(other.votes))
65 return false;
66 return true;
67 }
68
69 @Override
70 public String toString() {
71 return "OptIn[" + votes + "]";
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.