1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Utility functions for checking properties of trace objects |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.model; |
|
20 |
|
21 import java.util.Comparator; |
|
22 |
|
23 /** |
|
24 * Utility functions for checking properties of trace objects. |
|
25 * |
|
26 */ |
|
27 public class TraceObjectUtils { |
|
28 |
|
29 /** |
|
30 * Compares a trace to trace ID |
|
31 */ |
|
32 static Comparator<Object> traceToIDComparator = new Comparator<Object>() { |
|
33 |
|
34 /** |
|
35 * Compares a trace to trace name |
|
36 * |
|
37 * @param t1 |
|
38 * the trace |
|
39 * @param t2 |
|
40 * the trace name |
|
41 * @return the comparison result |
|
42 */ |
|
43 public int compare(Object t1, Object t2) { |
|
44 int n1 = ((Trace) t1).getID(); |
|
45 int n2 = (Integer) t2; |
|
46 return n1 > n2 ? 1 : n1 < n2 ? -1 : 0; |
|
47 } |
|
48 |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Compares a trace to trace name |
|
53 */ |
|
54 static Comparator<Object> traceToNameComparator = new Comparator<Object>() { |
|
55 |
|
56 /** |
|
57 * Compares a trace to trace name |
|
58 * |
|
59 * @param t1 |
|
60 * the trace |
|
61 * @param t2 |
|
62 * the trace name |
|
63 * @return the comparison result |
|
64 */ |
|
65 public int compare(Object t1, Object t2) { |
|
66 String n1 = ((Trace) t1).getName(); |
|
67 String n2 = (String) t2; |
|
68 if (n1 == null) { |
|
69 n1 = ""; //$NON-NLS-1$ |
|
70 } |
|
71 if (n2 == null) { |
|
72 n2 = ""; //$NON-NLS-1$ |
|
73 } |
|
74 return n1.compareTo(n2); |
|
75 } |
|
76 |
|
77 }; |
|
78 |
|
79 /** |
|
80 * Compares a trace to trace text |
|
81 */ |
|
82 static Comparator<Object> traceToTextComparator = new Comparator<Object>() { |
|
83 |
|
84 /** |
|
85 * Compares a trace to trace text |
|
86 * |
|
87 * @param t1 |
|
88 * the trace |
|
89 * @param t2 |
|
90 * the trace text |
|
91 * @return the comparison result |
|
92 */ |
|
93 public int compare(Object t1, Object t2) { |
|
94 String n1 = ((Trace) t1).getTrace(); |
|
95 String n2 = (String) t2; |
|
96 if (n1 == null) { |
|
97 n1 = ""; //$NON-NLS-1$ |
|
98 } |
|
99 if (n2 == null) { |
|
100 n2 = ""; //$NON-NLS-1$ |
|
101 } |
|
102 return n1.compareTo(n2); |
|
103 } |
|
104 |
|
105 }; |
|
106 |
|
107 /** |
|
108 * Compares trace objects by ID |
|
109 */ |
|
110 static Comparator<TraceObject> traceObjectIDComparator = new Comparator<TraceObject>() { |
|
111 |
|
112 /** |
|
113 * Compares ID's of trace objects |
|
114 * |
|
115 * @param t1 |
|
116 * trace 1 |
|
117 * @param t2 |
|
118 * trace 2 |
|
119 * @return the comparison result |
|
120 */ |
|
121 public int compare(TraceObject t1, TraceObject t2) { |
|
122 int n1 = t1.getID(); |
|
123 int n2 = t2.getID(); |
|
124 return n1 > n2 ? 1 : n1 < n2 ? -1 : 0; |
|
125 } |
|
126 |
|
127 }; |
|
128 |
|
129 /** |
|
130 * Compares trace objects by name |
|
131 */ |
|
132 static Comparator<TraceObject> traceObjectNameComparator = new Comparator<TraceObject>() { |
|
133 |
|
134 /** |
|
135 * Compares names of trace objects |
|
136 * |
|
137 * @param t1 |
|
138 * trace 1 |
|
139 * @param t2 |
|
140 * trace 2 |
|
141 * @return the comparison result |
|
142 */ |
|
143 public int compare(TraceObject t1, TraceObject t2) { |
|
144 String n1 = t1.getName(); |
|
145 String n2 = t2.getName(); |
|
146 if (n1 == null) { |
|
147 n1 = ""; //$NON-NLS-1$ |
|
148 } |
|
149 if (n2 == null) { |
|
150 n2 = ""; //$NON-NLS-1$ |
|
151 } |
|
152 return n1.compareTo(n2); |
|
153 } |
|
154 |
|
155 }; |
|
156 |
|
157 /** |
|
158 * Prevents construction |
|
159 */ |
|
160 private TraceObjectUtils() { |
|
161 } |
|
162 |
|
163 /** |
|
164 * Checks if trace parameter name is already in use and changes if it is. |
|
165 * |
|
166 * @param owner |
|
167 * the owner of the parameter |
|
168 * @param name |
|
169 * the parameter name |
|
170 * @return the modifier interface |
|
171 */ |
|
172 public static TraceObjectModifier modifyDuplicateParameterName(Trace owner, |
|
173 String name) { |
|
174 DuplicateParameterNameModifier modifier = new DuplicateParameterNameModifier( |
|
175 owner, name); |
|
176 modifier.processName(); |
|
177 return modifier; |
|
178 } |
|
179 |
|
180 /** |
|
181 * Gets the duplicate modifier from given text |
|
182 * |
|
183 * @param text |
|
184 * the text |
|
185 * @return the duplicate modifier |
|
186 */ |
|
187 public static String removeDuplicateModifier(String text) { |
|
188 String retval; |
|
189 String s = DuplicateValueModifier.getModifier(text); |
|
190 if (s != null) { |
|
191 retval = text.substring(s.length()); |
|
192 } else { |
|
193 retval = text; |
|
194 } |
|
195 return retval; |
|
196 } |
|
197 |
|
198 /** |
|
199 * Finds a property from a trace object. This returns an empty string if not |
|
200 * found |
|
201 * |
|
202 * @param object |
|
203 * the object |
|
204 * @param name |
|
205 * the property name |
|
206 * @return the property value |
|
207 */ |
|
208 public static String findProperty(TraceObject object, String name) { |
|
209 String retval = null; |
|
210 TraceObjectPropertyList propertyList = object |
|
211 .getExtension(TraceObjectPropertyList.class); |
|
212 if (propertyList != null) { |
|
213 TraceObjectProperty property = propertyList.getProperty(name); |
|
214 if (property != null) { |
|
215 retval = property.getValue(); |
|
216 } |
|
217 } |
|
218 if (retval == null) { |
|
219 retval = ""; //$NON-NLS-1$ |
|
220 } |
|
221 return retval; |
|
222 } |
|
223 |
|
224 } |
|