Remove the generic location (replace by Comparable)
[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 /**
17 * A convenience implementation on of ITmfLocation. The generic class (L) must
18 * be comparable.
19 *
20 * @version 1.0
21 * @author Francois Chouinard
22 */
23 public abstract class TmfLocation implements ITmfLocation, Cloneable {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 private Comparable<?> fLocationData;
30
31 // ------------------------------------------------------------------------
32 // Constructors
33 // ------------------------------------------------------------------------
34
35 /**
36 * Default constructor (for the 'null' location)
37 */
38 @SuppressWarnings("unused")
39 private TmfLocation() {
40 }
41
42 /**
43 * Standard constructor.
44 *
45 * @param locationData the trace location
46 */
47 public TmfLocation(final Comparable<?> locationData) {
48 fLocationData = locationData;
49 }
50
51 /**
52 * Copy constructor
53 *
54 * @param location the original location
55 */
56 public TmfLocation(final TmfLocation location) {
57 fLocationData = location.fLocationData;
58 }
59
60 // ------------------------------------------------------------------------
61 // Getters
62 // ------------------------------------------------------------------------
63
64 /**
65 * @since 2.0
66 */
67 @Override
68 public Comparable<?> getLocationData() {
69 return fLocationData;
70 }
71
72 // ------------------------------------------------------------------------
73 // Cloneable
74 // ------------------------------------------------------------------------
75
76 @Override
77 public abstract TmfLocation clone();
78
79 // /* (non-Javadoc)
80 // * @see java.lang.Object#clone()
81 // */
82 // @Override
83 // @SuppressWarnings("unchecked")
84 // public TmfLocation<L> clone() {
85 // TmfLocation<L> clone = null;
86 // try {
87 // clone = (TmfLocation<L>) super.clone();
88 // if (fLocationData != null) {
89 // final Class<?> clazz = fLocationData.getClass();
90 // final Method method = clazz.getMethod("clone", new Class[0]); //$NON-NLS-1$
91 // final Object copy = method.invoke(this.fLocationData, new Object[0]);
92 // clone.fLocationData = (L) copy;
93 // } else {
94 // clone.fLocationData = null;
95 // }
96 // } catch (final CloneNotSupportedException e) {
97 // } catch (final NoSuchMethodException e) {
98 // } catch (final Exception e) {
99 // throw new InternalError(e.toString());
100 // }
101 // return clone;
102 // }
103
104 // ------------------------------------------------------------------------
105 // Object
106 // ------------------------------------------------------------------------
107
108 /* (non-Javadoc)
109 * @see java.lang.Object#hashCode()
110 */
111 @Override
112 public int hashCode() {
113 final int prime = 31;
114 int result = 1;
115 result = prime * result + ((fLocationData != null) ? fLocationData.hashCode() : 0);
116 return result;
117 }
118
119 /* (non-Javadoc)
120 * @see java.lang.Object#equals(java.lang.Object)
121 */
122 @Override
123 public boolean equals(final Object obj) {
124 if (this == obj) {
125 return true;
126 }
127 if (obj == null) {
128 return false;
129 }
130 if (getClass() != obj.getClass()) {
131 return false;
132 }
133 final TmfLocation other = (TmfLocation) obj;
134 if (fLocationData == null) {
135 if (other.fLocationData != null) {
136 return false;
137 }
138 } else if (!fLocationData.equals(other.fLocationData)) {
139 return false;
140 }
141 return true;
142 }
143
144 @Override
145 @SuppressWarnings("nls")
146 public String toString() {
147 return "TmfLocation [fLocation=" + fLocationData + "]";
148 }
149
150 }
This page took 0.034508 seconds and 5 git commands to generate.