tmf: Rename TmfLocation.fLocation to .fLocationData
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfLocation.java
CommitLineData
8c8bf09f 1/*******************************************************************************
fcccd900 2 * Copyright (c) 2009, 2010, 2012 Ericsson
0283f7ff 3 *
8c8bf09f
ASL
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
0283f7ff 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
fcccd900 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
8c8bf09f
ASL
12 *******************************************************************************/
13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
ff4ed569
FC
16import java.lang.reflect.Method;
17
8c8bf09f 18/**
fcccd900
FC
19 * A convenience implementation on of ITmfLocation. The generic class (L) must
20 * be comparable.
0283f7ff
FC
21 *
22 * @param <L> The trace lcoation type
23 *
f7703ed6
FC
24 * @version 1.0
25 * @author Francois Chouinard
8c8bf09f 26 */
0316808c 27public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L>, Cloneable {
fcccd900 28
fcccd900
FC
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
6bab4511 33 private L fLocationData;
fcccd900
FC
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
39 /**
40 * Default constructor (for the 'null' location)
41 */
2848c377 42 @SuppressWarnings("unused")
fcccd900 43 private TmfLocation() {
fcccd900
FC
44 }
45
46 /**
47 * Standard constructor.
0283f7ff 48 *
6bab4511 49 * @param locationData the trace location
fcccd900 50 */
6bab4511
AM
51 public TmfLocation(final L locationData) {
52 fLocationData = locationData;
fcccd900
FC
53 }
54
55 /**
56 * Copy constructor
0283f7ff 57 *
2848c377 58 * @param location the original location
fcccd900 59 */
5d837f9b 60 public TmfLocation(final TmfLocation<L> location) {
6bab4511 61 fLocationData = location.fLocationData;
fcccd900
FC
62 }
63
64 // ------------------------------------------------------------------------
65 // Getters
66 // ------------------------------------------------------------------------
67
6bab4511
AM
68 /**
69 * @since 2.0
fcccd900
FC
70 */
71 @Override
6bab4511
AM
72 public L getLocationData() {
73 return fLocationData;
fcccd900
FC
74 }
75
76 // ------------------------------------------------------------------------
77 // Cloneable
78 // ------------------------------------------------------------------------
79
80 /* (non-Javadoc)
81 * @see java.lang.Object#clone()
82 */
83 @Override
84 @SuppressWarnings("unchecked")
85 public TmfLocation<L> clone() {
86 TmfLocation<L> clone = null;
87 try {
88 clone = (TmfLocation<L>) super.clone();
6bab4511
AM
89 if (fLocationData != null) {
90 final Class<?> clazz = fLocationData.getClass();
5d837f9b 91 final Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$
6bab4511
AM
92 final Object copy = method.invoke(this.fLocationData, new Object[0]);
93 clone.fLocationData = (L) copy;
0316808c 94 } else {
6bab4511 95 clone.fLocationData = null;
0316808c 96 }
5d837f9b
FC
97 } catch (final CloneNotSupportedException e) {
98 } catch (final NoSuchMethodException e) {
99 } catch (final Exception e) {
fcccd900
FC
100 throw new InternalError(e.toString());
101 }
102 return clone;
103 }
104
105 // ------------------------------------------------------------------------
ff4ed569
FC
106 // Object
107 // ------------------------------------------------------------------------
108
fcccd900
FC
109 /* (non-Javadoc)
110 * @see java.lang.Object#hashCode()
111 */
112 @Override
ff4ed569 113 public int hashCode() {
fcccd900
FC
114 final int prime = 31;
115 int result = 1;
6bab4511 116 result = prime * result + ((fLocationData != null) ? fLocationData.hashCode() : 0);
fcccd900 117 return result;
ff4ed569
FC
118 }
119
fcccd900
FC
120 /* (non-Javadoc)
121 * @see java.lang.Object#equals(java.lang.Object)
122 */
ff4ed569 123 @Override
fcccd900 124 @SuppressWarnings("unchecked")
5d837f9b 125 public boolean equals(final Object obj) {
0316808c 126 if (this == obj) {
fcccd900 127 return true;
0316808c
FC
128 }
129 if (obj == null) {
fcccd900 130 return false;
0316808c
FC
131 }
132 if (getClass() != obj.getClass()) {
fcccd900 133 return false;
0316808c 134 }
5d837f9b 135 final TmfLocation<L> other = (TmfLocation<L>) obj;
6bab4511
AM
136 if (fLocationData == null) {
137 if (other.fLocationData != null) {
fcccd900 138 return false;
0316808c 139 }
6bab4511 140 } else if (!fLocationData.equals(other.fLocationData)) {
fcccd900 141 return false;
0316808c 142 }
fcccd900 143 return true;
ff4ed569
FC
144 }
145
fcccd900 146 @Override
cbdacf03 147 @SuppressWarnings("nls")
fcccd900 148 public String toString() {
6bab4511 149 return "TmfLocation [fLocation=" + fLocationData + "]";
fcccd900 150 }
452ad365 151
8c8bf09f 152}
This page took 0.044279 seconds and 5 git commands to generate.