View Javadoc
1   package com.github.davidmoten.rx.jdbc.tuple;
2   
3   /**
4    * An explicitly typed tuple.
5    * 
6    * @param <T1>
7    * @param <T2>
8    */
9   public class Tuple2<T1, T2> {
10  
11      private final T1 value1;
12      private final T2 value2;
13  
14      /**
15       * Constructor.
16       * 
17       * @param value1
18       * @param value2
19       */
20      public Tuple2(T1 value1, T2 value2) {
21          this.value1 = value1;
22          this.value2 = value2;
23      }
24  
25      /**
26       * Returns a new instance.
27       * 
28       * @param r
29       * @param s
30       * @return
31       */
32      public static <R, S> Tuple2<R, S> create(R r, S s) {
33          return new Tuple2<R, S>(r, s);
34      }
35  
36      /**
37       * Returns the first memmber of the tuple.
38       * 
39       * @return
40       */
41      public T1 value1() {
42          return value1;
43      }
44  
45      /**
46       * Returns the 2nd member of the tuple.
47       * 
48       * @return
49       */
50      public T2 value2() {
51          return value2;
52      }
53  
54      @Override
55      public int hashCode() {
56          final int prime = 31;
57          int result = 1;
58          result = prime * result + ((value1 == null) ? 0 : value1.hashCode());
59          result = prime * result + ((value2 == null) ? 0 : value2.hashCode());
60          return result;
61      }
62  
63      @Override
64      public boolean equals(Object obj) {
65          if (this == obj)
66              return true;
67          if (obj == null)
68              return false;
69          if (getClass() != obj.getClass())
70              return false;
71          Tuple2<?, ?> other = (Tuple2<?, ?>) obj;
72          if (value1 == null) {
73              if (other.value1 != null)
74                  return false;
75          } else if (!value1.equals(other.value1))
76              return false;
77          if (value2 == null) {
78              if (other.value2 != null)
79                  return false;
80          } else if (!value2.equals(other.value2))
81              return false;
82          return true;
83      }
84  
85      @Override
86      public String toString() {
87          return "Tuple2 [value1=" + value1 + ", value2=" + value2 + "]";
88      }
89  
90  }