mirror of
https://github.com/apache/commons-math.git
synced 2025-02-12 13:06:06 +00:00
MATH-810
Added new accessors. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1357004 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
075a88a074
commit
f2187efaf0
@ -39,8 +39,8 @@ public class Pair<K, V> {
|
||||
* Create an entry representing a mapping from the specified key to the
|
||||
* specified value.
|
||||
*
|
||||
* @param k Key.
|
||||
* @param v Value.
|
||||
* @param k Key (first element of the pair).
|
||||
* @param v Value (second element of the pair).
|
||||
*/
|
||||
public Pair(K k, V v) {
|
||||
key = k;
|
||||
@ -59,7 +59,7 @@ public class Pair<K, V> {
|
||||
/**
|
||||
* Get the key.
|
||||
*
|
||||
* @return the key.
|
||||
* @return the key (first element of the pair).
|
||||
*/
|
||||
public K getKey() {
|
||||
return key;
|
||||
@ -68,12 +68,30 @@ public class Pair<K, V> {
|
||||
/**
|
||||
* Get the value.
|
||||
*
|
||||
* @return the value.
|
||||
* @return the value (second element of the pair).
|
||||
*/
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first element of the pair.
|
||||
*
|
||||
* @return the first element of the pair.
|
||||
*/
|
||||
public K getFirst() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the second element of the pair.
|
||||
*
|
||||
* @return the second element of the pair.
|
||||
*/
|
||||
public V getSecond() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the specified object with this entry for equality.
|
||||
*
|
||||
|
@ -29,6 +29,17 @@ public class PairTest {
|
||||
Assert.assertEquals(new Double(2), p.getValue(), Math.ulp(1d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessor2() {
|
||||
final Pair<Integer, Double> p
|
||||
= new Pair<Integer, Double>(new Integer(1), new Double(2));
|
||||
|
||||
// Check that both APIs refer to the same data.
|
||||
|
||||
Assert.assertTrue(p.getFirst() == p.getKey());
|
||||
Assert.assertTrue(p.getSecond() == p.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Pair<Integer, Double> p1 = new Pair<Integer, Double>(null, null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user