blob: 6fe81013844215acdeef8006071d1973e4e6e0ec [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov9f9d5492013-12-04 18:21:48 -08002
Sho SHIMIZU69aa0f32014-06-09 15:05:22 -07003import java.util.Objects;
4
Pavlin Radoslavov9f9d5492013-12-04 18:21:48 -08005/**
6 * A generic class representing a pair of two values.
7 */
Pavlin Radoslavov4535bc12013-12-05 10:43:49 -08008public class Pair<F, S> {
Ray Milkey269ffb92014-04-03 14:43:30 -07009 public F first; // The first value in the pair
10 public S second; // The second value in the pair
Pavlin Radoslavov9f9d5492013-12-04 18:21:48 -080011
12 /**
13 * Constructor for a pair of two values.
14 *
Ray Milkey269ffb92014-04-03 14:43:30 -070015 * @param first the first value in the pair.
Pavlin Radoslavov4535bc12013-12-05 10:43:49 -080016 * @param second the second value in the pair.
Pavlin Radoslavov9f9d5492013-12-04 18:21:48 -080017 */
Pavlin Radoslavov4535bc12013-12-05 10:43:49 -080018 public Pair(F first, S second) {
Ray Milkey269ffb92014-04-03 14:43:30 -070019 this.first = first;
20 this.second = second;
Pavlin Radoslavov9f9d5492013-12-04 18:21:48 -080021 }
Toshio Koided7476d02014-02-22 15:59:04 -080022
23 @Override
24 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 return String.format("<%s, %s>", first, second);
Toshio Koided7476d02014-02-22 15:59:04 -080026 }
Sho SHIMIZU69aa0f32014-06-09 15:05:22 -070027
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 Radoslavov9f9d5492013-12-04 18:21:48 -080047}