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