source: protocol/src/main/java/geniusweb/protocol/session/SessionResult.java

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

Fixed small issues in domaineditor.

File size: 5.2 KB
Line 
1package geniusweb.protocol.session;
2
3import java.util.Collections;
4import java.util.HashMap;
5import java.util.Map;
6
7import com.fasterxml.jackson.annotation.JsonAutoDetect;
8import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
9import com.fasterxml.jackson.annotation.JsonCreator;
10import com.fasterxml.jackson.annotation.JsonProperty;
11import com.fasterxml.jackson.annotation.JsonTypeInfo;
12
13import geniusweb.actions.PartyId;
14import geniusweb.inform.Agreements;
15import geniusweb.references.PartyWithProfile;
16
17/**
18 * All results collected from running a session. Normally this does not contain
19 * all the details, only the final outcome and other global notes.
20 */
21@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
22public class SessionResult {
23 private final Map<PartyId, PartyWithProfile> participants;
24 private final Agreements agreements;
25 private final Map<PartyId, Double> penalties;
26
27 // add more type info so that jackson can deserialize the actual class
28 @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT)
29 private final Throwable error;
30
31 /**
32 *
33 * @param participants the list oof {@link PartyWithProfile}. Should never
34 * be null. Some of them may have entered later of left
35 * early. This list should contain them all.
36 * @param agreements the final Agreements. The key is the party ID, value
37 * is the bid that the party agreed on. Only parties
38 * that reached an agreement are in this list.
39 * @param penalties Key is the party ID, the value is the penalties in
40 * [0,1] for that participant. A penalty only applies to
41 * an agreement, not to a reservation bid.
42 * @param error a fatal error that terminated the session. Non-fatal
43 * errors (warnings) are not to be reported. Null if no
44 * fatal error occured (session ended following the
45 * protocol). Normally, a fatal error results in no
46 * agreement but there might be protocols that allow a
47 * session to end with an error but stick with a already
48 * reached agreement as well.
49 */
50 @JsonCreator
51 public SessionResult(
52 @JsonProperty("participants") Map<PartyId, PartyWithProfile> participants,
53 @JsonProperty("agreements") Agreements agreements,
54 @JsonProperty("penalties") Map<PartyId, Double> penalties,
55 @JsonProperty("error") Throwable error) {
56 this.participants = new HashMap<>(participants);
57 this.agreements = agreements;
58 this.penalties = new HashMap<>(penalties);
59 this.error = error;
60 }
61
62 /**
63 *
64 * @return the map with for each {@link PartyId} the
65 * {@link PartyWithProfile}. Should never be null. Some of them may
66 * have entered later of left early. This list should contain them
67 * all.
68 */
69 public Map<PartyId, PartyWithProfile> getParticipants() {
70 return Collections.unmodifiableMap(participants);
71 }
72
73 /**
74 * @return the final {@link Agreements} of the session. May be empty, not
75 * null
76 */
77 public Agreements getAgreements() {
78 return agreements;
79 };
80
81 /**
82 *
83 * @return Map of penalties,
84 */
85 public Map<PartyId, Double> getPenalties() {
86 return Collections.unmodifiableMap(penalties);
87 }
88
89 /**
90 *
91 * @return a fatal error that terminated the session. Non-fatal errors
92 * (warnings) are not to be reported. Null if no fatal error occured
93 * (session ended following the protocol). Normally, a fatal error
94 * results in no agreement but there might be protocols that allow a
95 * session to end with an error but stick with a already reached
96 * agreement as well.
97 */
98 public Throwable getError() {
99 return error;
100 }
101
102 @Override
103 public String toString() {
104 return "SessionResult[" + participants + "," + agreements + ","
105 + penalties + "," + error + "]";
106 }
107
108 @Override
109 public int hashCode() {
110 final int prime = 31;
111 int result = 1;
112 result = prime * result
113 + ((agreements == null) ? 0 : agreements.hashCode());
114 result = prime * result + ((error == null) ? 0 : error.hashCode());
115 result = prime * result
116 + ((participants == null) ? 0 : participants.hashCode());
117 result = prime * result
118 + ((penalties == null) ? 0 : penalties.hashCode());
119 return result;
120 }
121
122 @Override
123 public boolean equals(Object obj) {
124 if (this == obj)
125 return true;
126 if (obj == null)
127 return false;
128 if (getClass() != obj.getClass())
129 return false;
130 SessionResult other = (SessionResult) obj;
131 if (agreements == null) {
132 if (other.agreements != null)
133 return false;
134 } else if (!agreements.equals(other.agreements))
135 return false;
136 if (error == null) {
137 if (other.error != null)
138 return false;
139 } else if (!error.equals(other.error))
140 return false;
141 if (participants == null) {
142 if (other.participants != null)
143 return false;
144 } else if (!participants.equals(other.participants))
145 return false;
146 if (penalties == null) {
147 if (other.penalties != null)
148 return false;
149 } else if (!penalties.equals(other.penalties))
150 return false;
151 return true;
152 }
153
154}
Note: See TracBrowser for help on using the repository browser.