Rename xxx.lttng to xxx.lttng.core
[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 @SuppressWarnings("rawtypes")
23 public class TmfLocation<L extends Comparable> implements ITmfLocation<L> {
24
25 private L fLocation;
26
27 @SuppressWarnings("unused")
28 private TmfLocation() {
29 }
30
31 public TmfLocation(L location) {
32 fLocation = location;
33 }
34
35 public TmfLocation(TmfLocation<L> other) {
36 if (other == null)
37 throw new IllegalArgumentException();
38 fLocation = other.fLocation;
39 }
40
41 @Override
42 public void setLocation(L location) {
43 fLocation = location;
44 }
45
46 @Override
47 public L getLocation() {
48 return fLocation;
49 }
50
51 // ------------------------------------------------------------------------
52 // Object
53 // ------------------------------------------------------------------------
54
55 @Override
56 public int hashCode() {
57 if (fLocation == null)
58 return -1;
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;
67 if (fLocation == null)
68 return (o.fLocation == null);
69 return fLocation.equals(o.fLocation);
70 }
71
72 @Override
73 @SuppressWarnings("nls")
74 public String toString() {
75 if (fLocation == null)
76 return "null";
77 return fLocation.toString();
78 }
79
80 @Override
81 @SuppressWarnings({ "nls", "unchecked" })
82 public TmfLocation<L> clone() {
83 TmfLocation<L> clone = null;
84 try {
85 clone = (TmfLocation<L>) super.clone();
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 }
92 } catch (NoSuchMethodException e) {
93 // exception suppressed
94 } catch (Exception e) {
95 throw new InternalError(e.toString());
96 }
97 return clone;
98 }
99
100 }
This page took 0.031746 seconds and 5 git commands to generate.