tmf: Fix the actual end time of state system modules
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / util / Pair.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11 * Mathieu Denis (mathieu.denis55@gmail.com) - Refactored code
12 * Bernd Hufmann - Integrated to TMF, fixed hashCode() and equals() methods
13 * Alexandre Montplaisir - Made non-null and immutable
14 *******************************************************************************/
15 package org.eclipse.tracecompass.tmf.core.util;
16
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.eclipse.tracecompass.common.core.NonNullUtils;
19
20 /**
21 * Pair utility class, encapsulates a pair of objects.
22 *
23 * @param <A>
24 * The type of the first object.
25 * @param <B>
26 * The type of the second object.
27 *
28 * @author Philippe Sawicki
29 */
30 public class Pair<A, B> {
31
32 /**
33 * A reference to the first object.
34 */
35 private final A fFirst;
36 /**
37 * A reference to the second object.
38 */
39 private final B fSecond;
40
41 /**
42 * Constructor.
43 * @param first
44 * The pair's first object.
45 * @param second
46 * The pair's second object.
47 */
48 public Pair(A first, B second) {
49 fFirst = first;
50 fSecond = second;
51 }
52
53
54 /**
55 * Returns a reference to the pair's first object.
56 *
57 * @return A reference to the pair's first object.
58 */
59 public A getFirst() {
60 return fFirst;
61 }
62
63 /**
64 * Returns a reference to the pair's second object.
65 *
66 * @return A reference to the pair's second object.
67 */
68 public B getSecond() {
69 return fSecond;
70 }
71
72
73 @Override
74 public int hashCode() {
75 final int prime = 31;
76 int result = 1;
77 result = prime * result + hashFromNullable(fFirst);
78 result = prime * result + hashFromNullable(fSecond);
79 return result;
80 }
81
82 private static int hashFromNullable(@Nullable Object o) {
83 return o == null ? 0 : o.hashCode();
84 }
85
86 @Override
87 public boolean equals(@Nullable Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (obj == null) {
92 return false;
93 }
94 if (getClass() != obj.getClass()) {
95 return false;
96 }
97 Pair<?, ?> other = (Pair<?, ?>) obj;
98 if (!NonNullUtils.equalsNullable(other.fFirst, fFirst)) {
99 return false;
100 }
101 if (!NonNullUtils.equalsNullable(other.fSecond, fSecond)) {
102 return false;
103 }
104 return true;
105 }
106
107 @Override
108 public String toString() {
109 return "(" + fFirst + ", " + fSecond + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
110 }
111 }
This page took 0.03412 seconds and 5 git commands to generate.