From fcccd90096c4a9d4b5ca41f02cd71390cf1a93d3 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Thu, 12 Apr 2012 18:02:03 -0400 Subject: [PATCH] Refactor ITmfLocation and fix dependencies --- .../lttng/core/event/LttngLocation.java | 2 +- .../tmf/core/tests/trace/TmfContextTest.java | 3 +- .../tmf/core/tests/trace/TmfLocationTest.java | 468 ++++++++++-------- .../tmf/core/ctfadaptor/CtfLocation.java | 2 +- .../tmf/core/trace/ITmfLocation.java | 27 +- .../tmf/core/trace/TmfLocation.java | 189 ++++--- 6 files changed, 399 insertions(+), 292 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java index 02580a9f34..c1865ac44f 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/event/LttngLocation.java @@ -168,7 +168,7 @@ public class LttngLocation implements ITmfLocation, Comparable fLocation1 = new TmfLocation(aString); final TmfLocation fLocation2 = new TmfLocation(aLong); - final TmfLocation fLocation3 = new TmfLocation(aTimestamp); + final TmfLocation fLocation3 = new TmfLocation(aTimestamp); final long fRank1 = 1; final long fRank2 = 2; diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java index 4b1aac4f1b..0f4ce3b21f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfLocationTest.java @@ -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 fLocation1; - TmfLocation fLocation2; - TmfLocation fLocation3; + TmfLocation fLocation0; + TmfLocation fLocation1; + TmfLocation fLocation2; + TmfLocation fLocation3; + TmfLocation fLocation4; // ------------------------------------------------------------------------ // Housekeeping // ------------------------------------------------------------------------ - /** - * @param name the test name - */ - public TmfLocationTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - fLocation1 = new TmfLocation(aString); - fLocation2 = new TmfLocation(aLong); - fLocation3 = new TmfLocation(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) null); + fLocation2 = new TmfLocation(aString); + fLocation3 = new TmfLocation(aLong); + fLocation4 = new TmfLocation(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 location1 = new TmfLocation(fLocation1); - TmfLocation location2 = new TmfLocation(fLocation2); - TmfLocation location3 = new TmfLocation(fLocation3); - - assertEquals("TmfLocation", aString, location1.getLocation()); - assertEquals("TmfLocation", aLong, location2.getLocation()); - assertEquals("TmfLocation", aTimestamp, location3.getLocation()); - } - - public void testTmfLocationCopy2() throws Exception { - try { - new TmfLocation((TmfLocation) 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 location0 = new TmfLocation(fLocation0); + TmfLocation location1 = new TmfLocation(fLocation1); + TmfLocation location2 = new TmfLocation(fLocation2); + TmfLocation location3 = new TmfLocation(fLocation3); + TmfLocation location4 = new TmfLocation(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 location1 = fLocation1.clone(); + TmfLocation location2 = fLocation2.clone(); + TmfLocation location3 = fLocation3.clone(); + TmfLocation 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 { + 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 location = new TmfLocation(myClass); + TmfLocation 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 { + 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 myLocation = new TmfLocation(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 location1 = new TmfLocation((String) null); + TmfLocation location2 = new TmfLocation(aString); + TmfLocation location3 = new TmfLocation(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 location1 = new TmfLocation(aString); - TmfLocation location2 = new TmfLocation(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 location1 = new TmfLocation(aString); - TmfLocation location2 = new TmfLocation(aString); - TmfLocation location3 = new TmfLocation(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 location1 = new TmfLocation(aString); - TmfLocation location2 = new TmfLocation(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 { + public TmfLocation2(String location) { + super(location); + } + } + + public void testEqualsWrongTypes() throws Exception { + TmfLocation location1 = new TmfLocation(aString); + TmfLocation2 location2 = new TmfLocation2(aString); + + assertFalse("equals", location1.equals(location2)); + assertFalse("equals", location2.equals(location1)); + } + + public void testEqualsWithNulls() throws Exception { + TmfLocation location1 = new TmfLocation(aString); + TmfLocation location2 = new TmfLocation((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 location2 = new TmfLocation(aString); + TmfLocation location3 = new TmfLocation(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 location1 = new TmfLocation(aString); + TmfLocation location2 = new TmfLocation(aString); + TmfLocation location3 = new TmfLocation(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 location1 = new TmfLocation(aString); - TmfLocation location2 = new TmfLocation(aLong); - TmfLocation location3 = new TmfLocation(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 location1 = new TmfLocation(aString); + TmfLocation location2 = new TmfLocation(aLong); + TmfLocation location3 = new TmfLocation(aTimestamp); - // ------------------------------------------------------------------------ - // clone - // ------------------------------------------------------------------------ + String expected1 = "TmfLocation [fLocation=" + aString + "]"; + String expected2 = "TmfLocation [fLocation=" + aLong + "]"; + String expected3 = "TmfLocation [fLocation=" + aTimestamp + "]"; - public void testClone() { - try { - TmfLocation location1 = fLocation1.clone(); - TmfLocation location2 = fLocation2.clone(); - TmfLocation 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 { - 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 myLocation = new TmfLocation(myClass); - TmfLocation location4 = myLocation.clone(); - - assertEquals("TmfLocation", myClass.toString(), location4.toString()); - } - catch (InternalError e) { - fail("clone()"); - } - } - - public static class MyUnCloneableClass implements Comparable { - 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 myLocation = new TmfLocation(myClass); - myLocation.clone(); - fail("clone()"); - } - catch (InternalError e) { - // Success - } - } + assertEquals("toString", expected1, location1.toString()); + assertEquals("toString", expected2, location2.toString()); + assertEquals("toString", expected3, location3.toString()); + } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java index 5cab5cb62f..a44610d35f 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java @@ -15,7 +15,7 @@ public class CtfLocation implements ITmfLocation { private Long fTimestamp; - @Override +// @Override public void setLocation(Long location) { this.fTimestamp = location; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java index 09ef798871..813a31edec 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfLocation.java @@ -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; /** * ITmfLocation *

- * 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. + *

+ * This location is trace-specific but must be comparable. */ public interface ITmfLocation> extends Cloneable { - public void setLocation(L location); + // ------------------------------------------------------------------------ + // Getters + // ------------------------------------------------------------------------ + + /** + * @return the location + */ + public L getLocation(); - public L getLocation(); + // ------------------------------------------------------------------------ + // Cloneable + // ------------------------------------------------------------------------ - public ITmfLocation clone(); + /** + * @return a clone of the location + */ + public ITmfLocation clone(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java index 55c5a8a8d2..a9e2947d5a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfLocation.java @@ -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; /** * TmfLocation *

- * A generic implementation of ITmfLocation + * A convenience implementation on of ITmfLocation. The generic class (L) must + * be comparable. */ -@SuppressWarnings("rawtypes") -public class TmfLocation implements ITmfLocation { - - private L fLocation; - - @SuppressWarnings("unused") - private TmfLocation() { - } - - public TmfLocation(L location) { - fLocation = location; - } - - public TmfLocation(TmfLocation 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> implements ITmfLocation { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + static public final TmfLocation NULL_LOCATION = new TmfLocation(); + + // ------------------------------------------------------------------------ + // 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 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 clone() { + TmfLocation clone = null; + try { + clone = (TmfLocation) 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 other = (TmfLocation) 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 clone() { - TmfLocation clone = null; - try { - clone = (TmfLocation) 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 + "]"; + } } -- 2.34.1