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