Fix for bug 381411: Implement ranked location in experiment.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / trace / TmfRankedLocation.java
1 /*******************************************************************************
2 * Copyright (c) 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.core.trace;
14
15 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
16 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
17
18 /**
19 * A pair of trace location and trace rank.
20 *
21 * @version 1.0
22 * @author Patrick Tasse
23 */
24 public class TmfRankedLocation implements Comparable<TmfRankedLocation>, Cloneable {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31 private long fRank;
32
33 // ------------------------------------------------------------------------
34 // Constructors
35 // ------------------------------------------------------------------------
36
37 /**
38 * The standard constructor
39 *
40 * @param context a trace context
41 */
42 public TmfRankedLocation(ITmfContext context) {
43 fLocation = context.getLocation().clone();
44 fRank = context.getRank();
45 }
46
47 /**
48 * Private constructor
49 *
50 * @param location the trace location
51 * @param rank the trace rank
52 */
53 private TmfRankedLocation(ITmfLocation<? extends Comparable<?>> location, long rank) {
54 fLocation = location;
55 fRank = rank;
56 }
57
58 // ------------------------------------------------------------------------
59 // Getters
60 // ------------------------------------------------------------------------
61
62 /**
63 * Get the trace location
64 *
65 * @return the trace location
66 */
67 public ITmfLocation<? extends Comparable<?>> getLocation() {
68 return fLocation;
69 }
70
71 /**
72 * Get the trace rank
73 *
74 * @return the trace rank
75 */
76 public long getRank() {
77 return fRank;
78 }
79
80 // ------------------------------------------------------------------------
81 // Cloneable
82 // ------------------------------------------------------------------------
83
84 /* (non-Javadoc)
85 * @see java.lang.Object#clone()
86 */
87 @Override
88 public TmfRankedLocation clone() {
89 return new TmfRankedLocation(fLocation.clone(), fRank);
90 }
91
92 // ------------------------------------------------------------------------
93 // Comparable
94 // ------------------------------------------------------------------------
95
96 /*
97 * (non-Javadoc)
98 * @see java.lang.Comparable#compareTo(java.lang.Object)
99 */
100 @Override
101 public int compareTo(TmfRankedLocation o) {
102 return Long.valueOf(fRank).compareTo(Long.valueOf(o.fRank));
103 }
104
105 // ------------------------------------------------------------------------
106 // Object
107 // ------------------------------------------------------------------------
108
109 /* (non-Javadoc)
110 * @see java.lang.Object#hashCode()
111 */
112 @Override
113 public int hashCode() {
114 final int prime = 31;
115 int result = 1;
116 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
117 result = prime * result + (int) (fRank ^ (fRank >>> 32));
118 return result;
119 }
120
121 /* (non-Javadoc)
122 * @see java.lang.Object#equals(java.lang.Object)
123 */
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj) {
127 return true;
128 }
129 if (obj == null) {
130 return false;
131 }
132 if (getClass() != obj.getClass()) {
133 return false;
134 }
135 TmfRankedLocation other = (TmfRankedLocation) obj;
136 if (fLocation == null) {
137 if (other.fLocation != null) {
138 return false;
139 }
140 } else if (!fLocation.equals(other.fLocation)) {
141 return false;
142 }
143 if (fRank != other.fRank) {
144 return false;
145 }
146 return true;
147 }
148
149 /* (non-Javadoc)
150 * @see java.lang.Object#toString()
151 */
152 @Override
153 @SuppressWarnings("nls")
154 public String toString() {
155 return fLocation + "," + fRank;
156 }
157
158 }
This page took 0.032813 seconds and 5 git commands to generate.