source: events/src/main/java/geniusweb/actions/PartyId.java@ 53

Last change on this file since 53 was 52, checked in by ruud, 21 months ago

Fixed small issues in domaineditor.

File size: 1.7 KB
Line 
1package geniusweb.actions;
2
3import com.fasterxml.jackson.annotation.JsonValue;
4
5/**
6 * Unique ID of a party in a negotiation. The name should start with a short
7 * string indicating the party (eg, the party name plus some machine
8 * identifier), optionally followed by an "_", and more characters to make the
9 * partyid unique. We require the name and "-" so that the string up to the
10 * first "-" can be used to determine between sessions which opponents are
11 * instances of the same class.
12 * <h2>Note</h2> Normally, negotiation parties should not create new Party IDs
13 * as all needed IDs should be provided by the protocol.
14 */
15public final class PartyId {
16 @JsonValue
17 private final String name;
18
19 /**
20 *
21 * @param name a simple name, starting with letter, followed by zero or more
22 * letters, digits or _.
23 */
24 public PartyId(String name) {
25 if (name == null || !name.matches("[a-zA-Z]\\w*")) {
26 throw new IllegalArgumentException("name '" + name
27 + "' is not a letter followed by zero or more word characters (letter, digit or _)");
28 }
29 this.name = name;
30 }
31
32 public String getName() {
33 return name;
34 }
35
36 @Override
37 public String toString() {
38 return name;
39 }
40
41 @Override
42 public int hashCode() {
43 final int prime = 31;
44 int result = 1;
45 result = prime * result + ((name == null) ? 0 : name.hashCode());
46 return result;
47 }
48
49 @Override
50 public boolean equals(Object obj) {
51 if (this == obj)
52 return true;
53 if (obj == null)
54 return false;
55 if (getClass() != obj.getClass())
56 return false;
57 PartyId other = (PartyId) obj;
58 if (name == null) {
59 if (other.name != null)
60 return false;
61 } else if (!name.equals(other.name))
62 return false;
63 return true;
64 }
65
66}
Note: See TracBrowser for help on using the repository browser.