| 12
 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
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 
 |  
import java.util.HashMap;
import java.util.Map;
 
public class Test {
	static final class Foo {
		private String a, d, e;
		private final String b, c;
 
		public Foo(String b, String c) {
			this.b = b;
			this.c = c;
		}
 
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			Foo other = (Foo) obj;
			if (b == null) {
				if (other.b != null) {
					return false;
				}
			} else if (!b.equals(other.b)) {
				return false;
			}
			if (c == null) {
				if (other.c != null) {
					return false;
				}
			} else if (!c.equals(other.c)) {
				return false;
			}
			return true;
		}
 
		public String getA() {
			return a;
		}
 
		public String getD() {
			return d;
		}
 
		public String getE() {
			return e;
		}
 
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + (b == null ? 0 : b.hashCode());
			result = prime * result + (c == null ? 0 : c.hashCode());
			return result;
		}
 
		public void setA(String a) {
			this.a = a;
		}
 
		public void setD(String d) {
			this.d = d;
		}
 
		public void setE(String e) {
			this.e = e;
		}
	}
 
	public static void main(String[] args) {
		Map<Foo, Object> map = new HashMap<Foo, Object>();
 
		Foo f1 = new Foo("foo1", "foo1");
		map.put(f1, "blabla");
		Foo f2 = new Foo("foo2", "foo2");
		map.put(f2, "blabla");
		Foo f3 = new Foo("foo3", "foo3");
		map.put(f3, "blabla");
		Foo f4 = new Foo("foo4", "foo4");
		map.put(f4, "blabla");
 
		System.out.println(map.containsKey(new Foo("foo1", "foo1"))); // print true
	}
 
} |