1 | package geniusweb.inform;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 |
|
---|
5 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
6 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
7 |
|
---|
8 | import geniusweb.actions.PartyId;
|
---|
9 | import geniusweb.progress.Progress;
|
---|
10 | import geniusweb.references.Parameters;
|
---|
11 | import geniusweb.references.ProfileRef;
|
---|
12 | import geniusweb.references.ProtocolRef;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Informs a {@link Party} about all settings for the upcoming negotiation
|
---|
16 | * session. This should be sent to a party one time, so that the party knows the
|
---|
17 | * 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 Map<String, Object> containing initialization
|
---|
34 | * parameters for this party. The Object can be a HashMap,
|
---|
35 | * ArrayList, String, or number (Integer, Double, etc).
|
---|
36 | * The Object should not be just any Object because
|
---|
37 | * deserialization will work only with the mentioned
|
---|
38 | * 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 HashMap<String,Object> containing initialization parameters
|
---|
88 | * that can be used by the party.
|
---|
89 | */
|
---|
90 | public HashMap<String, Object> 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 | }
|
---|