source: java2python/jackson-t/src/test/java/testcode/actions/PartyId.java@ 491

Last change on this file since 491 was 404, checked in by wouter, 2 years ago

#122 refactoring, creating separate packages for java core and jackson-translator (jackson-t)

File size: 1.7 KB
Line 
1package testcode.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 private final String name;
17
18 /**
19 *
20 * @param name a simple name, starting with letter, followed by zero or more
21 * letters, digits or _.
22 */
23 public PartyId(String name) {
24 if (name == null || !name.matches("[a-zA-Z]\\w*")) {
25 throw new IllegalArgumentException("name '" + name
26 + "' is not a letter followed by zero or more word characters (letter, digit or _)");
27 }
28 this.name = name;
29 }
30
31 @JsonValue
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.