Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
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 | ||
ff4ed569 FC |
15 | import java.lang.reflect.Method; |
16 | ||
8c8bf09f ASL |
17 | /** |
18 | * <b><u>TmfLocation</u></b> | |
19 | * <p> | |
452ad365 | 20 | * A generic implementation of ITmfLocation |
8c8bf09f | 21 | */ |
452ad365 | 22 | public class TmfLocation<L> implements ITmfLocation<L> { |
8c8bf09f | 23 | |
452ad365 | 24 | private L fLocation; |
8c8bf09f | 25 | |
ff4ed569 FC |
26 | @SuppressWarnings("unused") |
27 | private TmfLocation() { | |
28 | } | |
29 | ||
452ad365 | 30 | public TmfLocation(L location) { |
8c8bf09f ASL |
31 | fLocation = location; |
32 | } | |
33 | ||
ff4ed569 FC |
34 | public TmfLocation(TmfLocation<L> other) { |
35 | if (other == null) | |
36 | throw new IllegalArgumentException(); | |
37 | fLocation = other.fLocation; | |
38 | } | |
39 | ||
d4011df2 | 40 | @Override |
452ad365 | 41 | public void setLocation(L location) { |
8c8bf09f ASL |
42 | fLocation = location; |
43 | } | |
44 | ||
d4011df2 | 45 | @Override |
452ad365 | 46 | public L getLocation() { |
8c8bf09f ASL |
47 | return fLocation; |
48 | } | |
49 | ||
ff4ed569 FC |
50 | // ------------------------------------------------------------------------ |
51 | // Object | |
52 | // ------------------------------------------------------------------------ | |
53 | ||
54 | @Override | |
55 | public int hashCode() { | |
abfad0aa FC |
56 | if (fLocation == null) |
57 | return -1; | |
ff4ed569 FC |
58 | return fLocation.hashCode(); |
59 | } | |
60 | ||
61 | @Override | |
62 | public boolean equals(Object other) { | |
63 | if (!(other instanceof TmfLocation<?>)) | |
64 | return false; | |
65 | TmfLocation<?> o = (TmfLocation<?>) other; | |
abfad0aa FC |
66 | if (fLocation == null) |
67 | return (o.fLocation == null); | |
ff4ed569 FC |
68 | return fLocation.equals(o.fLocation); |
69 | } | |
70 | ||
452ad365 FC |
71 | @Override |
72 | public String toString() { | |
abfad0aa FC |
73 | if (fLocation == null) |
74 | return "null"; | |
452ad365 FC |
75 | return fLocation.toString(); |
76 | } | |
77 | ||
8c8bf09f | 78 | @SuppressWarnings("unchecked") |
ff4ed569 | 79 | @Override |
452ad365 | 80 | public TmfLocation<L> clone() { |
ff4ed569 | 81 | TmfLocation<L> clone = null; |
8c8bf09f | 82 | try { |
ff4ed569 | 83 | clone = (TmfLocation<L>) super.clone(); |
abfad0aa FC |
84 | if (this.fLocation != null) { |
85 | Class<?> clazz = this.fLocation.getClass(); | |
86 | Method method = clazz.getMethod("clone", new Class[0]); | |
87 | Object duplic = method.invoke(this.fLocation, new Object[0]); | |
88 | clone.fLocation = (L) duplic; | |
89 | } | |
ff4ed569 FC |
90 | } catch (NoSuchMethodException e) { |
91 | // exception suppressed | |
92 | } catch (Exception e) { | |
93 | throw new InternalError(e.toString()); | |
8c8bf09f | 94 | } |
ff4ed569 | 95 | return clone; |
8c8bf09f | 96 | } |
452ad365 | 97 | |
8c8bf09f | 98 | } |