1 | package genius.core.session;
|
---|
2 |
|
---|
3 | import genius.core.AgentID;
|
---|
4 | import genius.core.parties.Mediator;
|
---|
5 | import genius.core.repository.ParticipantRepItem;
|
---|
6 | import genius.core.repository.ProfileRepItem;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Contains full participant info: the party name, strategy and profile.
|
---|
10 | * Equality only involves the party NAME, as names should be unique in a
|
---|
11 | * negotiation. mediators are also participants. immutable.
|
---|
12 | */
|
---|
13 | public class Participant {
|
---|
14 | private AgentID id;
|
---|
15 | private ParticipantRepItem strategy;
|
---|
16 | private ProfileRepItem profile;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | * @param id
|
---|
21 | * the agent ID
|
---|
22 | * @param party
|
---|
23 | * the {@link ParticipantRepItem} to use for this participant.
|
---|
24 | * @param profile
|
---|
25 | * The profile that this participant uses. can be null if this
|
---|
26 | * participant does not need a profile (eg, {@link Mediator}.
|
---|
27 | */
|
---|
28 | public Participant(AgentID id, ParticipantRepItem party,
|
---|
29 | ProfileRepItem profile) {
|
---|
30 | if (id == null || party == null || profile == null) {
|
---|
31 | throw new IllegalArgumentException("parameter is null");
|
---|
32 | }
|
---|
33 | this.id = id;
|
---|
34 | this.strategy = party;
|
---|
35 | this.profile = profile;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public AgentID getId() {
|
---|
39 | return id;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public ParticipantRepItem getStrategy() {
|
---|
43 | return strategy;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public ProfileRepItem getProfile() {
|
---|
47 | return profile;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public int hashCode() {
|
---|
52 | final int prime = 31;
|
---|
53 | int result = 1;
|
---|
54 | result = prime * result + ((id == null) ? 0 : id.hashCode());
|
---|
55 | return result;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Equals is based only on the agent id.
|
---|
60 | */
|
---|
61 | @Override
|
---|
62 | public boolean equals(Object obj) {
|
---|
63 | if (this == obj)
|
---|
64 | return true;
|
---|
65 | if (obj == null)
|
---|
66 | return false;
|
---|
67 | if (getClass() != obj.getClass())
|
---|
68 | return false;
|
---|
69 | Participant other = (Participant) obj;
|
---|
70 | if (id == null) {
|
---|
71 | if (other.id != null)
|
---|
72 | return false;
|
---|
73 | } else if (!id.equals(other.id))
|
---|
74 | return false;
|
---|
75 | return true;
|
---|
76 | }
|
---|
77 |
|
---|
78 | @Override
|
---|
79 | public String toString() {
|
---|
80 | return "Participant[" + id + "," + strategy + "," + profile + "]";
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|