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