23
23
public class HgPair <K , V > implements Serializable {
24
24
25
25
/**
26
- * Key of this <code>Pair</code>.
26
+ * This is the key associated with this <code>Pair</code>.
27
27
*/
28
28
private K key ;
29
+
29
30
/**
30
- * Value of this <code>Pair</code>.
31
+ * This is the value associated with this <code>Pair</code>.
31
32
*/
32
33
private V value ;
33
34
@@ -36,20 +37,20 @@ public HgPair() {
36
37
}
37
38
38
39
/**
39
- * Creates a new pair
40
+ * Initializes a new pair with the specified key and value.
40
41
*
41
- * @param key The key for this pair
42
- * @param value The value to use for this pair
42
+ * @param key The key to be associated with this pair
43
+ * @param value The value to be associated with this pair
43
44
*/
44
45
public HgPair (K key , V value ) {
45
46
this .key = key ;
46
47
this .value = value ;
47
48
}
48
49
49
50
/**
50
- * Gets the key for this pair.
51
+ * Retrieves the key associated with this pair.
51
52
*
52
- * @return key for this pair
53
+ * @return the key of this pair
53
54
*/
54
55
public K getKey () {
55
56
return key ;
@@ -60,9 +61,9 @@ public void setKey(K key) {
60
61
}
61
62
62
63
/**
63
- * Gets the value for this pair.
64
+ * Retrieves the value associated with this pair.
64
65
*
65
- * @return value for this pair
66
+ * @return the value of this pair
66
67
*/
67
68
public V getValue () {
68
69
return value ;
@@ -73,63 +74,54 @@ public void setValue(V value) {
73
74
}
74
75
75
76
/**
76
- * <p><code>String</code> representation of this
77
- * <code>Pair</code>.</p>
77
+ * Provides a <code>String</code> representation of this <code>Pair</code>.
78
78
*
79
- * <p>The default name/ value delimiter '=' is always used .</p>
79
+ * <p>The default delimiter between name and value is '='.</p>
80
80
*
81
- * @return <code>String</code> representation of this <code>Pair</code>
81
+ * @return a <code>String</code> representation of this <code>Pair</code>
82
82
*/
83
83
@ Override
84
84
public String toString () {
85
85
return key + "=" + value ;
86
86
}
87
87
88
88
/**
89
- * <p>Generate a hash code for this <code>Pair</code>.</p>
89
+ * Generates a hash code for this <code>Pair</code>.
90
90
*
91
- * <p>The hash code is calculated using both the name and
91
+ * <p>The hash code is computed using both the key and
92
92
* the value of the <code>Pair</code>.</p>
93
93
*
94
- * @return hash code for this <code>Pair</code>
94
+ * @return the hash code for this <code>Pair</code>
95
95
*/
96
96
@ Override
97
97
public int hashCode () {
98
- // name's hashCode is multiplied by an arbitrary prime number (13)
99
- // in order to make sure there is a difference in the hashCode between
100
- // these two parameters:
101
- // name: a value: aa
102
- // name: aa value: a
98
+ // The hashCode of the key is multiplied by a prime number (13)
99
+ // to ensure uniqueness between different key-value combinations:
100
+ // key: a value: aa
101
+ // key: aa value: a
103
102
return key .hashCode () * 13 + (value == null ? 0 : value .hashCode ());
104
103
}
105
104
106
105
/**
107
- * <p>Test this <code>Pair</code> for equality with another
108
- * <code>Object</code>.</p>
106
+ * Checks if this <code>Pair</code> is equal to another <code>Object</code>.
109
107
*
110
- * <p>If the <code>Object</code> to be tested is not a
111
- * <code>Pair</code> or is <code>null</code>, then this method
112
- * returns <code>false</code>.</p>
108
+ * <p>This method returns <code>false</code> if the tested
109
+ * <code>Object</code> is not a <code>Pair</code> or is <code>null</code>.</p>
113
110
*
114
- * <p>Two <code>Pair</code>s are considered equal if and only if
115
- * both the names and values are equal.</p>
111
+ * <p>Two <code>Pair</code>s are equal if their keys and values are both equal.</p>
116
112
*
117
- * @param o the <code>Object</code> to test for
118
- * equality with this <code>Pair</code>
119
- * @return <code>true</code> if the given <code>Object</code> is
120
- * equal to this <code>Pair</code> else <code>false</code>
113
+ * @param o the <code>Object</code> to compare with this <code>Pair</code>
114
+ * @return <code>true</code> if the specified <code>Object</code> is
115
+ * equal to this <code>Pair</code>, otherwise <code>false</code>
121
116
*/
122
117
@ Override
123
118
public boolean equals (Object o ) {
124
119
if (this == o ) {
125
120
return true ;
126
121
}
127
122
if (o instanceof HgPair ) {
128
- HgPair pair = (HgPair ) o ;
129
- if (!Objects .equals (key , pair .key )) {
130
- return false ;
131
- }
132
- return Objects .equals (value , pair .value );
123
+ HgPair <?, ?> pair = (HgPair <?, ?>) o ;
124
+ return Objects .equals (key , pair .key ) && Objects .equals (value , pair .value );
133
125
}
134
126
return false ;
135
127
}
0 commit comments