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