(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / trace / TmfLocation.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.trace;
14
15 import java.lang.reflect.Method;
16
17 /**
18 * <b><u>TmfLocation</u></b>
19 * <p>
20 * A generic implementation of ITmfLocation
21 */
22 public class TmfLocation<L> implements ITmfLocation<L> {
23
24 private L fLocation;
25
26 @SuppressWarnings("unused")
27 private TmfLocation() {
28 }
29
30 public TmfLocation(L location) {
31 fLocation = location;
32 }
33
34 public TmfLocation(TmfLocation<L> other) {
35 if (other == null)
36 throw new IllegalArgumentException();
37 fLocation = other.fLocation;
38 }
39
40 public void setLocation(L location) {
41 fLocation = location;
42 }
43
44 public L getLocation() {
45 return fLocation;
46 }
47
48 // ------------------------------------------------------------------------
49 // Object
50 // ------------------------------------------------------------------------
51
52 @Override
53 public int hashCode() {
54 return fLocation.hashCode();
55 }
56
57 @Override
58 public boolean equals(Object other) {
59 if (!(other instanceof TmfLocation<?>))
60 return false;
61 TmfLocation<?> o = (TmfLocation<?>) other;
62 return fLocation.equals(o.fLocation);
63 }
64
65 @Override
66 public String toString() {
67 return fLocation.toString();
68 }
69
70 @SuppressWarnings("unchecked")
71 @Override
72 public TmfLocation<L> clone() {
73 TmfLocation<L> clone = null;
74 try {
75 clone = (TmfLocation<L>) super.clone();
76 Class<?> clazz = this.fLocation.getClass();
77 Method method = clazz.getMethod("clone", new Class[0]);
78 Object duplic = method.invoke(this.fLocation, new Object[0]);
79 clone.fLocation = (L) duplic;
80 } catch (NoSuchMethodException e) {
81 // exception suppressed
82 } catch (Exception e) {
83 throw new InternalError(e.toString());
84 }
85 return clone;
86 }
87
88 }
This page took 0.036876 seconds and 5 git commands to generate.