[43] | 1 | package geniusweb.inform;
|
---|
| 2 |
|
---|
| 3 | import java.util.Collections;
|
---|
| 4 | import java.util.List;
|
---|
| 5 | import java.util.Map;
|
---|
| 6 |
|
---|
| 7 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
| 9 |
|
---|
| 10 | import geniusweb.actions.Offer;
|
---|
| 11 | import geniusweb.actions.PartyId;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Informs a party that it's time to do voting.
|
---|
| 15 | */
|
---|
| 16 | public class Voting implements Inform {
|
---|
| 17 |
|
---|
| 18 | private final List<Offer> offers;
|
---|
| 19 | private final Map<PartyId, Integer> powers;
|
---|
| 20 |
|
---|
| 21 | @JsonCreator
|
---|
| 22 | public Voting(@JsonProperty("offers") List<Offer> offers,
|
---|
| 23 | @JsonProperty("powers") Map<PartyId, Integer> powers) {
|
---|
| 24 | this.offers = offers;
|
---|
| 25 | this.powers = powers;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * @return list of offers to be voted on
|
---|
| 30 | */
|
---|
| 31 | public List<Offer> getOffers() {
|
---|
| 32 | return Collections.unmodifiableList(offers);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Deprecated
|
---|
| 36 | public List<Offer> getBids() {
|
---|
| 37 | return getOffers();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | *
|
---|
| 42 | * @return map with the power of each party in the negotiation. This map may
|
---|
| 43 | * contain parties that are already finished, eg they reached an
|
---|
| 44 | * agreement or walked away.
|
---|
| 45 | */
|
---|
| 46 | public Map<PartyId, Integer> getPowers() {
|
---|
| 47 | return Collections.unmodifiableMap(powers);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | @Override
|
---|
| 51 | public int hashCode() {
|
---|
| 52 | final int prime = 31;
|
---|
| 53 | int result = 1;
|
---|
| 54 | result = prime * result + ((offers == null) ? 0 : offers.hashCode());
|
---|
| 55 | result = prime * result + ((powers == null) ? 0 : powers.hashCode());
|
---|
| 56 | return result;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | @Override
|
---|
| 60 | public boolean equals(Object obj) {
|
---|
| 61 | if (this == obj)
|
---|
| 62 | return true;
|
---|
| 63 | if (obj == null)
|
---|
| 64 | return false;
|
---|
| 65 | if (getClass() != obj.getClass())
|
---|
| 66 | return false;
|
---|
| 67 | Voting other = (Voting) obj;
|
---|
| 68 | if (offers == null) {
|
---|
| 69 | if (other.offers != null)
|
---|
| 70 | return false;
|
---|
| 71 | } else if (!offers.equals(other.offers))
|
---|
| 72 | return false;
|
---|
| 73 | if (powers == null) {
|
---|
| 74 | if (other.powers != null)
|
---|
| 75 | return false;
|
---|
| 76 | } else if (!powers.equals(other.powers))
|
---|
| 77 | return false;
|
---|
| 78 | return true;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | @Override
|
---|
| 82 | public String toString() {
|
---|
| 83 | return "Voting[" + offers + "," + powers + "]";
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | }
|
---|