Merge corrected branch 'master'
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / trace / TmfLocationArray.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 * Francois Chouinard - Put in shape for 1.0
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.tmf.core.trace;
15
16 import java.util.Arrays;
17
18 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
19
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 */
27 public class TmfLocationArray implements Comparable<TmfLocationArray>, Cloneable {
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 // ------------------------------------------------------------------------
80
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 */
102 @Override
103 public int hashCode() {
104 final int prime = 31;
105 int result = 1;
106 result = prime * result + Arrays.hashCode(fLocations);
107 return result;
108 }
109
110 /* (non-Javadoc)
111 * @see java.lang.Object#equals(java.lang.Object)
112 */
113 @Override
114 public boolean equals(Object obj) {
115 if (this == obj) {
116 return true;
117 }
118 if (obj == null) {
119 return false;
120 }
121 if (getClass() != obj.getClass()) {
122 return false;
123 }
124 TmfLocationArray other = (TmfLocationArray) obj;
125 if (!Arrays.equals(fLocations, other.fLocations)) {
126 return false;
127 }
128 return true;
129 }
130
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 }
139
140 }
This page took 0.034626 seconds and 6 git commands to generate.