1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Francois Chouinard - Put in shape for 1.0
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.trace
;
16 import java
.util
.Arrays
;
19 * A convenience class to store trace location arrays. The main purpose is to
20 * provide a Comparable implementation for TmfExperimentLocation.
23 * @author Patrick Tasse
25 public class TmfLocationArray
implements Comparable
<TmfLocationArray
>, Cloneable
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 private TmfRankedLocation
[] fLocations
;
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
38 * The standard constructor
40 * @param locations the locations
42 public TmfLocationArray(TmfRankedLocation
[] locations
) {
43 fLocations
= locations
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
51 * The standard constructor
53 * @param locations the locations
55 public TmfRankedLocation
[] getLocations() {
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * @see java.lang.Object#clone()
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;
73 return new TmfLocationArray(clones
);
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
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
);
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * @see java.lang.Object#hashCode()
101 public int hashCode() {
102 final int prime
= 31;
104 result
= prime
* result
+ Arrays
.hashCode(fLocations
);
109 * @see java.lang.Object#equals(java.lang.Object)
112 public boolean equals(Object obj
) {
119 if (getClass() != obj
.getClass()) {
122 TmfLocationArray other
= (TmfLocationArray
) obj
;
123 if (!Arrays
.equals(fLocations
, other
.fLocations
)) {
130 * @see java.lang.Object#toString()
133 @SuppressWarnings("nls")
134 public String
toString() {
135 return "TmfLocationArray [locations=" + Arrays
.toString(fLocations
) + "]";