More javadoc updates
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / Utils.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.ctf.core.trace;
14
15 import java.util.UUID;
16
17 /**
18 * Various utilities.
19 *
20 * @version 1.0
21 * @author Matthew Khouzam
22 * @author Simon Marchi
23 */
24 public class Utils {
25
26 // ------------------------------------------------------------------------
27 // Constants
28 // ------------------------------------------------------------------------
29
30 /**
31 * CTF magic number. (sort of looks like CTF CTF CT)
32 */
33 public final static int CTF_MAGIC = 0xC1FC1FC1;
34
35 /**
36 * TSDL magic number. (sort of looks like TSDL LSDT)
37 */
38 public final static int TSDL_MAGIC = 0x75D11D57;
39
40 /**
41 * TSDL magic number length in bytes.
42 */
43 public final static int TSDL_MAGIC_LEN = 4;
44
45 /**
46 * Directory separator on the current platform.
47 */
48 public final static String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$
49
50 /**
51 * Length in bytes of a UUID value.
52 */
53 public final static int UUID_LEN = 16;
54
55 // ------------------------------------------------------------------------
56 // Operations
57 // ------------------------------------------------------------------------
58
59 /**
60 * Unsigned long comparison.
61 *
62 * @param a
63 * First operand.
64 * @param b
65 * Second operand.
66 * @return -1 if a < b, 1 if a > b, 0 if a == b.
67 */
68 public static int unsignedCompare(long a, long b) {
69 boolean aLeftBit = (a & (1 << (Long.SIZE - 1))) != 0;
70 boolean bLeftBit = (b & (1 << (Long.SIZE - 1))) != 0;
71
72 if (aLeftBit && !bLeftBit) {
73 return 1;
74 } else if (!aLeftBit && bLeftBit) {
75 return -1;
76 } else {
77 if (a < b) {
78 return -1;
79 } else if (a > b) {
80 return 1;
81 } else {
82 return 0;
83 }
84 }
85 }
86
87 /**
88 * Creates a UUID object from an array of 16 bytes.
89 *
90 * @param bytes
91 * Array of 16 bytes.
92 * @return A UUID object.
93 */
94 public static UUID makeUUID(byte bytes[]) {
95 long high = 0;
96 long low = 0;
97
98 assert (bytes.length == Utils.UUID_LEN);
99
100 for (int i = 0; i < 8; i++) {
101 low = (low << 8) | (bytes[i + 8] & 0xFF);
102 high = (high << 8) | (bytes[i] & 0xFF);
103 }
104
105 UUID uuid = new UUID(high, low);
106
107 return uuid;
108 }
109
110 }
This page took 0.045205 seconds and 5 git commands to generate.