9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.util;
27
28 import java.io.Serializable;
29 import javafx.beans.NamedArg;
30
31 /**
32 * <p>A convenience class to represent name-value pairs.</p>
33 * @since JavaFX 2.0
34 */
35 public class Pair<K,V> implements Serializable{
36
37 /**
38 * Key of this <code>Pair</code>.
39 */
40 private K key;
41
42 /**
43 * Gets the key for this pair.
44 * @return key for this pair
45 */
46 public K getKey() { return key; }
47
48 /**
72 *
73 * <p>The default name/value delimiter '=' is always used.</p>
74 *
75 * @return <code>String</code> representation of this <code>Pair</code>
76 */
77 @Override
78 public String toString() {
79 return key + "=" + value;
80 }
81
82 /**
83 * <p>Generate a hash code for this <code>Pair</code>.</p>
84 *
85 * <p>The hash code is calculated using both the name and
86 * the value of the <code>Pair</code>.</p>
87 *
88 * @return hash code for this <code>Pair</code>
89 */
90 @Override
91 public int hashCode() {
92 // name's hashCode is multiplied by an arbitrary prime number (13)
93 // in order to make sure there is a difference in the hashCode between
94 // these two parameters:
95 // name: a value: aa
96 // name: aa value: a
97 return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
98 }
99
100 /**
101 * <p>Test this <code>Pair</code> for equality with another
102 * <code>Object</code>.</p>
103 *
104 * <p>If the <code>Object</code> to be tested is not a
105 * <code>Pair</code> or is <code>null</code>, then this method
106 * returns <code>false</code>.</p>
107 *
108 * <p>Two <code>Pair</code>s are considered equal if and only if
109 * both the names and values are equal.</p>
110 *
111 * @param o the <code>Object</code> to test for
112 * equality with this <code>Pair</code>
113 * @return <code>true</code> if the given <code>Object</code> is
114 * equal to this <code>Pair</code> else <code>false</code>
115 */
116 @Override
117 public boolean equals(Object o) {
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.util;
27
28 import java.io.Serializable;
29 import java.util.Objects;
30 import javafx.beans.NamedArg;
31
32 /**
33 * <p>A convenience class to represent name-value pairs.</p>
34 * @since JavaFX 2.0
35 */
36 public class Pair<K,V> implements Serializable{
37
38 /**
39 * Key of this <code>Pair</code>.
40 */
41 private K key;
42
43 /**
44 * Gets the key for this pair.
45 * @return key for this pair
46 */
47 public K getKey() { return key; }
48
49 /**
73 *
74 * <p>The default name/value delimiter '=' is always used.</p>
75 *
76 * @return <code>String</code> representation of this <code>Pair</code>
77 */
78 @Override
79 public String toString() {
80 return key + "=" + value;
81 }
82
83 /**
84 * <p>Generate a hash code for this <code>Pair</code>.</p>
85 *
86 * <p>The hash code is calculated using both the name and
87 * the value of the <code>Pair</code>.</p>
88 *
89 * @return hash code for this <code>Pair</code>
90 */
91 @Override
92 public int hashCode() {
93 return Objects.hash(key, value);
94 }
95
96 /**
97 * <p>Test this <code>Pair</code> for equality with another
98 * <code>Object</code>.</p>
99 *
100 * <p>If the <code>Object</code> to be tested is not a
101 * <code>Pair</code> or is <code>null</code>, then this method
102 * returns <code>false</code>.</p>
103 *
104 * <p>Two <code>Pair</code>s are considered equal if and only if
105 * both the names and values are equal.</p>
106 *
107 * @param o the <code>Object</code> to test for
108 * equality with this <code>Pair</code>
109 * @return <code>true</code> if the given <code>Object</code> is
110 * equal to this <code>Pair</code> else <code>false</code>
111 */
112 @Override
113 public boolean equals(Object o) {
|