/*******************************************************************************
* 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
*/
@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;
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/* (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;
}
// ------------------------------------------------------------------------
* @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
// ------------------------------------------------------------------------
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;
}
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
- @SuppressWarnings("unchecked")
public boolean equals(final Object obj) {
if (this == obj) {
return true;
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;
@Override
@SuppressWarnings("nls")
public String toString() {
- return "TmfLocation [fLocation=" + fLocation + "]";
+ return "TmfLocation [fLocation=" + fLocationInfo + "]";
}
}