2010-07-12 Francois Chouinard <fchouinar@gmail.com> Contribution for Bug319428...
[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 if (fLocation == null)
55 return -1;
56 return fLocation.hashCode();
57 }
58
59 @Override
60 public boolean equals(Object other) {
61 if (!(other instanceof TmfLocation<?>))
62 return false;
63 TmfLocation<?> o = (TmfLocation<?>) other;
64 if (fLocation == null)
65 return (o.fLocation == null);
66 return fLocation.equals(o.fLocation);
67 }
68
69 @Override
70 public String toString() {
71 if (fLocation == null)
72 return "null";
73 return fLocation.toString();
74 }
75
76 @SuppressWarnings("unchecked")
77 @Override
78 public TmfLocation<L> clone() {
79 TmfLocation<L> clone = null;
80 try {
81 clone = (TmfLocation<L>) super.clone();
82 if (this.fLocation != null) {
83 Class<?> clazz = this.fLocation.getClass();
84 Method method = clazz.getMethod("clone", new Class[0]);
85 Object duplic = method.invoke(this.fLocation, new Object[0]);
86 clone.fLocation = (L) duplic;
87 }
88 } catch (NoSuchMethodException e) {
89 // exception suppressed
90 } catch (Exception e) {
91 throw new InternalError(e.toString());
92 }
93 return clone;
94 }
95
96 }
This page took 0.041591 seconds and 6 git commands to generate.