Refactor ITmfLocation and fix dependencies
authorFrancois Chouinard <fchouinard@gmail.com>
Thu, 12 Apr 2012 22:02:03 +0000 (18:02 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Thu, 12 Apr 2012 22:02:03 +0000 (18:02 -0400)
org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfContextTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java

index 02580a9f345a28c60ab4477a193e78fa05d96185..c1865ac44f285b8d0b9550cf26b3fe40615f90db 100644 (file)
@@ -168,7 +168,7 @@ public class LttngLocation implements ITmfLocation<LttngTimestamp>, Comparable<L
        // ITmfLocation
        // ------------------------------------------------------------------------
 
-       @Override
+//     @Override
        public void setLocation(LttngTimestamp location) {
                operationTime  = (LttngTimestamp)location;
        }
index 3f6e2620ba4f2f533d9babdc2d016a371d880288..54812aa796ec6598bd4790ef8123b52dee4ac7a3 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.tests.trace;
 
 import junit.framework.TestCase;
 
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
@@ -36,7 +37,7 @@ public class TmfContextTest extends TestCase {
 
        final TmfLocation<String> fLocation1 = new TmfLocation<String>(aString);
        final TmfLocation<Long>   fLocation2 = new TmfLocation<Long>(aLong);
-       final TmfLocation<TmfTimestamp> fLocation3 = new TmfLocation<TmfTimestamp>(aTimestamp);
+       final TmfLocation<ITmfTimestamp> fLocation3 = new TmfLocation<ITmfTimestamp>(aTimestamp);
 
        final long fRank1 = 1;
        final long fRank2 = 2;
index 4b1aac4f1bb3da02242be83dd5f2ba313372abca..0f4ce3b21fe8309200a2c6c340c0bb7fe525e1e1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.tests.trace;
 
 import junit.framework.TestCase;
 
+import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
 
@@ -25,247 +26,286 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
 @SuppressWarnings("nls")
 public class TmfLocationTest extends TestCase {
 
-       // ------------------------------------------------------------------------
-       // Variables
-       // ------------------------------------------------------------------------
+    // ------------------------------------------------------------------------
+    // Variables
+    // ------------------------------------------------------------------------
 
-       String       aString    = "some location";
-       Long         aLong      = 12345L;
-       TmfTimestamp aTimestamp = new TmfTimestamp();
+    String aString = "some location";
+    Long aLong = 12345L;
+    TmfTimestamp aTimestamp = new TmfTimestamp();
 
-       TmfLocation<String>       fLocation1;
-       TmfLocation<Long>         fLocation2;
-       TmfLocation<TmfTimestamp> fLocation3;
+    TmfLocation<Boolean> fLocation0;
+    TmfLocation<String> fLocation1;
+    TmfLocation<String> fLocation2;
+    TmfLocation<Long> fLocation3;
+    TmfLocation<ITmfTimestamp> fLocation4;
 
     // ------------------------------------------------------------------------
     // Housekeeping
     // ------------------------------------------------------------------------
 
-       /**
-        * @param name the test name
-        */
-       public TmfLocationTest(String name) {
-               super(name);
-       }
-
-       @Override
-       protected void setUp() throws Exception {
-               super.setUp();
-               fLocation1 = new TmfLocation<String>(aString);
-               fLocation2 = new TmfLocation<Long>(aLong);
-               fLocation3 = new TmfLocation<TmfTimestamp>(aTimestamp);
-       }
-
-       @Override
-       protected void tearDown() throws Exception {
-               super.tearDown();
-       }
+    /**
+     * @param name
+     *            the test name
+     */
+    public TmfLocationTest(String name) {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        fLocation0 = TmfLocation.NULL_LOCATION;
+        fLocation1 = new TmfLocation<String>((String) null);
+        fLocation2 = new TmfLocation<String>(aString);
+        fLocation3 = new TmfLocation<Long>(aLong);
+        fLocation4 = new TmfLocation<ITmfTimestamp>(aTimestamp);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
-       public void testTmfLocation() {
-               assertEquals("TmfLocation", aString,    fLocation1.getLocation());
-               assertEquals("TmfLocation", aLong,      fLocation2.getLocation());
-               assertEquals("TmfLocation", aTimestamp, fLocation3.getLocation());
-       }
-
-       public void testTmfLocationCopy() {
-               TmfLocation<String> location1 = new TmfLocation<String>(fLocation1);
-               TmfLocation<Long>   location2 = new TmfLocation<Long>(fLocation2);
-               TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(fLocation3);
-
-               assertEquals("TmfLocation", aString,    location1.getLocation());
-               assertEquals("TmfLocation", aLong,      location2.getLocation());
-               assertEquals("TmfLocation", aTimestamp, location3.getLocation());
-       }
-
-       public void testTmfLocationCopy2() throws Exception {
-               try {
-                       new TmfLocation<Long>((TmfLocation<Long>) null);
-                       fail("null copy");
-               }
-               catch (IllegalArgumentException e) {
-                       // Success
-               }
-       }
+    public void testTmfLocation() {
+        assertNull("TmfLocation", fLocation0.getLocation());
+        assertNull("TmfLocation", fLocation1.getLocation());
+        assertEquals("TmfLocation", aString, fLocation2.getLocation());
+        assertEquals("TmfLocation", aLong, fLocation3.getLocation());
+        assertEquals("TmfLocation", aTimestamp, fLocation4.getLocation());
+    }
+
+    public void testTmfLocationCopy() {
+        TmfLocation<Boolean> location0 = new TmfLocation<Boolean>(fLocation0);
+        TmfLocation<String> location1 = new TmfLocation<String>(fLocation1);
+        TmfLocation<String> location2 = new TmfLocation<String>(fLocation2);
+        TmfLocation<Long> location3 = new TmfLocation<Long>(fLocation3);
+        TmfLocation<ITmfTimestamp> location4 = new TmfLocation<ITmfTimestamp>(fLocation4);
+
+        assertNull("TmfLocation", location0.getLocation());
+        assertNull("TmfLocation", location1.getLocation());
+        assertEquals("TmfLocation", aString, location2.getLocation());
+        assertEquals("TmfLocation", aLong, location3.getLocation());
+        assertEquals("TmfLocation", aTimestamp, location4.getLocation());
+    }
+
+    // ------------------------------------------------------------------------
+    // clone
+    // ------------------------------------------------------------------------
+
+    public void testClone() {
+        try {
+            TmfLocation<String> location1 = fLocation1.clone();
+            TmfLocation<String> location2 = fLocation2.clone();
+            TmfLocation<Long> location3 = fLocation3.clone();
+            TmfLocation<ITmfTimestamp> location4 = fLocation4.clone();
+
+            assertEquals("clone", fLocation1, location1);
+            assertEquals("clone", fLocation2, location2);
+            assertEquals("clone", fLocation3, location3);
+            assertEquals("clone", fLocation4, location4);
+
+            assertEquals("clone", fLocation1.getLocation(), location1.getLocation());
+            assertEquals("clone", fLocation2.getLocation(), location2.getLocation());
+            assertEquals("clone", fLocation3.getLocation(), location3.getLocation());
+            assertEquals("clone", fLocation4.getLocation(), location4.getLocation());
+
+            assertNull("clone", location1.getLocation());
+            assertEquals("clone", aString, location2.getLocation());
+            assertEquals("clone", aLong, location3.getLocation());
+            assertEquals("clone", aTimestamp, location4.getLocation());
+        } catch (InternalError e) {
+            fail("clone()");
+        }
+    }
+
+    public static class MyCloneableClass implements Cloneable, Comparable<MyCloneableClass> {
+        private String fName;
+
+        public MyCloneableClass(String name) {
+            fName = name;
+        }
+
+        @Override
+        public String toString() {
+            return fName;
+        }
+
+        @Override
+        public MyCloneableClass clone() {
+            MyCloneableClass clone = null;
+            try {
+                clone = (MyCloneableClass) super.clone();
+                clone.fName = fName;
+            } catch (CloneNotSupportedException e) {
+            }
+            return clone;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            return fName.compareTo(((MyCloneableClass) o).fName) == 0;
+        }
+
+        @Override
+        public int compareTo(MyCloneableClass o) {
+            return fName.compareTo(o.fName);
+        }
+    }
+
+    public void testCloneCloneable() {
+        try {
+            MyCloneableClass myClass = new MyCloneableClass("myCloneableClass");
+            TmfLocation<MyCloneableClass> location = new TmfLocation<MyCloneableClass>(myClass);
+            TmfLocation<MyCloneableClass> clone = location.clone();
+
+            assertEquals("clone", location, clone);
+            assertEquals("clone", location.getLocation(), clone.getLocation());
+            assertEquals("clone", myClass, location.getLocation());
+        } catch (InternalError e) {
+            fail("clone a cloneable class");
+        }
+    }
+
+    public static class MyUnCloneableClass implements Comparable<MyUnCloneableClass> {
+        private String fName;
+
+        public MyUnCloneableClass(String name) {
+            fName = name;
+        }
+
+        @Override
+        public String toString() {
+            return fName;
+        }
+
+        @Override
+        public Object clone() throws CloneNotSupportedException {
+            throw new CloneNotSupportedException();
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            return fName.compareTo(((MyUnCloneableClass) o).fName) == 0;
+        }
+
+        @Override
+        public int compareTo(MyUnCloneableClass o) {
+            return fName.compareTo(o.fName);
+        }
+    }
+
+    public void testCloneUncloneable() {
+        try {
+            MyUnCloneableClass myClass = new MyUnCloneableClass("myUncloneableClass");
+            TmfLocation<MyUnCloneableClass> myLocation = new TmfLocation<MyUnCloneableClass>(myClass);
+            myLocation.clone();
+            fail("clone an uncloneable class");
+        } catch (InternalError e) {
+        }
+    }
 
     // ------------------------------------------------------------------------
-    // setLocation
+    // hashCode
     // ------------------------------------------------------------------------
 
-       public void testSetLocation() {
-               String       aString2    = "some other location";
-               Long         aLong2      = 1234567L;
-               TmfTimestamp aTimestamp2 = (TmfTimestamp) TmfTimestamp.BIG_BANG;
+    public void testHashCode() throws Exception {
+        TmfLocation<String> location1 = new TmfLocation<String>((String) null);
+        TmfLocation<String> location2 = new TmfLocation<String>(aString);
+        TmfLocation<Long> location3 = new TmfLocation<Long>(aLong);
 
-               fLocation1.setLocation(aString2);
-               fLocation2.setLocation(aLong2);
-               fLocation3.setLocation(aTimestamp2);
-               
-               assertEquals("TmfLocation", aString2,    fLocation1.getLocation());
-               assertEquals("TmfLocation", aLong2,      fLocation2.getLocation());
-               assertEquals("TmfLocation", aTimestamp2, fLocation3.getLocation());
-       }
+        assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
+        assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
+        assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode());
+
+        assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode());
+        assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode());
+    }
 
     // ------------------------------------------------------------------------
     // toEquals
     // ------------------------------------------------------------------------
 
-       public void testEqualsReflexivity() throws Exception {
-               assertTrue("equals", fLocation1.equals(fLocation1));
-               assertTrue("equals", fLocation2.equals(fLocation2));
-
-               assertTrue("equals", !fLocation1.equals(fLocation2));
-               assertTrue("equals", !fLocation2.equals(fLocation1));
-       }
-       
-       public void testEqualsSymmetry() throws Exception {
-               TmfLocation<String> location1 = new TmfLocation<String>(aString);
-               TmfLocation<Long>   location2 = new TmfLocation<Long>(aLong);
-
-               assertTrue("equals", location1.equals(fLocation1));
-               assertTrue("equals", fLocation1.equals(location1));
-
-               assertTrue("equals", location2.equals(fLocation2));
-               assertTrue("equals", fLocation2.equals(location2));
-       }
-       
-       public void testEqualsTransivity() throws Exception {
-               TmfLocation<String> location1 = new TmfLocation<String>(aString);
-               TmfLocation<String> location2 = new TmfLocation<String>(aString);
-               TmfLocation<String> location3 = new TmfLocation<String>(aString);
-
-               assertTrue("equals", location1.equals(location2));
-               assertTrue("equals", location2.equals(location3));
-               assertTrue("equals", location1.equals(location3));
-       }
-       
-       public void testEqualsNull() throws Exception {
-               assertTrue("equals", !fLocation1.equals(null));
-               assertTrue("equals", !fLocation1.equals(null));
-       }
-       
-       // ------------------------------------------------------------------------
-       // hashCode
-       // ------------------------------------------------------------------------
-
-       public void testHashCode() throws Exception {
-               TmfLocation<String> location1 = new TmfLocation<String>(aString);
-               TmfLocation<Long>   location2 = new TmfLocation<Long>(aLong);
-
-               assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode());
-               assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode());
-
-               assertTrue("hashCode", fLocation1.hashCode() != location2.hashCode());
-               assertTrue("hashCode", fLocation2.hashCode() != location1.hashCode());
-       }
-       
+    private static class TmfLocation2 extends TmfLocation<String> {
+        public TmfLocation2(String location) {
+            super(location);
+        }
+    }
+
+    public void testEqualsWrongTypes() throws Exception {
+        TmfLocation<String> location1 = new TmfLocation<String>(aString);
+        TmfLocation2 location2 = new TmfLocation2(aString);
+        
+        assertFalse("equals", location1.equals(location2));
+        assertFalse("equals", location2.equals(location1));
+    }
+
+    public void testEqualsWithNulls() throws Exception {
+        TmfLocation<String> location1 = new TmfLocation<String>(aString);
+        TmfLocation<String> location2 = new TmfLocation<String>((String) null);
+        
+        assertFalse("equals", location1.equals(location2));
+        assertFalse("equals", location2.equals(location1));
+    }
+
+    public void testEqualsReflexivity() throws Exception {
+        assertTrue("equals", fLocation2.equals(fLocation2));
+        assertTrue("equals", fLocation3.equals(fLocation3));
+
+        assertTrue("equals", !fLocation2.equals(fLocation3));
+        assertTrue("equals", !fLocation3.equals(fLocation2));
+    }
+
+    public void testEqualsSymmetry() throws Exception {
+        TmfLocation<String> location2 = new TmfLocation<String>(aString);
+        TmfLocation<Long> location3 = new TmfLocation<Long>(aLong);
+
+        assertTrue("equals", location2.equals(fLocation2));
+        assertTrue("equals", fLocation2.equals(location2));
+
+        assertTrue("equals", location3.equals(fLocation3));
+        assertTrue("equals", fLocation3.equals(location3));
+    }
+
+    public void testEqualsTransivity() throws Exception {
+        TmfLocation<String> location1 = new TmfLocation<String>(aString);
+        TmfLocation<String> location2 = new TmfLocation<String>(aString);
+        TmfLocation<String> location3 = new TmfLocation<String>(aString);
+
+        assertTrue("equals", location1.equals(location2));
+        assertTrue("equals", location2.equals(location3));
+        assertTrue("equals", location3.equals(location1));
+    }
+
+    public void testEqualsNull() throws Exception {
+        assertTrue("equals", !fLocation2.equals(null));
+        assertTrue("equals", !fLocation2.equals(null));
+    }
+
     // ------------------------------------------------------------------------
     // toString
     // ------------------------------------------------------------------------
 
-       public void testToString() {
-               String       aString     = "some location";
-               Long         aLong       = 12345L;
-               TmfTimestamp aTimestamp  = new TmfTimestamp();
-
-               TmfLocation<String>       location1 = new TmfLocation<String>(aString);
-               TmfLocation<Long>         location2 = new TmfLocation<Long>(aLong);
-               TmfLocation<TmfTimestamp> location3 = new TmfLocation<TmfTimestamp>(aTimestamp);
+    public void testToString() {
+        String aString = "some location";
+        Long aLong = 12345L;
+        TmfTimestamp aTimestamp = new TmfTimestamp();
 
-               assertEquals("TmfLocation", aString.toString(),    location1.toString());
-               assertEquals("TmfLocation", aLong.toString(),      location2.toString());
-               assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
-       }
+        TmfLocation<String> location1 = new TmfLocation<String>(aString);
+        TmfLocation<Long> location2 = new TmfLocation<Long>(aLong);
+        TmfLocation<ITmfTimestamp> location3 = new TmfLocation<ITmfTimestamp>(aTimestamp);
 
-    // ------------------------------------------------------------------------
-    // clone
-    // ------------------------------------------------------------------------
+        String expected1 = "TmfLocation [fLocation=" + aString + "]";
+        String expected2 = "TmfLocation [fLocation=" + aLong + "]";
+        String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]";
 
-       public void testClone() {
-               try {
-                       TmfLocation<String> location1 = fLocation1.clone();
-                       TmfLocation<Long>   location2 = fLocation2.clone();
-                       TmfLocation<TmfTimestamp> location3 = fLocation3.clone();
-
-                       assertEquals("TmfLocation", aString.toString(), location1.toString());
-                       assertEquals("TmfLocation", aLong.toString(), location2.toString());
-                       assertEquals("TmfLocation", aTimestamp.toString(), location3.toString());
-               }
-               catch (InternalError e) {
-                       fail("clone()");
-               }
-       }
-
-       public static class MyCloneableClass implements Cloneable, Comparable<MyCloneableClass> {
-               private String fName;
-               public MyCloneableClass(String name) {
-                       fName = name;
-               }
-               @Override
-               public String toString() {
-                       return fName;
-               }
-               @Override
-               public MyCloneableClass clone() {
-                       MyCloneableClass clone = null;
-                       try {
-                               clone = (MyCloneableClass) super.clone();
-                               clone.fName = fName;
-                       } catch (CloneNotSupportedException e) {
-                       }
-                       return clone;
-               }
-               @Override
-               public int compareTo(MyCloneableClass o) {
-                       return 0;
-               }
-       }
-
-       public void testCloneCloneable() {
-               try {
-                       MyCloneableClass myClass = new MyCloneableClass("myClass");
-                       TmfLocation<MyCloneableClass> myLocation = new TmfLocation<MyCloneableClass>(myClass);
-                       TmfLocation<MyCloneableClass> location4 = myLocation.clone();
-
-                       assertEquals("TmfLocation", myClass.toString(), location4.toString());
-               }
-               catch (InternalError e) {
-                       fail("clone()");
-               }
-       }
-
-       public static class MyUnCloneableClass implements Comparable<MyUnCloneableClass> {
-               private String fName;
-               public MyUnCloneableClass(String name) {
-                       fName = name;
-               }
-               @Override
-               public String toString() {
-                       return fName;
-               }
-               @Override
-               public Object clone() throws CloneNotSupportedException {
-                       throw new CloneNotSupportedException();
-               }
-               @Override
-               public int compareTo(MyUnCloneableClass o) {
-                       return 0;
-               }
-       }
-
-       public void testCloneUnCloneable() {
-               try {
-                       MyUnCloneableClass myClass = new MyUnCloneableClass("myClass");
-                       TmfLocation<MyUnCloneableClass> myLocation = new TmfLocation<MyUnCloneableClass>(myClass);
-                       myLocation.clone();
-                       fail("clone()");
-               }
-               catch (InternalError e) {
-                       // Success
-               }
-       }
+        assertEquals("toString", expected1, location1.toString());
+        assertEquals("toString", expected2, location2.toString());
+        assertEquals("toString", expected3, location3.toString());
+    }
 
 }
index 5cab5cb62fa973210e8635bc5665cfe8fb753ee6..a44610d35f1201f649749e4dcd3dc87fd053fee3 100644 (file)
@@ -15,7 +15,7 @@ public class CtfLocation implements ITmfLocation<Long> {
 
     private Long fTimestamp;
 
-    @Override
+//    @Override
     public void setLocation(Long location) {
         this.fTimestamp = location;
     }
index 09ef7988717662e3bceed3ba1e579c088326e9e2..813a31edecc1b3ff754033c5b996cd9b6b3ede05 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -8,6 +8,7 @@
  * 
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
@@ -15,14 +16,30 @@ package org.eclipse.linuxtools.tmf.core.trace;
 /**
  * <b><u>ITmfLocation</u></b>
  * <p>
- * This is a place-holder for the location objects.
+ * An ITmfLocation is the equivalent of a random-access file position, holding
+ * enough information to allow the positioning of the trace 'pointer' to read an
+ * arbitrary event.
+ * <p>
+ * This location is trace-specific but must be comparable.
  */
 public interface ITmfLocation<L extends Comparable<?>> extends Cloneable {
 
-       public void setLocation(L location);
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the location
+     */
+    public L getLocation();
 
-       public L getLocation();
+    // ------------------------------------------------------------------------
+    // Cloneable
+    // ------------------------------------------------------------------------
 
-       public ITmfLocation<L> clone();
+    /**
+     * @return a clone of the location
+     */
+    public ITmfLocation<L> clone();
 
 }
index 55c5a8a8d2235a28dad68126c9d212230b59b1f8..a9e2947d5a4a060483dd9b5aa8ad0aabe73c3179 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * 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
@@ -8,6 +8,7 @@
  * 
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Francois Chouinard - Updated as per TMF Trace Model 1.0
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.trace;
@@ -17,84 +18,132 @@ import java.lang.reflect.Method;
 /**
  * <b><u>TmfLocation</u></b>
  * <p>
- * A generic implementation of ITmfLocation
+ * A convenience implementation on of ITmfLocation. The generic class (L) must
+ * be comparable.
  */
-@SuppressWarnings("rawtypes")
-public class TmfLocation<L extends Comparable> implements ITmfLocation<L> {
-
-       private L fLocation;
-       
-       @SuppressWarnings("unused")
-       private TmfLocation() {
-       }
-
-       public TmfLocation(L location) {
-               fLocation = location;
-       }
-
-       public TmfLocation(TmfLocation<L> other) {
-       if (other == null)
-               throw new IllegalArgumentException();
-       fLocation = other.fLocation;
-       }
-
-       @Override
-       public void setLocation(L location) {
-               fLocation = location;
-       }
-
-       @Override
-       public L getLocation() {
-               return fLocation;
-       }
-
-       // ------------------------------------------------------------------------
+public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L> {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+
+    static public final TmfLocation<Boolean> NULL_LOCATION = new TmfLocation<Boolean>();
+    
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private L fLocation;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor (for the 'null' location)
+     */
+    private TmfLocation() {
+        fLocation = null;
+    }
+
+    /**
+     * Standard constructor.
+     * 
+     * @param location the trace location
+     */
+    public TmfLocation(L location) {
+        fLocation = location;
+    }
+
+    /**
+     * Copy constructor
+     * 
+     * @param other the original location
+     */
+    public TmfLocation(TmfLocation<L> location) {
+        fLocation = location.fLocation;
+    }
+
+    // ------------------------------------------------------------------------
+    // Getters
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
+     */
+    @Override
+    public L getLocation() {
+        return fLocation;
+    }
+
+    // ------------------------------------------------------------------------
+    // Cloneable
+    // ------------------------------------------------------------------------
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public TmfLocation<L> clone() {
+        TmfLocation<L> clone = null;
+        try {
+            clone = (TmfLocation<L>) super.clone();
+            if (fLocation != null) {
+                Class<?> clazz = fLocation.getClass();
+                Method method = clazz.getMethod("clone", new Class[0]);
+                Object copy = method.invoke(this.fLocation, new Object[0]);
+                clone.fLocation = (L) copy;
+            } else {
+                clone.fLocation = null;
+            }
+        } catch (CloneNotSupportedException e) {
+        } catch (NoSuchMethodException e) {
+        } catch (Exception e) {
+            throw new InternalError(e.toString());
+        }
+        return clone;
+    }
+
+    // ------------------------------------------------------------------------
     // Object
     // ------------------------------------------------------------------------
 
-       @Override
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
     public int hashCode() {
-           if (fLocation == null)
-               return -1;
-               return fLocation.hashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0);
+        return result;
     }
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
     @Override
-    public boolean equals(Object other) {
-        if (!(other instanceof TmfLocation<?>))
-               return false;
-        TmfLocation<?> o = (TmfLocation<?>) other;
-        if (fLocation == null)
-            return (o.fLocation == null);
-        return fLocation.equals(o.fLocation);
+    @SuppressWarnings("unchecked")
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        TmfLocation<L> other = (TmfLocation<L>) obj;
+        if (fLocation == null) {
+            if (other.fLocation != null)
+                return false;
+        } else if (!fLocation.equals(other.fLocation))
+            return false;
+        return true;
     }
 
-       @Override
-       @SuppressWarnings("nls")
-       public String toString() {
-           if (fLocation == null)
-               return "null";
-               return fLocation.toString();
-       }
-
-       @Override
-       @SuppressWarnings({ "nls", "unchecked" })
-       public TmfLocation<L> clone() {
-               TmfLocation<L> clone = null;
-               try {
-                       clone = (TmfLocation<L>) super.clone();
-                       if (this.fLocation != null) {
-                           Class<?> clazz  = this.fLocation.getClass(); 
-                           Method   method = clazz.getMethod("clone", new Class[0]);
-                           Object   duplic = method.invoke(this.fLocation, new Object[0]);
-                           clone.fLocation = (L) duplic;
-                       }
-               } catch (NoSuchMethodException e) { 
-                     // exception suppressed 
-               } catch (Exception e) {
-                       throw new InternalError(e.toString());
-               }
-               return clone;
-       }
+    @Override
+    public String toString() {
+        return "TmfLocation [fLocation=" + fLocation + "]";
+    }
 
 }
This page took 0.037961 seconds and 5 git commands to generate.