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
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
21 * A convenience class to store trace location arrays. The main purpose is to
22 * provide a Comparable implementation for TmfExperimentLocation.
25 * @author Patrick Tasse
27 public class TmfLocationArray
implements Comparable
<TmfLocationArray
>, Cloneable
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private final ITmfLocation
<?
extends Comparable
<?
>>[] fLocations
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
40 * The standard constructor
42 * @param locations the locations
44 public TmfLocationArray(ITmfLocation
<?
extends Comparable
<?
>>[] locations
) {
45 fLocations
= locations
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Get the locations inside this array
55 * @return the locations
57 public ITmfLocation
<?
extends Comparable
<?
>>[] getLocations() {
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 * @see java.lang.Object#clone()
69 public TmfLocationArray
clone() {
70 ITmfLocation
<?
extends Comparable
<?
>>[] clones
= new ITmfLocation
<?
>[fLocations
.length
];
71 for (int i
= 0; i
< fLocations
.length
; i
++) {
72 ITmfLocation
<?
> location
= fLocations
[i
];
73 clones
[i
] = (location
!= null) ? location
.clone() : null;
75 return new TmfLocationArray(clones
);
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 @SuppressWarnings("rawtypes")
84 public int compareTo(TmfLocationArray o
) {
85 for (int i
= 0; i
< fLocations
.length
; i
++) {
86 ITmfLocation
<?
extends Comparable
> l1
= (ITmfLocation
<?
extends Comparable
>) fLocations
[i
].getLocation();
87 ITmfLocation
<?
extends Comparable
> l2
= (ITmfLocation
<?
extends Comparable
>) o
.fLocations
[i
].getLocation();
88 int result
= l1
.getLocation().compareTo(l2
.getLocation());
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * @see java.lang.Object#hashCode()
104 public int hashCode() {
105 final int prime
= 31;
107 result
= prime
* result
+ Arrays
.hashCode(fLocations
);
112 * @see java.lang.Object#equals(java.lang.Object)
115 public boolean equals(Object obj
) {
122 if (getClass() != obj
.getClass()) {
125 TmfLocationArray other
= (TmfLocationArray
) obj
;
126 if (!Arrays
.equals(fLocations
, other
.fLocations
)) {
133 * @see java.lang.Object#toString()
136 @SuppressWarnings("nls")
137 public String
toString() {
138 return "TmfLocationArray [locations=" + Arrays
.toString(fLocations
) + "]";
This page took 0.043313 seconds and 6 git commands to generate.