1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
16 import java
.lang
.reflect
.Method
;
19 * A convenience implementation on of ITmfLocation. The generic class (L) must
22 * @param <L> The trace lcoation type
25 * @author Francois Chouinard
27 public class TmfLocation
<L
extends Comparable
<L
>> implements ITmfLocation
<L
>, Cloneable
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private L fLocationData
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
40 * Default constructor (for the 'null' location)
42 @SuppressWarnings("unused")
43 private TmfLocation() {
47 * Standard constructor.
49 * @param locationData the trace location
51 public TmfLocation(final L locationData
) {
52 fLocationData
= locationData
;
58 * @param location the original location
60 public TmfLocation(final TmfLocation
<L
> location
) {
61 fLocationData
= location
.fLocationData
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
72 public L
getLocationData() {
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * @see java.lang.Object#clone()
84 @SuppressWarnings("unchecked")
85 public TmfLocation
<L
> clone() {
86 TmfLocation
<L
> clone
= null;
88 clone
= (TmfLocation
<L
>) super.clone();
89 if (fLocationData
!= null) {
90 final Class
<?
> clazz
= fLocationData
.getClass();
91 final Method method
= clazz
.getMethod("clone", new Class
[0]); //$NON-NLS-1$
92 final Object copy
= method
.invoke(this.fLocationData
, new Object
[0]);
93 clone
.fLocationData
= (L
) copy
;
95 clone
.fLocationData
= null;
97 } catch (final CloneNotSupportedException e
) {
98 } catch (final NoSuchMethodException e
) {
99 } catch (final Exception e
) {
100 throw new InternalError(e
.toString());
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 * @see java.lang.Object#hashCode()
113 public int hashCode() {
114 final int prime
= 31;
116 result
= prime
* result
+ ((fLocationData
!= null) ? fLocationData
.hashCode() : 0);
121 * @see java.lang.Object#equals(java.lang.Object)
124 @SuppressWarnings("unchecked")
125 public boolean equals(final Object obj
) {
132 if (getClass() != obj
.getClass()) {
135 final TmfLocation
<L
> other
= (TmfLocation
<L
>) obj
;
136 if (fLocationData
== null) {
137 if (other
.fLocationData
!= null) {
140 } else if (!fLocationData
.equals(other
.fLocationData
)) {
147 @SuppressWarnings("nls")
148 public String
toString() {
149 return "TmfLocation [fLocation=" + fLocationData
+ "]";