package geniusweb.actions; import com.fasterxml.jackson.annotation.JsonValue; /** * Globally (that is, worldwide) unique ID of a party in a negotiation. * Normally, negotiation parties should not create new Party IDs as all needed * IDs should be provided by the protocol. Serializes only as part of a bigger * object. This ID may contain parts of an ip address but that address should * not be used to make contact. */ 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; } }