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 | ||
452ad365 | 40 | public void setLocation(L location) { |
8c8bf09f ASL |
41 | fLocation = location; |
42 | } | |
43 | ||
452ad365 | 44 | public L getLocation() { |
8c8bf09f ASL |
45 | return fLocation; |
46 | } | |
47 | ||
ff4ed569 FC |
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 | ||
452ad365 FC |
65 | @Override |
66 | public String toString() { | |
67 | return fLocation.toString(); | |
68 | } | |
69 | ||
8c8bf09f | 70 | @SuppressWarnings("unchecked") |
ff4ed569 | 71 | @Override |
452ad365 | 72 | public TmfLocation<L> clone() { |
ff4ed569 | 73 | TmfLocation<L> clone = null; |
8c8bf09f | 74 | try { |
ff4ed569 FC |
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()); | |
8c8bf09f | 84 | } |
ff4ed569 | 85 | return clone; |
8c8bf09f | 86 | } |
452ad365 | 87 | |
8c8bf09f | 88 | } |