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

Last change on this file since 4 was 1, checked in by bart, 5 years ago

Initial Release

File size: 1.5 KB
Line 
1package geniusweb.actions;
2
3import com.fasterxml.jackson.annotation.JsonValue;
4
5/**
6 * Globally (that is, worldwide) unique ID of a party in a negotiation.
7 * Normally, negotiation parties should not create new Party IDs as all needed
8 * IDs should be provided by the protocol. Serializes only as part of a bigger
9 * object. This ID may contain parts of an ip address but that address should
10 * not be used to make contact.
11 */
12public final class PartyId {
13 @JsonValue
14 private final String name;
15
16 /**
17 *
18 * @param name a simple name, starting with letter, followed by zero or more
19 * letters, digits or _.
20 */
21 public PartyId(String name) {
22 if (name == null || !name.matches("[a-zA-Z]\\w*")) {
23 throw new IllegalArgumentException("name '" + name
24 + "' is not a letter followed by zero or more word characters (letter, digit or _)");
25 }
26 this.name = name;
27 }
28
29 public String getName() {
30 return name;
31 }
32
33 @Override
34 public String toString() {
35 return name;
36 }
37
38 @Override
39 public int hashCode() {
40 final int prime = 31;
41 int result = 1;
42 result = prime * result + ((name == null) ? 0 : name.hashCode());
43 return result;
44 }
45
46 @Override
47 public boolean equals(Object obj) {
48 if (this == obj)
49 return true;
50 if (obj == null)
51 return false;
52 if (getClass() != obj.getClass())
53 return false;
54 PartyId other = (PartyId) obj;
55 if (name == null) {
56 if (other.name != null)
57 return false;
58 } else if (!name.equals(other.name))
59 return false;
60 return true;
61 }
62
63}
Note: See TracBrowser for help on using the repository browser.