Repository navigation
Expand file tree
/
Copy pathPair.java
More file actions
132 lines (120 loc) · 2.88 KB
/
Copy pathPair.java
File metadata and controls
132 lines (120 loc) · 2.88 KB
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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.tron.common.utils;
import java.io.Serializable;
/**
* <p>A convenience class to represent name-value pairs.</p>
*
* @since JavaFX 2.0
*/
public class Pair<K, V> implements Serializable {
private static final long serialVersionUID = -76702881811738599L;
/**
* Key of this <code>Pair</code>.
*/
private K key;
/**
* Value of this this <code>Pair</code>.
*/
private V value;
/**
* Creates a new pair
*
* @param key The key for this pair
* @param value The value to use for this pair
*/
public Pair(@NamedArg("key") K key, @NamedArg("value") V value) {
this.key = key;
this.value = value;
}
/**
* Gets the key for this pair.
*
* @return key for this pair
*/
public K getKey() {
return key;
}
/**
* Gets the value for this pair.
*
* @return value for this pair
*/
public V getValue() {
return value;
}
/**
* <p><code>String</code> representation of this <code>Pair</code>.</p>
*
* <p>The default name/value delimiter '=' is always used.</p>
*
* @return <code>String</code> representation of this <code>Pair</code>
*/
@Override
public String toString() {
return key + "=" + value;
}
/**
* <p>Generate a hash code for this <code>Pair</code>.</p>
*
* <p>The hash code is calculated using both the name and the value of the <code>Pair</code>.</p>
*
* @return hash code for this <code>Pair</code>
*/
@Override
public int hashCode() {
// name's hashCode is multiplied by an arbitrary prime number (13)
// in order to make sure there is a difference in the hashCode between
// these two parameters:
// name: a value: aa
// name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
}
/**
* <p>Test this <code>Pair</code> for equality with another <code>Object</code>.</p>
*
* <p>If the <code>Object</code> to be tested is not a <code>Pair</code> or is <code>null</code>,
* then this method returns <code>false</code>.</p>
*
* <p>Two <code>Pair</code>s are considered equal if and only if both the names and values are
* equal.</p>
*
* @param o the <code>Object</code> to test for equality with this <code>Pair</code>
* @return <code>true</code> if the given <code>Object</code> is equal to this <code>Pair</code>
* else <code>false</code>
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof Pair) {
Pair pair = (Pair) o;
return !((key != null ? !key.equals(pair.key) : pair.key != null) || (value != null ? !value
.equals(pair.value) : pair.value != null));
}
return false;
}
}