analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / util / Pair.java
index 368df79823dff70b62c91b41e9288630e315ad7b..c805ece46e26e00b0648cb2cd68e71c427df6fc0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  *   Philippe Sawicki (INF4990.A2010@gmail.com)   - Initial API and implementation
  *   Mathieu Denis    (mathieu.denis55@gmail.com) - Refactored code
  *   Bernd Hufmann - Integrated to TMF, fixed hashCode() and equals() methods
+ *   Alexandre Montplaisir - Made non-null and immutable
  *******************************************************************************/
 package org.eclipse.tracecompass.tmf.core.util;
 
+import org.eclipse.jdt.annotation.Nullable;
+
 /**
  * Pair utility class, encapsulates a pair of objects.
  *
@@ -22,18 +25,17 @@ package org.eclipse.tracecompass.tmf.core.util;
  *            The type of the second object.
  *
  * @author Philippe Sawicki
- * @since 2.0
  */
 public class Pair<A, B> {
 
     /**
      * A reference to the first object.
      */
-    protected A fFirst;
+    private final A fFirst;
     /**
      * A reference to the second object.
      */
-    protected B fSecond;
+    private final B fSecond;
 
     /**
      * Constructor.
@@ -47,30 +49,36 @@ public class Pair<A, B> {
         fSecond = second;
     }
 
+
     /**
-     * Constructor.
+     * Returns a reference to the pair's first object.
+     *
+     * @return A reference to the pair's first object.
      */
-    public Pair() {
-        this(null, null);
+    public A getFirst() {
+        return fFirst;
     }
 
     /**
-     * Pair hash code.
+     * Returns a reference to the pair's second object.
+     *
+     * @return A reference to the pair's second object.
      */
+    public B getSecond() {
+        return fSecond;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((fFirst == null) ? 0 : fFirst.hashCode());
-        result = prime * result + ((fSecond == null) ? 0 : fSecond.hashCode());
+        result = prime * result + fFirst.hashCode();
+        result = prime * result + fSecond.hashCode();
         return result;
     }
 
-    /**
-     * Object comparison.
-     */
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(@Nullable Object obj) {
         if (this == obj) {
             return true;
         }
@@ -85,62 +93,18 @@ public class Pair<A, B> {
 
         Pair<?, ?> other = (Pair<?, ?>) obj;
 
-        if (fFirst == null) {
-            if (other.fFirst != null) {
-                return false;
-            }
-        } else if (!fFirst.equals(other.fFirst)) {
+        if (!fFirst.equals(other.fFirst)) {
             return false;
         }
-        if (fSecond == null) {
-            if (other.fSecond != null) {
-                return false;
-            }
-        } else if (!fSecond.equals(other.fSecond)) {
+        if (!fSecond.equals(other.fSecond)) {
             return false;
         }
         return true;
     }
 
-    /**
-     * Object to string.
-     */
     @Override
     public String toString() {
         return "(" + fFirst + ", " + fSecond + ")";  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
     }
 
-    /**
-     * Returns a reference to the pair's first object.
-     * @return A reference to the pair's first object.
-     */
-    public A getFirst() {
-        return fFirst;
-    }
-
-    /**
-     * Sets the pair's first object.
-     * @param first
-     *            The pair's first object.
-     */
-    public void setFirst(A first) {
-        fFirst = first;
-    }
-
-    /**
-     * Returns a reference to the pair's second object.
-     * @return A reference to the pair's second object.
-     */
-    public B getSecond() {
-        return fSecond;
-    }
-
-    /**
-     * Sets the pair's second object.
-     * @param second
-     *            The pair's second object.
-     */
-    public void setSecond(B second) {
-        fSecond = second;
-    }
 }
\ No newline at end of file
This page took 0.025845 seconds and 5 git commands to generate.