[43] | 1 | package geniusweb.inform;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.Map;
|
---|
| 5 |
|
---|
| 6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 7 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
| 8 |
|
---|
| 9 | import geniusweb.actions.PartyId;
|
---|
| 10 | import geniusweb.progress.Progress;
|
---|
| 11 | import geniusweb.references.Parameters;
|
---|
| 12 | import geniusweb.references.ProfileRef;
|
---|
| 13 | import geniusweb.references.ProtocolRef;
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | * Informs a Party about all settings for the upcoming negotiation session. This
|
---|
| 17 | * should be sent to a party one time, so that the party knows the situation.
|
---|
| 18 | *
|
---|
| 19 | */
|
---|
| 20 | public class Settings implements Inform {
|
---|
| 21 | private ProfileRef profile;
|
---|
| 22 | private ProtocolRef protocol;
|
---|
| 23 | private Progress progress;
|
---|
| 24 | private PartyId id;
|
---|
| 25 | private Parameters parameters;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | *
|
---|
| 29 | * @param id the {@link PartyId} for this party
|
---|
| 30 | * @param profile the profile used for this party in this session
|
---|
| 31 | * @param protocol the protocol used in this session
|
---|
| 32 | * @param progress the {@link Progress} object used for this session
|
---|
| 33 | * @param parameters a {@link Map} <String, Object> containing
|
---|
| 34 | * initialization parameters for this party. The Object
|
---|
| 35 | * can be a HashMap, ArrayList, String, or number
|
---|
| 36 | * (Integer, Double, etc). The Object should not be just
|
---|
| 37 | * any Object because deserialization will work only with
|
---|
| 38 | * the mentioned types.
|
---|
| 39 | */
|
---|
| 40 | @JsonCreator
|
---|
| 41 | public Settings(@JsonProperty("id") PartyId id,
|
---|
| 42 | @JsonProperty("profile") ProfileRef profile,
|
---|
| 43 | @JsonProperty("protocol") ProtocolRef protocol,
|
---|
| 44 | @JsonProperty("progress") Progress progress,
|
---|
| 45 | @JsonProperty("parameters") Parameters parameters) {
|
---|
| 46 | if (profile == null || protocol == null || progress == null
|
---|
| 47 | || parameters == null) {
|
---|
| 48 | throw new IllegalArgumentException(
|
---|
| 49 | "party, profile, protocol, parameters and progress must be not null.");
|
---|
| 50 | }
|
---|
| 51 | this.profile = profile;
|
---|
| 52 | this.protocol = protocol;
|
---|
| 53 | this.progress = progress;
|
---|
| 54 | this.parameters = parameters;
|
---|
| 55 | this.id = id;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | *
|
---|
| 60 | * @return the profile used for this party in this session
|
---|
| 61 | */
|
---|
| 62 | public ProfileRef getProfile() {
|
---|
| 63 | return profile;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public ProtocolRef getProtocol() {
|
---|
| 67 | return protocol;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | *
|
---|
| 72 | * @return the {@link Progress} object used for this session
|
---|
| 73 | */
|
---|
| 74 | public Progress getProgress() {
|
---|
| 75 | return progress;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * @return the party ID of this party
|
---|
| 80 | */
|
---|
| 81 | public PartyId getID() {
|
---|
| 82 | return id;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
| 86 | *
|
---|
| 87 | * @return a {@link HashMap}<String,Object> containing initialization
|
---|
| 88 | * parameters that can be used by the party.
|
---|
| 89 | */
|
---|
| 90 | public Parameters getParameters() {
|
---|
| 91 | return parameters;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | @Override
|
---|
| 95 | public String toString() {
|
---|
| 96 | return "Settings[" + id + "," + profile + "," + protocol + ","
|
---|
| 97 | + progress + "," + parameters + "]";
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | @Override
|
---|
| 101 | public int hashCode() {
|
---|
| 102 | final int prime = 31;
|
---|
| 103 | int result = 1;
|
---|
| 104 | result = prime * result + ((id == null) ? 0 : id.hashCode());
|
---|
| 105 | result = prime * result
|
---|
| 106 | + ((parameters == null) ? 0 : parameters.hashCode());
|
---|
| 107 | result = prime * result + ((profile == null) ? 0 : profile.hashCode());
|
---|
| 108 | result = prime * result
|
---|
| 109 | + ((progress == null) ? 0 : progress.hashCode());
|
---|
| 110 | result = prime * result
|
---|
| 111 | + ((protocol == null) ? 0 : protocol.hashCode());
|
---|
| 112 | return result;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | @Override
|
---|
| 116 | public boolean equals(Object obj) {
|
---|
| 117 | if (this == obj)
|
---|
| 118 | return true;
|
---|
| 119 | if (obj == null)
|
---|
| 120 | return false;
|
---|
| 121 | if (getClass() != obj.getClass())
|
---|
| 122 | return false;
|
---|
| 123 | Settings other = (Settings) obj;
|
---|
| 124 | if (id == null) {
|
---|
| 125 | if (other.id != null)
|
---|
| 126 | return false;
|
---|
| 127 | } else if (!id.equals(other.id))
|
---|
| 128 | return false;
|
---|
| 129 | if (parameters == null) {
|
---|
| 130 | if (other.parameters != null)
|
---|
| 131 | return false;
|
---|
| 132 | } else if (!parameters.equals(other.parameters))
|
---|
| 133 | return false;
|
---|
| 134 | if (profile == null) {
|
---|
| 135 | if (other.profile != null)
|
---|
| 136 | return false;
|
---|
| 137 | } else if (!profile.equals(other.profile))
|
---|
| 138 | return false;
|
---|
| 139 | if (progress == null) {
|
---|
| 140 | if (other.progress != null)
|
---|
| 141 | return false;
|
---|
| 142 | } else if (!progress.equals(other.progress))
|
---|
| 143 | return false;
|
---|
| 144 | if (protocol == null) {
|
---|
| 145 | if (other.protocol != null)
|
---|
| 146 | return false;
|
---|
| 147 | } else if (!protocol.equals(other.protocol))
|
---|
| 148 | return false;
|
---|
| 149 | return true;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | }
|
---|