package geniusweb.actions; import com.fasterxml.jackson.annotation.JsonValue; /** * Unique ID of a party in a negotiation. The name should start with a short * string indicating the party (eg, the party name plus some machine * identifier), optionally followed by an "_", and more characters to make the * partyid unique. We require the name and "-" so that the string up to the * first "-" can be used to determine between sessions which opponents are * instances of the same class. *

Note

Normally, negotiation parties should not create new Party IDs * as all needed IDs should be provided by the protocol. */ public final class PartyId { @JsonValue private final String name; /** * * @param name a simple name, starting with letter, followed by zero or more * letters, digits or _. */ public PartyId(String name) { if (name == null || !name.matches("[a-zA-Z]\\w*")) { throw new IllegalArgumentException("name '" + name + "' is not a letter followed by zero or more word characters (letter, digit or _)"); } this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; PartyId other = (PartyId) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }