Cambridge SMT System
Pair.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  * Copyright 2014 - Juan Pino, Aurelien Waite, William Byrne
15  *******************************************************************************/
20 package uk.ac.cam.eng.util;
21 
29 public class Pair<T, U> {
30 
31  private T first;
32  private U second;
33 
34  public Pair() {
35  }
36 
41  public Pair(T first, U second) {
42  this.first = first;
43  this.second = second;
44  }
45 
46  public static <F, S> Pair<F, S> createPair(F first, S second) {
47  return new Pair<F, S>(first, second);
48  }
49 
53  public T getFirst() {
54  return first;
55  }
56 
60  public void setFirst(T first) {
61  this.first = first;
62  }
63 
67  public U getSecond() {
68  return second;
69  }
70 
74  public void setSecond(U second) {
75  this.second = second;
76  }
77 
78  @Override
79  public String toString() {
80  return first + "\t" + second;
81  }
82 
83  @Override
84  public int hashCode() {
85  final int prime = 31;
86  int result = 1;
87  result = prime * result + ((first == null) ? 0 : first.hashCode());
88  result = prime * result + ((second == null) ? 0 : second.hashCode());
89  return result;
90  }
91 
92  @Override
93  public boolean equals(Object obj) {
94  if (this == obj) {
95  return true;
96  }
97  if (obj == null) {
98  return false;
99  }
100  if (getClass() != obj.getClass()) {
101  return false;
102  }
103  @SuppressWarnings("unchecked")
104  Pair<T, U> other = (Pair<T, U>) obj;
105  if (first == null) {
106  if (other.first != null) {
107  return false;
108  }
109  } else if (!first.equals(other.first)) {
110  return false;
111  }
112  if (second == null) {
113  if (other.second != null) {
114  return false;
115  }
116  } else if (!second.equals(other.second)) {
117  return false;
118  }
119  return true;
120  }
121 }
static< F, S > Pair< F, S > createPair(F first, S second)
Definition: Pair.java:46
double F
void setSecond(U second)
Definition: Pair.java:74
Pair(T first, U second)
Definition: Pair.java:41
boolean equals(Object obj)
Definition: Pair.java:93
void setFirst(T first)
Definition: Pair.java:60