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