tmf: Rename the UI TmfStatistics class to TmfStatisticsValues
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / Utils.java
CommitLineData
b0d3496e 1/*****************************************************************************\r
fb5cad3d 2 * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2012 Ericsson.\r
b0d3496e
ASL
3 * All rights reserved. This program and the accompanying materials\r
4 * are made available under the terms of the Eclipse Public License v1.0\r
5 * which accompanies this distribution, and is available at\r
6 * http://www.eclipse.org/legal/epl-v10.html\r
7 *\r
8 * Contributors:\r
fb5cad3d
PT
9 * Intel Corporation - Initial API and implementation\r
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
11 * Alvaro Sanchez-Leon - Udpated for TMF\r
12 * Patrick Tasse - Refactoring\r
b0d3496e 13 *\r
b0d3496e
ASL
14 *****************************************************************************/\r
15\r
2fa130b8 16package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
b0d3496e
ASL
17\r
18import java.text.SimpleDateFormat;\r
19import java.util.Date;\r
20import java.util.Iterator;\r
b0d3496e 21\r
2fa130b8 22import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
fb5cad3d 23import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
b0d3496e
ASL
24import org.eclipse.swt.graphics.Color;\r
25import org.eclipse.swt.graphics.Device;\r
26import org.eclipse.swt.graphics.GC;\r
27import org.eclipse.swt.graphics.Point;\r
28import org.eclipse.swt.graphics.Rectangle;\r
29import org.eclipse.swt.widgets.Display;\r
30\r
013a5f1c
AM
31/**\r
32 * General utilities and definitions used by the time graph widget\r
33 *\r
34 * @version 1.0\r
35 * @author Alvaro Sanchez-Leon\r
36 * @author Patrick Tasse\r
37 */\r
b0d3496e
ASL
38public class Utils {\r
39\r
3934297e 40 /** Time format for dates and timestamp */\r
fb5cad3d 41 public enum TimeFormat {\r
3934297e
AM
42 /** Relative to the start of the trace */\r
43 RELATIVE,\r
44 /** Absolute timestamp (ie, relative to the Unix epoch) */\r
45 ABSOLUTE\r
013a5f1c 46 }\r
b0d3496e 47\r
fb5cad3d
PT
48 static public final int IMG_THREAD_RUNNING = 0;\r
49 static public final int IMG_THREAD_SUSPENDED = 1;\r
50 static public final int IMG_THREAD_STOPPED = 2;\r
51 static public final int IMG_METHOD_RUNNING = 3;\r
52 static public final int IMG_METHOD = 4;\r
53 static public final int IMG_NUM = 5;\r
b0d3496e 54\r
fb5cad3d 55 static public final Object[] _empty = new Object[0];\r
b0d3496e 56\r
4a56c4e6 57 public static enum Resolution {\r
fb5cad3d 58 SECONDS, MILLISEC, MICROSEC, NANOSEC\r
013a5f1c 59 }\r
fb5cad3d
PT
60\r
61 static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$\r
62 static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$\r
fb5cad3d
PT
63\r
64 static Rectangle clone(Rectangle source) {\r
65 return new Rectangle(source.x, source.y, source.width, source.height);\r
66 }\r
67\r
3934297e
AM
68 /**\r
69 * Initialize a Rectangle object to default values (all equal to 0)\r
70 *\r
71 * @param rect\r
72 * The Rectangle to initialize\r
73 */\r
fb5cad3d
PT
74 static public void init(Rectangle rect) {\r
75 rect.x = 0;\r
76 rect.y = 0;\r
77 rect.width = 0;\r
78 rect.height = 0;\r
79 }\r
80\r
3934297e
AM
81 /**\r
82 * Initialize a Rectangle object with all the given values\r
83 *\r
84 * @param rect\r
85 * The Rectangle object to initialize\r
86 * @param x\r
87 * The X coordinate\r
88 * @param y\r
89 * The Y coordinate\r
90 * @param width\r
91 * The width of the rectangle\r
92 * @param height\r
93 * The height of the rectangle\r
94 */\r
fb5cad3d
PT
95 static public void init(Rectangle rect, int x, int y, int width, int height) {\r
96 rect.x = x;\r
97 rect.y = y;\r
98 rect.width = width;\r
99 rect.height = height;\r
100 }\r
101\r
3934297e
AM
102 /**\r
103 * Initialize a Rectangle object to another existing Rectangle's values.\r
104 *\r
105 * @param rect\r
106 * The Rectangle to initialize\r
107 * @param source\r
108 * The reference Rectangle to copy\r
109 */\r
fb5cad3d
PT
110 static public void init(Rectangle rect, Rectangle source) {\r
111 rect.x = source.x;\r
112 rect.y = source.y;\r
113 rect.width = source.width;\r
114 rect.height = source.height;\r
115 }\r
116\r
3934297e
AM
117 /**\r
118 * Reduce the size of a given rectangle by the given amounts.\r
119 *\r
120 * @param rect\r
121 * The rectangle to modify\r
122 * @param x\r
123 * The reduction in width\r
124 * @param y\r
125 * The reduction in height\r
126 */\r
fb5cad3d
PT
127 static public void deflate(Rectangle rect, int x, int y) {\r
128 rect.x += x;\r
129 rect.y += y;\r
130 rect.width -= x + x;\r
131 rect.height -= y + y;\r
132 }\r
133\r
3934297e
AM
134 /**\r
135 * Increase the size of a given rectangle by the given amounts.\r
136 *\r
137 * @param rect\r
138 * The rectangle to modify\r
139 * @param x\r
140 * The augmentation in width\r
141 * @param y\r
142 * The augmentation in height\r
143 */\r
fb5cad3d
PT
144 static public void inflate(Rectangle rect, int x, int y) {\r
145 rect.x -= x;\r
146 rect.y -= y;\r
147 rect.width += x + x;\r
148 rect.height += y + y;\r
149 }\r
150\r
151 static void dispose(Color col) {\r
013a5f1c 152 if (null != col) {\r
fb5cad3d 153 col.dispose();\r
013a5f1c 154 }\r
fb5cad3d
PT
155 }\r
156\r
3934297e
AM
157 /**\r
158 * Get the resulting color from a mix of two existing ones for a given\r
159 * display.\r
160 *\r
161 * @param display\r
162 * The display device (which might affect the color conversion)\r
163 * @param c1\r
164 * The first color\r
165 * @param c2\r
166 * The second color\r
167 * @param w1\r
168 * The gamma level for color 1\r
169 * @param w2\r
170 * The gamma level for color 2\r
171 * @return The resulting color\r
172 */\r
fb5cad3d
PT
173 static public Color mixColors(Device display, Color c1, Color c2, int w1,\r
174 int w2) {\r
175 return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())\r
176 / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())\r
177 / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())\r
178 / (w1 + w2));\r
179 }\r
180\r
3934297e
AM
181 /**\r
182 * Get the system color with the given ID.\r
183 *\r
184 * @param id\r
185 * The color ID\r
186 * @return The resulting color\r
187 */\r
fb5cad3d
PT
188 static public Color getSysColor(int id) {\r
189 Color col = Display.getCurrent().getSystemColor(id);\r
190 return new Color(col.getDevice(), col.getRGB());\r
191 }\r
192\r
3934297e
AM
193 /**\r
194 * Get the resulting color from a mix of two existing ones for the current\r
195 * display.\r
196 *\r
197 * @param col1\r
198 * The first color\r
199 * @param col2\r
200 * The second color\r
201 * @param w1\r
202 * The gamma level for color 1\r
203 * @param w2\r
204 * The gamma level for color 2\r
205 * @return The resulting color\r
206 */\r
fb5cad3d
PT
207 static public Color mixColors(Color col1, Color col2, int w1, int w2) {\r
208 return mixColors(Display.getCurrent(), col1, col2, w1, w2);\r
209 }\r
210\r
3934297e
AM
211 /**\r
212 * Draw text in a rectangle.\r
213 *\r
214 * @param gc\r
215 * The SWT GC object\r
216 * @param text\r
217 * The text to draw\r
218 * @param rect\r
219 * The rectangle object which is being drawn\r
220 * @param transp\r
221 * Should we transpose the color\r
222 * @return The X coordinate where we have written\r
223 */\r
fb5cad3d
PT
224 static public int drawText(GC gc, String text, Rectangle rect, boolean transp) {\r
225 Point size = gc.stringExtent(text);\r
226 gc.drawText(text, rect.x, rect.y, transp);\r
227 return size.x;\r
228 }\r
229\r
3934297e
AM
230 /**\r
231 * Draw text at a given location.\r
232 *\r
233 * @param gc\r
234 * The SWT GC object\r
235 * @param text\r
236 * The text to draw\r
237 * @param x\r
238 * The X coordinate of the starting point\r
239 * @param y\r
240 * the Y coordinate of the starting point\r
241 * @param transp\r
242 * Should we transpose the color\r
243 * @return The X coordinate where we have written\r
244 */\r
fb5cad3d
PT
245 static public int drawText(GC gc, String text, int x, int y, boolean transp) {\r
246 Point size = gc.stringExtent(text);\r
247 gc.drawText(text, x, y, transp);\r
248 return size.x;\r
249 }\r
250\r
251 /**\r
0d9a6d76 252 * Formats time in format: MM:SS:NNN\r
013a5f1c 253 *\r
fb5cad3d
PT
254 * @param time time\r
255 * @param format 0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn\r
256 * @param resolution the resolution\r
257 * @return the formatted time\r
258 */\r
259 static public String formatTime(long time, TimeFormat format, Resolution resolution) {\r
260 // if format is absolute (Calendar)\r
261 if (format == TimeFormat.ABSOLUTE) {\r
262 return formatTimeAbs(time, resolution);\r
263 }\r
264\r
265 StringBuffer str = new StringBuffer();\r
266 boolean neg = time < 0;\r
267 if (neg) {\r
268 time = -time;\r
269 str.append('-');\r
270 }\r
271\r
272 long sec = (long) (time * 1E-9);\r
273 // TODO: Expand to make it possible to select the minute, second, nanosecond format\r
274 //printing minutes is suppressed just sec and ns\r
275 // if (sec / 60 < 10)\r
276 // str.append('0');\r
277 // str.append(sec / 60);\r
278 // str.append(':');\r
279 // sec %= 60;\r
280 // if (sec < 10)\r
281 // str.append('0');\r
282 str.append(sec);\r
283 String ns = formatNs(time, resolution);\r
284 if (!ns.equals("")) { //$NON-NLS-1$\r
b83af2c3 285 str.append('.');\r
fb5cad3d
PT
286 str.append(ns);\r
287 }\r
288\r
289 return str.toString();\r
290 }\r
291\r
292 /**\r
293 * From input time in nanoseconds, convert to Date format YYYY-MM-dd\r
013a5f1c 294 *\r
fb5cad3d 295 * @param absTime\r
3934297e 296 * The source time, in ns\r
fb5cad3d
PT
297 * @return the formatted date\r
298 */\r
299 public static String formatDate(long absTime) {\r
300 String sdate = sdateformat.format(new Date((long) (absTime * 1E-6)));\r
301 return sdate;\r
302 }\r
303\r
304 /**\r
305 * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn\r
013a5f1c 306 *\r
fb5cad3d 307 * @param time\r
3934297e
AM
308 * The source time, in ns\r
309 * @param res\r
310 * The resolution to use\r
fb5cad3d
PT
311 * @return the formatted time\r
312 */\r
313 static public String formatTimeAbs(long time, Resolution res) {\r
314 StringBuffer str = new StringBuffer();\r
315\r
316 // format time from nanoseconds to calendar time HH:MM:SS\r
317 String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
b83af2c3
PT
318 str.append(stime);\r
319 str.append('.');\r
fb5cad3d
PT
320 // append the Milliseconds, MicroSeconds and NanoSeconds as specified in\r
321 // the Resolution\r
322 str.append(formatNs(time, res));\r
323 return str.toString();\r
324 }\r
325\r
326 /**\r
327 * Obtains the remainder fraction on unit Seconds of the entered value in\r
328 * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction\r
329 * seconds can be obtained by removing the last 9 digits: 1241207054 the\r
330 * fractional portion of seconds, expressed in ns is: 171080214\r
013a5f1c 331 *\r
fb5cad3d 332 * @param time\r
3934297e 333 * The source time in ns\r
fb5cad3d 334 * @param res\r
3934297e 335 * The Resolution to use\r
fb5cad3d
PT
336 * @return the formatted nanosec\r
337 */\r
338 public static String formatNs(long time, Resolution res) {\r
b83af2c3 339 StringBuffer str = new StringBuffer();\r
fb5cad3d
PT
340 boolean neg = time < 0;\r
341 if (neg) {\r
342 time = -time;\r
343 }\r
344\r
345 // The following approach could be used although performance\r
346 // decreases in half.\r
347 // String strVal = String.format("%09d", time);\r
348 // String tmp = strVal.substring(strVal.length() - 9);\r
349\r
fb5cad3d
PT
350 long ns = time;\r
351 ns %= 1000000000;\r
352 if (ns < 10) {\r
b83af2c3 353 str.append("00000000"); //$NON-NLS-1$\r
fb5cad3d 354 } else if (ns < 100) {\r
b83af2c3 355 str.append("0000000"); //$NON-NLS-1$\r
fb5cad3d 356 } else if (ns < 1000) {\r
b83af2c3 357 str.append("000000"); //$NON-NLS-1$\r
fb5cad3d 358 } else if (ns < 10000) {\r
b83af2c3 359 str.append("00000"); //$NON-NLS-1$\r
fb5cad3d 360 } else if (ns < 100000) {\r
b83af2c3 361 str.append("0000"); //$NON-NLS-1$\r
fb5cad3d 362 } else if (ns < 1000000) {\r
b83af2c3 363 str.append("000"); //$NON-NLS-1$\r
fb5cad3d 364 } else if (ns < 10000000) {\r
b83af2c3 365 str.append("00"); //$NON-NLS-1$\r
fb5cad3d 366 } else if (ns < 100000000) {\r
b83af2c3 367 str.append("0"); //$NON-NLS-1$\r
fb5cad3d 368 }\r
b83af2c3
PT
369 str.append(ns);\r
370\r
371 if (res == Resolution.MILLISEC) {\r
372 return str.substring(0, 3);\r
373 } else if (res == Resolution.MICROSEC) {\r
374 return str.substring(0, 6);\r
375 } else if (res == Resolution.NANOSEC) {\r
376 return str.substring(0, 9);\r
fb5cad3d 377 }\r
b83af2c3 378 return ""; //$NON-NLS-1$\r
fb5cad3d
PT
379 }\r
380\r
3934297e
AM
381 /**\r
382 * FIXME Currently does nothing.\r
383 *\r
384 * @param opt\r
385 * The option name\r
386 * @param def\r
387 * The option value\r
388 * @param min\r
389 * The minimal accepted value\r
390 * @param max\r
391 * The maximal accepted value\r
392 * @return The value that was read\r
393 */\r
fb5cad3d
PT
394 static public int loadIntOption(String opt, int def, int min, int max) {\r
395 // int val =\r
396 // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);\r
397 // if (0 == val)\r
398 // val = def;\r
399 // if (val < min)\r
400 // val = min;\r
401 // if (val > max)\r
402 // val = max;\r
403 return def;\r
404 }\r
405\r
3934297e
AM
406 /**\r
407 * FIXME currently does nothing\r
408 *\r
409 * @param opt\r
410 * The option name\r
411 * @param val\r
412 * The option value\r
413 */\r
fb5cad3d
PT
414 static public void saveIntOption(String opt, int val) {\r
415 // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val);\r
416 }\r
417\r
bc51e30c
PT
418 static ITimeEvent getFirstEvent(ITimeGraphEntry entry) {\r
419 if (null == entry || ! entry.hasTimeEvents()) {\r
fb5cad3d 420 return null;\r
bc51e30c
PT
421 }\r
422 Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();\r
fb5cad3d
PT
423 if (iterator != null && iterator.hasNext()) {\r
424 return iterator.next();\r
fb5cad3d 425 }\r
abbdd66a 426 return null;\r
fb5cad3d
PT
427 }\r
428\r
429 /**\r
430 * N means: <list> <li>-1: Previous Event</li> <li>0: Current Event</li> <li>\r
431 * 1: Next Event</li> <li>2: Previous Event when located in a non Event Area\r
432 * </list>\r
013a5f1c 433 *\r
bc51e30c 434 * @param entry\r
fb5cad3d
PT
435 * @param time\r
436 * @param n\r
437 * @return\r
438 */\r
bc51e30c
PT
439 static ITimeEvent findEvent(ITimeGraphEntry entry, long time, int n) {\r
440 if (null == entry || ! entry.hasTimeEvents()) {\r
a5823d5f 441 return null;\r
bc51e30c
PT
442 }\r
443 Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator();\r
fb5cad3d
PT
444 if (iterator == null) {\r
445 return null;\r
446 }\r
a5823d5f
ASL
447 ITimeEvent nextEvent = null;\r
448 ITimeEvent currEvent = null;\r
449 ITimeEvent prevEvent = null;\r
450\r
ce62370f 451 while (iterator.hasNext()) {\r
abbdd66a 452 nextEvent = iterator.next();\r
a5823d5f 453 long nextStartTime = nextEvent.getTime();\r
fb5cad3d 454\r
a5823d5f
ASL
455 if (nextStartTime > time) {\r
456 break;\r
457 }\r
fb5cad3d 458\r
a5823d5f
ASL
459 if (currEvent == null || currEvent.getTime() != nextStartTime) {\r
460 prevEvent = currEvent;\r
461 currEvent = nextEvent;\r
462 }\r
463 }\r
fb5cad3d 464\r
a5823d5f
ASL
465 if (n == -1) { //previous\r
466 if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
467 return prevEvent;\r
a5823d5f 468 }\r
abbdd66a 469 return currEvent;\r
a5823d5f
ASL
470 } else if (n == 0) { //current\r
471 if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
472 return currEvent;\r
a5823d5f 473 }\r
abbdd66a 474 return null;\r
a5823d5f 475 } else if (n == 1) { //next\r
6a08b49e
PT
476 if (nextEvent != null && nextEvent.getTime() > time) {\r
477 return nextEvent;\r
478 }\r
479 return null;\r
a5823d5f
ASL
480 } else if (n == 2) { //current or previous when in empty space\r
481 return currEvent;\r
482 }\r
fb5cad3d 483\r
a5823d5f
ASL
484 return null;\r
485 }\r
b0d3496e 486\r
3934297e
AM
487 /**\r
488 * Pretty-print a method signature.\r
489 *\r
490 * @param sig\r
491 * The original signature\r
492 * @return The pretty signature\r
493 */\r
fb5cad3d
PT
494 static public String fixMethodSignature(String sig) {\r
495 int pos = sig.indexOf('(');\r
496 if (pos >= 0) {\r
497 String ret = sig.substring(0, pos);\r
498 sig = sig.substring(pos);\r
499 sig = sig + " " + ret; //$NON-NLS-1$\r
500 }\r
501 return sig;\r
502 }\r
503\r
3934297e
AM
504 /**\r
505 * Restore an original method signature from a pretty-printed one.\r
506 *\r
507 * @param sig\r
508 * The pretty-printed signature\r
509 * @return The original method signature\r
510 */\r
fb5cad3d
PT
511 static public String restoreMethodSignature(String sig) {\r
512 String ret = ""; //$NON-NLS-1$\r
513 int pos = sig.indexOf('(');\r
514 if (pos >= 0) {\r
515 ret = sig.substring(0, pos);\r
516 sig = sig.substring(pos + 1);\r
517 }\r
518 pos = sig.indexOf(')');\r
519 if (pos >= 0) {\r
520 sig = sig.substring(0, pos);\r
521 }\r
522 String args[] = sig.split(","); //$NON-NLS-1$\r
5a5c2fc7 523 StringBuffer result = new StringBuffer("("); //$NON-NLS-1$\r
fb5cad3d
PT
524 for (int i = 0; i < args.length; i++) {\r
525 String arg = args[i].trim();\r
013a5f1c 526 if (arg.length() == 0 && args.length == 1) {\r
fb5cad3d 527 break;\r
013a5f1c 528 }\r
fb5cad3d
PT
529 result.append(getTypeSignature(arg));\r
530 }\r
531 result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$\r
532 return result.toString();\r
533 }\r
534\r
3934297e
AM
535 /**\r
536 * Get the mangled type information from an array of types.\r
537 *\r
538 * @param type\r
539 * The types to convert. See method implementation for what it\r
540 * expects.\r
541 * @return The mangled string of types\r
542 */\r
fb5cad3d
PT
543 static public String getTypeSignature(String type) {\r
544 int dim = 0;\r
545 for (int j = 0; j < type.length(); j++) {\r
013a5f1c 546 if (type.charAt(j) == '[') {\r
fb5cad3d 547 dim++;\r
013a5f1c 548 }\r
fb5cad3d
PT
549 }\r
550 int pos = type.indexOf('[');\r
013a5f1c 551 if (pos >= 0) {\r
fb5cad3d 552 type = type.substring(0, pos);\r
013a5f1c 553 }\r
fb5cad3d
PT
554 StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$\r
555 for (int j = 0; j < dim; j++)\r
013a5f1c 556 {\r
fb5cad3d 557 sig.append("["); //$NON-NLS-1$\r
013a5f1c 558 }\r
abbdd66a
AM
559 if (type.equals("boolean")) { //$NON-NLS-1$\r
560 sig.append('Z');\r
561 } else if (type.equals("byte")) { //$NON-NLS-1$\r
562 sig.append('B');\r
563 } else if (type.equals("char")) { //$NON-NLS-1$\r
564 sig.append('C');\r
565 } else if (type.equals("short")) { //$NON-NLS-1$\r
566 sig.append('S');\r
567 } else if (type.equals("int")) { //$NON-NLS-1$\r
568 sig.append('I');\r
569 } else if (type.equals("long")) { //$NON-NLS-1$\r
570 sig.append('J');\r
571 } else if (type.equals("float")) { //$NON-NLS-1$\r
572 sig.append('F');\r
573 } else if (type.equals("double")) { //$NON-NLS-1$\r
574 sig.append('D');\r
575 } else if (type.equals("void")) { //$NON-NLS-1$\r
576 sig.append('V');\r
013a5f1c
AM
577 }\r
578 else {\r
abbdd66a 579 sig.append('L').append(type.replace('.', '/')).append(';');\r
013a5f1c 580 }\r
fb5cad3d
PT
581 return sig.toString();\r
582 }\r
583\r
3934297e
AM
584 /**\r
585 * Compare two doubles together.\r
586 *\r
587 * @param d1\r
588 * First double\r
589 * @param d2\r
590 * Second double\r
591 * @return 1 if they are different, and 0 if they are *exactly* the same.\r
592 * Because of the way doubles are stored, it's possible for the\r
593 * same number obtained in two different ways to actually look\r
594 * different.\r
595 */\r
fb5cad3d 596 static public int compare(double d1, double d2) {\r
013a5f1c 597 if (d1 > d2) {\r
fb5cad3d 598 return 1;\r
013a5f1c
AM
599 }\r
600 if (d1 < d2) {\r
fb5cad3d 601 return 1;\r
013a5f1c 602 }\r
fb5cad3d
PT
603 return 0;\r
604 }\r
605\r
3934297e
AM
606 /**\r
607 * Compare two character strings alphabetically. This is simply a wrapper\r
608 * around String.compareToIgnoreCase but that will handle cases where\r
609 * strings can be null\r
610 *\r
611 * @param s1\r
612 * The first string\r
613 * @param s2\r
614 * The second string\r
615 * @return A number below, equal, or greater than zero if the first string\r
616 * is smaller, equal, or bigger (alphabetically) than the second\r
617 * one.\r
618 */\r
fb5cad3d 619 static public int compare(String s1, String s2) {\r
013a5f1c 620 if (s1 != null && s2 != null) {\r
fb5cad3d 621 return s1.compareToIgnoreCase(s2);\r
013a5f1c
AM
622 }\r
623 if (s1 != null) {\r
fb5cad3d 624 return 1;\r
013a5f1c
AM
625 }\r
626 if (s2 != null) {\r
fb5cad3d 627 return -1;\r
013a5f1c 628 }\r
fb5cad3d
PT
629 return 0;\r
630 }\r
b0d3496e 631}\r
This page took 0.07511 seconds and 5 git commands to generate.