Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfLocation.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2012 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 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.trace;
15
16
17 /**
18 * A abstract implementation of ITmfLocation. The concrete classes must provide
19 * comparable location information.
20 *
21 * @version 2.0
22 * @author Francois Chouinard
23 */
24 public abstract class TmfLocation implements ITmfLocation, Cloneable {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 private Comparable<?> fLocationInfo;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 /**
37 * Default constructor (for the 'null' location)
38 */
39 @SuppressWarnings("unused")
40 private TmfLocation() {
41 fLocationInfo = null;
42 }
43
44 /**
45 * Standard constructor.
46 *
47 * @param locationInfo the concrete trace location
48 */
49 public TmfLocation(final Comparable<?> locationInfo) {
50 fLocationInfo = locationInfo;
51 }
52
53 /**
54 * Copy constructor
55 *
56 * @param location the original trace location
57 */
58 public TmfLocation(final TmfLocation location) {
59 fLocationInfo = location.fLocationInfo;
60 }
61
62 // ------------------------------------------------------------------------
63 // Getters
64 // ------------------------------------------------------------------------
65
66 /* (non-Javadoc)
67 * @see org.eclipse.linuxtools.tmf.core.trace.ITmfLocation#getLocationInfo()
68 */
69 /**
70 * @since 2.0
71 */
72 @Override
73 public Comparable<?> getLocationInfo() {
74 return fLocationInfo;
75 }
76
77 // ------------------------------------------------------------------------
78 // Cloneable
79 // ------------------------------------------------------------------------
80
81 /* (non-Javadoc)
82 * @see java.lang.Object#clone()
83 */
84 @Override
85 public TmfLocation clone() {
86 TmfLocation clone = null;
87 try {
88 clone = (TmfLocation) super.clone();
89 clone.fLocationInfo = cloneLocationInfo();
90 } catch (CloneNotSupportedException e) {
91 }
92 return clone;
93 }
94
95 /**
96 * Delegate to the locationInfo cloning to the subclasses
97 *
98 * @return the locationInfo clone
99 * @since 2.0
100 */
101 protected abstract Comparable<?> cloneLocationInfo();
102
103 // ------------------------------------------------------------------------
104 // Object
105 // ------------------------------------------------------------------------
106
107 /* (non-Javadoc)
108 * @see java.lang.Object#hashCode()
109 */
110 @Override
111 public int hashCode() {
112 final int prime = 31;
113 int result = 1;
114 result = prime * result + ((fLocationInfo != null) ? fLocationInfo.hashCode() : 0);
115 return result;
116 }
117
118 /* (non-Javadoc)
119 * @see java.lang.Object#equals(java.lang.Object)
120 */
121 @Override
122 public boolean equals(final Object obj) {
123 if (this == obj) {
124 return true;
125 }
126 if (obj == null) {
127 return false;
128 }
129 if (getClass() != obj.getClass()) {
130 return false;
131 }
132 final TmfLocation other = (TmfLocation) obj;
133 if (fLocationInfo == null) {
134 if (other.fLocationInfo != null) {
135 return false;
136 }
137 } else if (!fLocationInfo.equals(other.fLocationInfo)) {
138 return false;
139 }
140 return true;
141 }
142
143 @Override
144 @SuppressWarnings("nls")
145 public String toString() {
146 return "TmfLocation [fLocation=" + fLocationInfo + "]";
147 }
148
149 }
This page took 0.033126 seconds and 5 git commands to generate.