1 | package geniusweb.voting.evaluatorwithvalue;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 |
|
---|
5 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
6 | import com.fasterxml.jackson.annotation.JsonIgnore;
|
---|
7 |
|
---|
8 | import geniusweb.inform.Agreements;
|
---|
9 | import geniusweb.voting.CollectedVotesWithValue;
|
---|
10 | import geniusweb.voting.VotingEvaluatorWithValue;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Take the first possible agreement, and take the largest possible agreement.
|
---|
14 | * Stop after first agreement.
|
---|
15 | */
|
---|
16 | public class LargestAgreementWithValue implements VotingEvaluatorWithValue {
|
---|
17 | @JsonIgnore
|
---|
18 | private final CollectedVotesWithValue allVotes;
|
---|
19 |
|
---|
20 | // caching
|
---|
21 | @JsonIgnore
|
---|
22 | private Agreements maxAgreements = null;
|
---|
23 |
|
---|
24 | @JsonCreator
|
---|
25 | public LargestAgreementWithValue() {
|
---|
26 | this(new CollectedVotesWithValue(Collections.emptyMap(),
|
---|
27 | Collections.emptyMap()));
|
---|
28 | }
|
---|
29 |
|
---|
30 | protected LargestAgreementWithValue(CollectedVotesWithValue votes) {
|
---|
31 | this.allVotes = votes;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public Agreements getAgreements() {
|
---|
36 | if (maxAgreements == null)
|
---|
37 | maxAgreements = new Agreements(allVotes.getMaxAgreements());
|
---|
38 | return maxAgreements;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public boolean isFinished() {
|
---|
43 | return getAgreements().getMap().isEmpty();
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public VotingEvaluatorWithValue create(CollectedVotesWithValue votes) {
|
---|
48 | return new LargestAgreementWithValue(votes);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public int hashCode() {
|
---|
53 | final int prime = 31;
|
---|
54 | int result = 1;
|
---|
55 | result = prime * result
|
---|
56 | + ((allVotes == null) ? 0 : allVotes.hashCode());
|
---|
57 | return result;
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public boolean equals(Object obj) {
|
---|
62 | if (this == obj)
|
---|
63 | return true;
|
---|
64 | if (obj == null)
|
---|
65 | return false;
|
---|
66 | if (getClass() != obj.getClass())
|
---|
67 | return false;
|
---|
68 | LargestAgreementWithValue other = (LargestAgreementWithValue) obj;
|
---|
69 | if (allVotes == null) {
|
---|
70 | if (other.allVotes != null)
|
---|
71 | return false;
|
---|
72 | } else if (!allVotes.equals(other.allVotes))
|
---|
73 | return false;
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public String toString() {
|
---|
79 | return "LargestAgreement";
|
---|
80 | }
|
---|
81 | }
|
---|