4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
Pair.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Bc. Radim Loskot xlosko01@stud.fit.vutbr.cz
4  * File: Pair.java
5  * Description: Contains Java equivalent of C++ Pair or C# Tupple.
6  */
7 /**
8  * @file Pair.java
9  *
10  * @brief Contains Java equivalent of C++ Pair or C# Tupple.
11  */
12 
13 package cz.vutbr.fit.knot.annotations.document;
14 
15 /**
16  * Java equivalent of C++ Pair or C# Tupple.
17  *
18  * @brief Java equivalent of C++ Pair or C# Tupple.
19  *
20  * @author Bc. Radim Loskot (xlosko01 at stud.fit.vutbr.cz)
21  */
22 public class Pair<L, R> {
23 
24  public L left;
25  public R right;
26 
27  /**
28  * Constructor
29  */
30  public Pair() {}
31 
32  /**
33  * Constructor
34  *
35  * @param left left pair
36  * @param right right pair
37  */
38  public Pair(L left, R right) {
39  this.left = left;
40  this.right = right;
41  } // Pair()
42 
43  /**
44  * Equals if object is the same class instance and has same left and right values.
45  *
46  * @param obj Object to compare
47  * @return
48  */
49  @Override
50  public boolean equals(Object obj) {
51  if (obj == null) {
52  return false;
53  }
54 
55  if (!(obj instanceof Pair)) {
56  return false;
57  }
58 
59  Pair pairObj = (Pair) obj;
60  return left.equals(pairObj.left) && right.equals(pairObj.right);
61  } // equals()
62 
63  /**
64  * Returns hash code of this object.
65  *
66  * @return Hash code
67  */
68  @Override
69  public int hashCode() {
70  return left.hashCode() ^ right.hashCode();
71  } // hashCode()
72 };