Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfLocation.java
index 8a438dc62283e6b6f9eea6f00a0c4bc2e22dc060..a5fb1b54eff3ae35a6f88d5ac42ad8b060a73dd6 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Francois Chouinard - Updated as per TMF Trace Model 1.0
 
 package org.eclipse.linuxtools.tmf.core.trace;
 
-import java.lang.reflect.Method;
 
 /**
- * A convenience implementation on of ITmfLocation. The generic class (L) must
- * be comparable.
- * 
- * @version 1.0
+ * A abstract implementation of ITmfLocation. The concrete classes must provide
+ * comparable location information.
+ *
+ * @version 2.0
  * @author Francois Chouinard
  */
-public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cloneable {
+public abstract class TmfLocation implements ITmfLocation, Cloneable {
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
 
-    private L fLocation;
+    private Comparable<?> fLocationInfo;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -39,24 +38,25 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
      */
     @SuppressWarnings("unused")
     private TmfLocation() {
+        fLocationInfo = null;
     }
 
     /**
      * Standard constructor.
-     * 
-     * @param location the trace location
+     *
+     * @param locationInfo the concrete trace location
      */
-    public TmfLocation(final L location) {
-        fLocation = location;
+    public TmfLocation(final Comparable<?> locationInfo) {
+        fLocationInfo = locationInfo;
     }
 
     /**
      * Copy constructor
-     * 
-     * @param location the original location
+     *
+     * @param location the original trace location
      */
-    public TmfLocation(final TmfLocation<L> location) {
-        fLocation = location.fLocation;
+    public TmfLocation(final TmfLocation location) {
+        fLocationInfo = location.fLocationInfo;
     }
 
     // ------------------------------------------------------------------------
@@ -64,11 +64,14 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
     // ------------------------------------------------------------------------
 
     /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocationInfo()
+     */
+    /**
+     * @since 2.0
      */
     @Override
-    public L getLocation() {
-        return fLocation;
+    public Comparable<?> getLocationInfo() {
+        return fLocationInfo;
     }
 
     // ------------------------------------------------------------------------
@@ -79,27 +82,24 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
      * @see java.lang.Object#clone()
      */
     @Override
-    @SuppressWarnings("unchecked")
-    public TmfLocation<L> clone() {
-        TmfLocation<L> clone = null;
+    public TmfLocation clone() {
+        TmfLocation clone = null;
         try {
-            clone = (TmfLocation<L>) super.clone();
-            if (fLocation != null) {
-                final Class<?> clazz = fLocation.getClass();
-                final Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$
-                final Object copy = method.invoke(this.fLocation, new Object[0]);
-                clone.fLocation = (L) copy;
-            } else {
-                clone.fLocation = null;
-            }
-        } catch (final CloneNotSupportedException e) {
-        } catch (final NoSuchMethodException e) {
-        } catch (final Exception e) {
-            throw new InternalError(e.toString());
+            clone = (TmfLocation) super.clone();
+            clone.fLocationInfo = cloneLocationInfo();
+        } catch (CloneNotSupportedException e) {
         }
         return clone;
     }
 
+    /**
+     * Delegate to the locationInfo cloning to the subclasses
+     *
+     * @return the locationInfo clone
+     * @since 2.0
+     */
+    protected abstract Comparable<?> cloneLocationInfo();
+
     // ------------------------------------------------------------------------
     // Object
     // ------------------------------------------------------------------------
@@ -111,7 +111,7 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0);
+        result = prime * result + ((fLocationInfo != null) ? fLocationInfo.hashCode() : 0);
         return result;
     }
 
@@ -119,7 +119,6 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
-    @SuppressWarnings("unchecked")
     public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
@@ -130,12 +129,12 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
         if (getClass() != obj.getClass()) {
             return false;
         }
-        final TmfLocation<L> other = (TmfLocation<L>) obj;
-        if (fLocation == null) {
-            if (other.fLocation != null) {
+        final TmfLocation other = (TmfLocation) obj;
+        if (fLocationInfo == null) {
+            if (other.fLocationInfo != null) {
                 return false;
             }
-        } else if (!fLocation.equals(other.fLocation)) {
+        } else if (!fLocationInfo.equals(other.fLocationInfo)) {
             return false;
         }
         return true;
@@ -144,7 +143,7 @@ public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cl
     @Override
     @SuppressWarnings("nls")
     public String toString() {
-        return "TmfLocation [fLocation=" + fLocation + "]";
+        return "TmfLocation [fLocation=" + fLocationInfo + "]";
     }
 
 }
This page took 0.028128 seconds and 5 git commands to generate.