Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
fcccd900 | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
8c8bf09f ASL |
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 | |
fcccd900 | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
ff4ed569 FC |
16 | import java.lang.reflect.Method; |
17 | ||
8c8bf09f | 18 | /** |
fcccd900 FC |
19 | * A convenience implementation on of ITmfLocation. The generic class (L) must |
20 | * be comparable. | |
f7703ed6 FC |
21 | * |
22 | * @since 1.0 | |
23 | * @version 1.0 | |
24 | * @author Francois Chouinard | |
8c8bf09f | 25 | */ |
fcccd900 FC |
26 | public class TmfLocation<L extends Comparable<L>> implements ITmfLocation<L> { |
27 | ||
fcccd900 FC |
28 | // ------------------------------------------------------------------------ |
29 | // Attributes | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | private L fLocation; | |
33 | ||
34 | // ------------------------------------------------------------------------ | |
35 | // Constructors | |
36 | // ------------------------------------------------------------------------ | |
37 | ||
38 | /** | |
39 | * Default constructor (for the 'null' location) | |
40 | */ | |
2848c377 | 41 | @SuppressWarnings("unused") |
fcccd900 FC |
42 | private TmfLocation() { |
43 | fLocation = null; | |
44 | } | |
45 | ||
46 | /** | |
47 | * Standard constructor. | |
48 | * | |
49 | * @param location the trace location | |
50 | */ | |
5d837f9b | 51 | public TmfLocation(final L location) { |
fcccd900 FC |
52 | fLocation = location; |
53 | } | |
54 | ||
55 | /** | |
56 | * Copy constructor | |
57 | * | |
2848c377 | 58 | * @param location the original location |
fcccd900 | 59 | */ |
5d837f9b | 60 | public TmfLocation(final TmfLocation<L> location) { |
fcccd900 FC |
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) { | |
5d837f9b FC |
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]); | |
fcccd900 | 93 | clone.fLocation = (L) copy; |
5d837f9b | 94 | } else |
fcccd900 | 95 | clone.fLocation = null; |
5d837f9b FC |
96 | } catch (final CloneNotSupportedException e) { |
97 | } catch (final NoSuchMethodException e) { | |
98 | } catch (final Exception e) { | |
fcccd900 FC |
99 | throw new InternalError(e.toString()); |
100 | } | |
101 | return clone; | |
102 | } | |
103 | ||
104 | // ------------------------------------------------------------------------ | |
ff4ed569 FC |
105 | // Object |
106 | // ------------------------------------------------------------------------ | |
107 | ||
fcccd900 FC |
108 | /* (non-Javadoc) |
109 | * @see java.lang.Object#hashCode() | |
110 | */ | |
111 | @Override | |
ff4ed569 | 112 | public int hashCode() { |
fcccd900 FC |
113 | final int prime = 31; |
114 | int result = 1; | |
115 | result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0); | |
116 | return result; | |
ff4ed569 FC |
117 | } |
118 | ||
fcccd900 FC |
119 | /* (non-Javadoc) |
120 | * @see java.lang.Object#equals(java.lang.Object) | |
121 | */ | |
ff4ed569 | 122 | @Override |
fcccd900 | 123 | @SuppressWarnings("unchecked") |
5d837f9b | 124 | public boolean equals(final Object obj) { |
fcccd900 FC |
125 | if (this == obj) |
126 | return true; | |
127 | if (obj == null) | |
128 | return false; | |
129 | if (getClass() != obj.getClass()) | |
130 | return false; | |
5d837f9b | 131 | final TmfLocation<L> other = (TmfLocation<L>) obj; |
fcccd900 FC |
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; | |
ff4ed569 FC |
138 | } |
139 | ||
fcccd900 | 140 | @Override |
cbdacf03 | 141 | @SuppressWarnings("nls") |
fcccd900 FC |
142 | public String toString() { |
143 | return "TmfLocation [fLocation=" + fLocation + "]"; | |
144 | } | |
452ad365 | 145 | |
8c8bf09f | 146 | } |