diff options
Diffstat (limited to 'src/main/java/derms/City.java')
| -rw-r--r-- | src/main/java/derms/City.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/derms/City.java b/src/main/java/derms/City.java new file mode 100644 index 0000000..9fc71b8 --- /dev/null +++ b/src/main/java/derms/City.java @@ -0,0 +1,40 @@ +package derms; + +import java.io.Serializable; + +public class City implements Serializable { + public static final int codeLen = 3; + + private String code; + + public City(String code) throws IllegalArgumentException { + if (code.length() != codeLen) + throw new IllegalArgumentException("Invalid city: "+code+"; must be "+codeLen+" letters"); + this.code = code; + } + + public City() { + this("XXX"); + } + + public String getCode() { return code; } + + @Override + public String toString() { + return code; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || this.getClass() != obj.getClass()) { + return false; + } + City other = (City) obj; + return this.code.equals(other.code); + } + + @Override + public int hashCode() { + return code.hashCode(); + } +} |