summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica3/City.java
blob: 89fd8ce8bf8b7b2c99d38ba45e16f2b46f46f3ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package derms.replica3;

import java.io.Serializable;

public class City implements Serializable {
	static final int codeLen = 3;

	private String code;

	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();
	}
}