tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / internal / lttng / core / util / Pair.java
1 /*******************************************************************************
2 * Copyright (c) 2011 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 *******************************************************************************/
13 package org.eclipse.linuxtools.internal.lttng.core.util;
14
15 /**
16 * Pair utility class, encapsulates a pair of objects.
17 *
18 * @author Philippe Sawicki
19 *
20 * @param <A>
21 * The type of the first object.
22 * @param <B>
23 * The type of the second object.
24 */
25 public abstract class Pair<A, B> {
26
27 /**
28 * A reference to the first object.
29 */
30 protected A fFirst;
31 /**
32 * A reference to the second object.
33 */
34 protected B fSecond;
35
36 /**
37 * Constructor.
38 * @param first
39 * The pair's first object.
40 * @param second
41 * The pair's second object.
42 */
43 public Pair(A first, B second) {
44 fFirst = first;
45 fSecond = second;
46 }
47
48 /**
49 * Constructor.
50 */
51 public Pair() {
52 this(null, null);
53 }
54
55 /**
56 * Pair hash code.
57 */
58 @Override
59 public int hashCode() {
60 int hashFirst = fFirst != null ? fFirst.hashCode() : 0;
61 int hashSecond = fSecond != null ? fSecond.hashCode() : 0;
62
63 return (hashFirst + hashSecond) * hashSecond + hashFirst;
64 }
65
66 /**
67 * Object comparison.
68 */
69 @Override
70 @SuppressWarnings("unchecked")
71 public boolean equals(Object other) {
72 if (other instanceof Pair) {
73 Pair<A, B> otherPair = (Pair<A, B>) other;
74 return ((fFirst == otherPair.fFirst || (fFirst != null && otherPair.fFirst != null && fFirst.equals(otherPair.fFirst))) && (fSecond == otherPair.fSecond || (fSecond != null
75 && otherPair.fSecond != null && fSecond.equals(otherPair.fSecond))));
76 }
77 return false;
78 }
79
80 /**
81 * Object to string.
82 */
83 @Override
84 public String toString() {
85 return "(" + fFirst + ", " + fSecond + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
86 }
87
88 /**
89 * Returns a reference to the pair's first object.
90 * @return A reference to the pair's first object.
91 */
92 public A getFirst() {
93 return fFirst;
94 }
95
96 /**
97 * Sets the pair's first object.
98 * @param first
99 * The pair's first object.
100 */
101 public void setFirst(A first) {
102 fFirst = first;
103 }
104
105 /**
106 * Returns a reference to the pair's second object.
107 * @return A reference to the pair's second object.
108 */
109 public B getSecond() {
110 return fSecond;
111 }
112
113 /**
114 * Sets the pair's second object.
115 * @param second
116 * The pair's second object.
117 */
118 public void setSecond(B second) {
119 fSecond = second;
120 }
121 }
This page took 0.034083 seconds and 5 git commands to generate.