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

Last change on this file since 1355 was 1116, checked in by wouter, 2 months ago

#363 small cleanup in test code

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