Commit | Line | Data |
---|---|---|
a79913eb FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.experiment; |
a79913eb | 14 | |
478e04a4 PT |
15 | import java.util.Arrays; |
16 | ||
6c13869b | 17 | import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; |
a79913eb FC |
18 | |
19 | public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable { | |
20 | public ITmfLocation<? extends Comparable<?>>[] locations; | |
21 | ||
22 | public TmfLocationArray(ITmfLocation<? extends Comparable<?>>[] locations) { | |
23 | this.locations = locations; | |
24 | } | |
25 | ||
26 | @SuppressWarnings({ "unchecked", "rawtypes" }) | |
27 | @Override | |
28 | public int compareTo(TmfLocationArray o) { | |
29 | for (int i = 0; i < locations.length; i++) { | |
30 | ITmfLocation<? extends Comparable> l1 = (ITmfLocation<? extends Comparable>) locations[i].getLocation(); | |
31 | ITmfLocation<? extends Comparable> l2 = (ITmfLocation<? extends Comparable>) o.locations[i].getLocation(); | |
32 | int result = l1.getLocation().compareTo(l2.getLocation()); | |
33 | if (result != 0) { | |
34 | return result; | |
35 | } | |
36 | } | |
37 | return 0; | |
38 | } | |
39 | ||
40 | /* (non-Javadoc) | |
41 | * @see java.lang.Object#clone() | |
42 | */ | |
43 | @Override | |
44 | protected TmfLocationArray clone() { | |
45 | ITmfLocation<? extends Comparable<?>>[] clones = (ITmfLocation<? extends Comparable<?>>[]) new ITmfLocation<?>[locations.length]; | |
46 | for (int i = 0; i < locations.length; i++) { | |
47 | clones[i] = locations[i].clone(); | |
48 | } | |
49 | return new TmfLocationArray(clones); | |
50 | } | |
478e04a4 PT |
51 | |
52 | @Override | |
53 | public int hashCode() { | |
54 | final int prime = 31; | |
55 | int result = 1; | |
56 | result = prime * result + Arrays.hashCode(locations); | |
57 | return result; | |
58 | } | |
59 | ||
60 | @Override | |
61 | public boolean equals(Object obj) { | |
62 | if (this == obj) | |
63 | return true; | |
64 | if (obj == null) | |
65 | return false; | |
66 | if (getClass() != obj.getClass()) | |
67 | return false; | |
68 | TmfLocationArray other = (TmfLocationArray) obj; | |
69 | if (!Arrays.equals(locations, other.locations)) | |
70 | return false; | |
71 | return true; | |
72 | } | |
73 | ||
a79913eb FC |
74 | } |
75 |