View Javadoc
1   package com.github.davidmoten.rx2.util;
2   
3   public class Pair<T, S> {
4   
5       private final T a;
6       private final S b;
7   
8       public Pair(T a, S b) {
9           this.a = a;
10          this.b = b;
11      }
12  
13      public static <T, S> Pair<T, S> create(T t, S s) {
14          return new Pair<T, S>(t, s);
15      }
16  
17      public T a() {
18          return a;
19      }
20  
21      public S b() {
22          return b;
23      }
24  
25      public T left() {
26          return a;
27      }
28  
29      public S right() {
30          return b;
31      }
32  
33      @Override
34      public int hashCode() {
35          final int prime = 31;
36          int result = 1;
37          result = prime * result + ((a == null) ? 0 : a.hashCode());
38          result = prime * result + ((b == null) ? 0 : b.hashCode());
39          return result;
40      }
41  
42      @Override
43      public boolean equals(Object obj) {
44          if (this == obj)
45              return true;
46          if (obj == null)
47              return false;
48          if (getClass() != obj.getClass())
49              return false;
50          Pair<?, ?> other = (Pair<?, ?>) obj;
51          if (a == null) {
52              if (other.a != null)
53                  return false;
54          } else if (!a.equals(other.a))
55              return false;
56          if (b == null) {
57              if (other.b != null)
58                  return false;
59          } else if (!b.equals(other.b))
60              return false;
61          return true;
62      }
63  
64      @Override
65      public String toString() {
66          StringBuilder builder = new StringBuilder();
67          builder.append("Pair [left=");
68          builder.append(a);
69          builder.append(", right=");
70          builder.append(b);
71          builder.append("]");
72          return builder.toString();
73      }
74  
75      public T _1() {
76          return a;
77      }
78  
79      public S _2() {
80          return b;
81      }
82  }