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
24 * @author Francois Chouinard
26 public class TmfLocation
<L
extends Comparable
<L
>> implements ITmfLocation
<L
> {
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 * Default constructor (for the 'null' location)
41 @SuppressWarnings("unused")
42 private TmfLocation() {
47 * Standard constructor.
49 * @param location the trace location
51 public TmfLocation(final L location
) {
58 * @param location the original location
60 public TmfLocation(final TmfLocation
<L
> location
) {
61 fLocation
= location
.fLocation
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
72 public L
getLocation() {
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 (fLocation
!= null) {
90 final Class
<?
> clazz
= fLocation
.getClass();
91 final Method method
= clazz
.getMethod("clone", new Class
[0]); //$NON-NLS-1$
92 final Object copy
= method
.invoke(this.fLocation
, new Object
[0]);
93 clone
.fLocation
= (L
) copy
;
95 clone
.fLocation
= null;
96 } catch (final CloneNotSupportedException e
) {
97 } catch (final NoSuchMethodException e
) {
98 } catch (final Exception e
) {
99 throw new InternalError(e
.toString());
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
109 * @see java.lang.Object#hashCode()
112 public int hashCode() {
113 final int prime
= 31;
115 result
= prime
* result
+ ((fLocation
!= null) ? fLocation
.hashCode() : 0);
120 * @see java.lang.Object#equals(java.lang.Object)
123 @SuppressWarnings("unchecked")
124 public boolean equals(final Object obj
) {
129 if (getClass() != obj
.getClass())
131 final TmfLocation
<L
> other
= (TmfLocation
<L
>) obj
;
132 if (fLocation
== null) {
133 if (other
.fLocation
!= null)
135 } else if (!fLocation
.equals(other
.fLocation
))
141 @SuppressWarnings("nls")
142 public String
toString() {
143 return "TmfLocation [fLocation=" + fLocation
+ "]";