Fix for Linux tree item height bug.
[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 * @since 1.0
23 * @version 1.0
24 * @author Francois Chouinard
25 */
26 public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L> {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 private L fLocation;
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37
38 /**
39 * Default constructor (for the 'null' location)
40 */
41 @SuppressWarnings("unused")
42 private TmfLocation() {
43 fLocation = null;
44 }
45
46 /**
47 * Standard constructor.
48 *
49 * @param location the trace location
50 */
51 public TmfLocation(final L location) {
52 fLocation = location;
53 }
54
55 /**
56 * Copy constructor
57 *
58 * @param location the original location
59 */
60 public TmfLocation(final TmfLocation<L> location) {
61 fLocation = location.fLocation;
62 }
63
64 // ------------------------------------------------------------------------
65 // Getters
66 // ------------------------------------------------------------------------
67
68 /* (non-Javadoc)
69 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocation()
70 */
71 @Override
72 public L getLocation() {
73 return fLocation;
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 (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;
94 } else
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());
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 + ((fLocation != null) ? fLocation.hashCode() : 0);
116 return result;
117 }
118
119 /* (non-Javadoc)
120 * @see java.lang.Object#equals(java.lang.Object)
121 */
122 @Override
123 @SuppressWarnings("unchecked")
124 public boolean equals(final Object obj) {
125 if (this == obj)
126 return true;
127 if (obj == null)
128 return false;
129 if (getClass() != obj.getClass())
130 return false;
131 final TmfLocation<L> other = (TmfLocation<L>) obj;
132 if (fLocation == null) {
133 if (other.fLocation != null)
134 return false;
135 } else if (!fLocation.equals(other.fLocation))
136 return false;
137 return true;
138 }
139
140 @Override
141 @SuppressWarnings("nls")
142 public String toString() {
143 return "TmfLocation [fLocation=" + fLocation + "]";
144 }
145
146 }
This page took 0.034446 seconds and 6 git commands to generate.