ctf: java 8 compliance of javadoc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / Utils.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 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 private Utils() {}
27
28 // ------------------------------------------------------------------------
29 // Constants
30 // ------------------------------------------------------------------------
31
32 /**
33 * CTF magic number. (sort of looks like CTF CTF CT)
34 */
35 public static final int CTF_MAGIC = 0xC1FC1FC1;
36
37 /**
38 * TSDL magic number. (sort of looks like TSDL LSDT)
39 */
40 public static final int TSDL_MAGIC = 0x75D11D57;
41
42 /**
43 * TSDL magic number length in bytes.
44 */
45 public static final int TSDL_MAGIC_LEN = 4;
46
47 /**
48 * Directory separator on the current platform.
49 */
50 public static final String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$
51
52 /**
53 * Length in bytes of a UUID value.
54 */
55 public static final int UUID_LEN = 16;
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 /**
62 * Performs an unsigned long comparison on two unsigned long numbers.
63 *
64 * <strong> As Java does not support unsigned types and arithmetic, parameters
65 * are received encoded as a signed long (two-complement) but the
66 * operation is an unsigned comparator.</strong>
67 *
68 * @param left
69 * Left operand of the comparator.
70 * @param right
71 * Right operand of the comparator.
72 * @return -1 if left &lt; right, 1 if left &gt; right, 0 if left == right.
73 */
74 public static int unsignedCompare(long left, long right) {
75 /*
76 * This method assumes that the arithmetic overflow on signed
77 * integer wrap on a circular domain (modulo arithmetic in
78 * two-complement), which is the defined behavior in Java.
79 *
80 * This idea is to rotate the domain by the length of the negative
81 * space, and then use the signed operator.
82 */
83 final long a = left + Long.MIN_VALUE;
84 final long b = right + Long.MIN_VALUE;
85 if (a < b) {
86 return -1;
87 } else if (a > b) {
88 return 1;
89 }
90 return 0;
91 }
92
93 /**
94 * Creates a UUID object from an array of 16 bytes.
95 *
96 * @param bytes
97 * Array of 16 bytes.
98 * @return A UUID object.
99 */
100 public static UUID makeUUID(byte bytes[]) {
101 long high = 0;
102 long low = 0;
103
104 assert (bytes.length == Utils.UUID_LEN);
105
106 for (int i = 0; i < 8; i++) {
107 low = (low << 8) | (bytes[i + 8] & 0xFF);
108 high = (high << 8) | (bytes[i] & 0xFF);
109 }
110
111 UUID uuid = new UUID(high, low);
112
113 return uuid;
114 }
115
116 }
This page took 0.035328 seconds and 6 git commands to generate.