Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 2 | |
Sho SHIMIZU | 69aa0f3 | 2014-06-09 15:05:22 -0700 | [diff] [blame^] | 3 | import java.util.Objects; |
| 4 | |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 5 | /** |
| 6 | * A generic class representing a pair of two values. |
| 7 | */ |
Pavlin Radoslavov | 4535bc1 | 2013-12-05 10:43:49 -0800 | [diff] [blame] | 8 | public class Pair<F, S> { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 9 | public F first; // The first value in the pair |
| 10 | public S second; // The second value in the pair |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * Constructor for a pair of two values. |
| 14 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | * @param first the first value in the pair. |
Pavlin Radoslavov | 4535bc1 | 2013-12-05 10:43:49 -0800 | [diff] [blame] | 16 | * @param second the second value in the pair. |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 17 | */ |
Pavlin Radoslavov | 4535bc1 | 2013-12-05 10:43:49 -0800 | [diff] [blame] | 18 | public Pair(F first, S second) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | this.first = first; |
| 20 | this.second = second; |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 21 | } |
Toshio Koide | d7476d0 | 2014-02-22 15:59:04 -0800 | [diff] [blame] | 22 | |
| 23 | @Override |
| 24 | public String toString() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | return String.format("<%s, %s>", first, second); |
Toshio Koide | d7476d0 | 2014-02-22 15:59:04 -0800 | [diff] [blame] | 26 | } |
Sho SHIMIZU | 69aa0f3 | 2014-06-09 15:05:22 -0700 | [diff] [blame^] | 27 | |
| 28 | @Override |
| 29 | public boolean equals(Object o) { |
| 30 | if (o == this) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | if (!(o instanceof Pair)) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | Pair<?, ?> that = (Pair<?, ?>) o; |
| 39 | return Objects.equals(this.first, that.first) |
| 40 | && Objects.equals(this.second, that.second); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public int hashCode() { |
| 45 | return Objects.hash(this.first, this.second); |
| 46 | } |
Pavlin Radoslavov | 9f9d549 | 2013-12-04 18:21:48 -0800 | [diff] [blame] | 47 | } |