ctf: java 8 compliance of javadoc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / Utils.java
CommitLineData
866e5b51 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
866e5b51
FC
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
13package org.eclipse.linuxtools.ctf.core.trace;
14
15import java.util.UUID;
16
17/**
866e5b51 18 * Various utilities.
0594c61c 19 *
d37aaa7f
FC
20 * @version 1.0
21 * @author Matthew Khouzam
22 * @author Simon Marchi
866e5b51
FC
23 */
24public class Utils {
25
0594c61c
AM
26 private Utils() {}
27
866e5b51
FC
28 // ------------------------------------------------------------------------
29 // Constants
30 // ------------------------------------------------------------------------
31
32 /**
9ac2eb62 33 * CTF magic number. (sort of looks like CTF CTF CT)
866e5b51 34 */
0594c61c 35 public static final int CTF_MAGIC = 0xC1FC1FC1;
866e5b51
FC
36
37 /**
9ac2eb62 38 * TSDL magic number. (sort of looks like TSDL LSDT)
866e5b51 39 */
0594c61c 40 public static final int TSDL_MAGIC = 0x75D11D57;
866e5b51
FC
41
42 /**
43 * TSDL magic number length in bytes.
44 */
0594c61c 45 public static final int TSDL_MAGIC_LEN = 4;
866e5b51
FC
46
47 /**
48 * Directory separator on the current platform.
49 */
0594c61c 50 public static final String SEPARATOR = System.getProperty("file.separator"); //$NON-NLS-1$
866e5b51
FC
51
52 /**
53 * Length in bytes of a UUID value.
54 */
0594c61c 55 public static final int UUID_LEN = 16;
866e5b51
FC
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 /**
1c8799d5 62 * Performs an unsigned long comparison on two unsigned long numbers.
866e5b51 63 *
ab04fc6b 64 * <strong> As Java does not support unsigned types and arithmetic, parameters
1c8799d5 65 * are received encoded as a signed long (two-complement) but the
ab04fc6b 66 * operation is an unsigned comparator.</strong>
1c8799d5
EB
67 *
68 * @param left
69 * Left operand of the comparator.
70 * @param right
71 * Right operand of the comparator.
ab04fc6b 72 * @return -1 if left &lt; right, 1 if left &gt; right, 0 if left == right.
866e5b51 73 */
1c8799d5
EB
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 */
f5166b60
AM
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;
866e5b51
FC
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.044228 seconds and 5 git commands to generate.