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 / TmfLocationArray.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 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 * Francois Chouinard - Put in shape for 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.tmf.core.trace;
15
16 import java.util.Arrays;
17
18 /**
19 * A convenience class to store trace location arrays. The main purpose is to
20 * provide a Comparable implementation for TmfExperimentLocation.
21 *
22 * @version 1.0
23 * @author Patrick Tasse
24 */
25 public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable {
26
27 // ------------------------------------------------------------------------
28 // Attributes
29 // ------------------------------------------------------------------------
30
31 private TmfRankedLocation[] fLocations;
32
33 // ------------------------------------------------------------------------
34 // Constructors
35 // ------------------------------------------------------------------------
36
37 /**
38 * The standard constructor
39 *
40 * @param locations the locations
41 */
42 public TmfLocationArray(TmfRankedLocation[] locations) {
43 fLocations = locations;
44 }
45
46 // ------------------------------------------------------------------------
47 // Getters
48 // ------------------------------------------------------------------------
49
50 /**
51 * The standard constructor
52 *
53 * @param locations the locations
54 */
55 public TmfRankedLocation[] getLocations() {
56 return fLocations;
57 }
58
59 // ------------------------------------------------------------------------
60 // Cloneable
61 // ------------------------------------------------------------------------
62
63 /* (non-Javadoc)
64 * @see java.lang.Object#clone()
65 */
66 @Override
67 public TmfLocationArray clone() {
68 TmfRankedLocation[] clones = new TmfRankedLocation[fLocations.length];
69 for (int i = 0; i < fLocations.length; i++) {
70 TmfRankedLocation location = fLocations[i];
71 clones[i] = (location != null) ? location.clone() : null;
72 }
73 return new TmfLocationArray(clones);
74 }
75
76 // ------------------------------------------------------------------------
77 // Comparable
78 // ------------------------------------------------------------------------
79
80 @Override
81 public int compareTo(TmfLocationArray o) {
82 for (int i = 0; i < fLocations.length; i++) {
83 TmfRankedLocation l1 = fLocations[i];
84 TmfRankedLocation l2 = o.fLocations[i];
85 int result = l1.compareTo(l2);
86 if (result != 0) {
87 return result;
88 }
89 }
90 return 0;
91 }
92
93 // ------------------------------------------------------------------------
94 // Object
95 // ------------------------------------------------------------------------
96
97 /* (non-Javadoc)
98 * @see java.lang.Object#hashCode()
99 */
100 @Override
101 public int hashCode() {
102 final int prime = 31;
103 int result = 1;
104 result = prime * result + Arrays.hashCode(fLocations);
105 return result;
106 }
107
108 /* (non-Javadoc)
109 * @see java.lang.Object#equals(java.lang.Object)
110 */
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) {
114 return true;
115 }
116 if (obj == null) {
117 return false;
118 }
119 if (getClass() != obj.getClass()) {
120 return false;
121 }
122 TmfLocationArray other = (TmfLocationArray) obj;
123 if (!Arrays.equals(fLocations, other.fLocations)) {
124 return false;
125 }
126 return true;
127 }
128
129 /* (non-Javadoc)
130 * @see java.lang.Object#toString()
131 */
132 @Override
133 @SuppressWarnings("nls")
134 public String toString() {
135 return "TmfLocationArray [locations=" + Arrays.toString(fLocations) + "]";
136 }
137
138 }
This page took 0.034839 seconds and 6 git commands to generate.