c781fe0974ecf173c7b78cc5db1a2072b8332738
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 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 * The standard constructor
55 * @param locations 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
= (ITmfLocation
<?
extends Comparable
<?
>>[]) new ITmfLocation
<?
>[fLocations
.length
];
71 for (int i
= 0; i
< fLocations
.length
; i
++) {
72 clones
[i
] = fLocations
[i
].clone();
74 return new TmfLocationArray(clones
);
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 @SuppressWarnings({ "unchecked", "rawtypes" })
83 public int compareTo(TmfLocationArray o
) {
84 for (int i
= 0; i
< fLocations
.length
; i
++) {
85 ITmfLocation
<?
extends Comparable
> l1
= (ITmfLocation
<?
extends Comparable
>) fLocations
[i
].getLocation();
86 ITmfLocation
<?
extends Comparable
> l2
= (ITmfLocation
<?
extends Comparable
>) o
.fLocations
[i
].getLocation();
87 int result
= l1
.getLocation().compareTo(l2
.getLocation());
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 * @see java.lang.Object#hashCode()
103 public int hashCode() {
104 final int prime
= 31;
106 result
= prime
* result
+ Arrays
.hashCode(fLocations
);
111 * @see java.lang.Object#equals(java.lang.Object)
114 public boolean equals(Object obj
) {
121 if (getClass() != obj
.getClass()) {
124 TmfLocationArray other
= (TmfLocationArray
) obj
;
125 if (!Arrays
.equals(fLocations
, other
.fLocations
)) {
132 * @see java.lang.Object#toString()
135 @SuppressWarnings("nls")
136 public String
toString() {
137 return "TmfLocationArray [locations=" + Arrays
.toString(fLocations
) + "]";
This page took 0.033262 seconds and 5 git commands to generate.