Skip to content

Method: equals(Object)

1: package de.fhdw.wtf.persistence.utils;
2:
3: /**
4: * Implementation of a generic Tuple of two Types X and Y.
5: *
6: * @param <X>
7: * @param <Y>
8: */
9: public class Tuple<X, Y> {
10:         
11:         private final X first;
12:         
13:         private final Y second;
14:         
15:         /**
16:          *
17:          * @return the first Component
18:          */
19:         public X getFirst() {
20:                 return this.first;
21:         }
22:         
23:         /**
24:          *
25:          * @return the second Component
26:          */
27:         public Y getSecond() {
28:                 return this.second;
29:         }
30:         
31:         /**
32:          * Constructor for a new tuple with first and, second.
33:          *
34:          * @param first
35:          * @param second
36:          */
37:         public Tuple(final X first, final Y second) {
38:                 super();
39:                 this.first = first;
40:                 this.second = second;
41:         }
42:         
43:         @SuppressWarnings("rawtypes")
44:         @Override
45:         public boolean equals(final java.lang.Object obj) {
46:•                if (obj instanceof Tuple) {
47:                         return this.customEquals((Tuple) obj);
48:                 }
49:                 return false;
50:         }
51:         
52:         private boolean customEquals(@SuppressWarnings("rawtypes") final Tuple obj) {
53:                 return this.getFirst().equals(obj.getFirst()) && this.getSecond().equals(obj.getSecond());
54:         }
55:         
56:         @Override
57:         public String toString() {
58:                 return "(" + this.getFirst() + "," + this.getSecond() + ")";
59:         }
60:         
61:         @Override
62:         public int hashCode() {
63:                 return this.getFirst().hashCode() ^ this.getSecond().hashCode();
64:         }
65:         
66: }