com.hazelcast.client.impl.protocol.util
Class BitUtil

java.lang.Object
  extended by com.hazelcast.client.impl.protocol.util.BitUtil

public final class BitUtil
extends Object

Miscellaneous useful functions for dealing with low level bits and bytes.


Field Summary
static short BYTE_MASK
          byte mask
static int CACHE_LINE_LENGTH
          Length of the data blocks used by the CPU cache sub-system in bytes.
static int INT_MASK
          Int mask
static long LONG_MASK
          Long mask
static int SIZE_OF_BOOLEAN
          Size of a boolean in bytes
static int SIZE_OF_BYTE
          Size of a byte in bytes
static int SIZE_OF_CHAR
          Size of a char in bytes
static int SIZE_OF_DOUBLE
          Size of a double in bytes
static int SIZE_OF_FLOAT
          Size of a a float in bytes
static int SIZE_OF_INT
          Size of an int in bytes
static int SIZE_OF_LONG
          Size of a long in bytes
static int SIZE_OF_SHORT
          Size of a short in bytes
static Charset UTF8_CHARSET
          UTF-8 charset
 
Method Summary
static int align(int value, int alignment)
          Align a value to the next multiple up of an alignment number.
static int findNextPositivePowerOfTwo(int value)
          Fast method of finding the next power of 2 greater than or equal to the supplied value.
static boolean isEven(int value)
          Checks to see if a value is an even number.
static boolean isPowerOfTwo(int value)
          Checks to see if a value is a positive power of two.
static int next(int current, int max)
          Cycles the indices of an array one at a time in a forward fashion.
static int previous(int current, int max)
          Cycles the indices of an array one at a time in a backwards fashion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_OF_BYTE

public static final int SIZE_OF_BYTE
Size of a byte in bytes

See Also:
Constant Field Values

SIZE_OF_BOOLEAN

public static final int SIZE_OF_BOOLEAN
Size of a boolean in bytes

See Also:
Constant Field Values

SIZE_OF_CHAR

public static final int SIZE_OF_CHAR
Size of a char in bytes

See Also:
Constant Field Values

SIZE_OF_SHORT

public static final int SIZE_OF_SHORT
Size of a short in bytes

See Also:
Constant Field Values

SIZE_OF_INT

public static final int SIZE_OF_INT
Size of an int in bytes

See Also:
Constant Field Values

SIZE_OF_FLOAT

public static final int SIZE_OF_FLOAT
Size of a a float in bytes

See Also:
Constant Field Values

SIZE_OF_LONG

public static final int SIZE_OF_LONG
Size of a long in bytes

See Also:
Constant Field Values

SIZE_OF_DOUBLE

public static final int SIZE_OF_DOUBLE
Size of a double in bytes

See Also:
Constant Field Values

CACHE_LINE_LENGTH

public static final int CACHE_LINE_LENGTH
Length of the data blocks used by the CPU cache sub-system in bytes.

See Also:
Constant Field Values

LONG_MASK

public static final long LONG_MASK
Long mask

See Also:
Constant Field Values

INT_MASK

public static final int INT_MASK
Int mask

See Also:
Constant Field Values

BYTE_MASK

public static final short BYTE_MASK
byte mask

See Also:
Constant Field Values

UTF8_CHARSET

public static final Charset UTF8_CHARSET
UTF-8 charset

Method Detail

findNextPositivePowerOfTwo

public static int findNextPositivePowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.

If the value is <= 0 then 1 will be returned.

This method is not suitable for Integer.MIN_VALUE or numbers greater than 2^30.

Parameters:
value - The value from which to search for the next power of 2.
Returns:
The next power of 2 or the value itself if it is a power of 2.

align

public static int align(int value,
                        int alignment)
Align a value to the next multiple up of an alignment number. If the value equals a multiple of the alignment number, then the value is returned unchanged.

This method executes without branching.

Parameters:
value - The value to be aligned to the next multiple up of the alignment number.
alignment - The alignment number to be used.
Returns:
the value aligned to the next multiple up of the alignment number.

isEven

public static boolean isEven(int value)
Checks to see if a value is an even number.

Parameters:
value - The value to check.
Returns:
true if the value is an even number, false otherwise.

isPowerOfTwo

public static boolean isPowerOfTwo(int value)
Checks to see if a value is a positive power of two.

Parameters:
value - The value to check.
Returns:
true if the number is a positive power of two, false otherwise.

next

public static int next(int current,
                       int max)
Cycles the indices of an array one at a time in a forward fashion.

Parameters:
current - The index array value to be incremented.
max - The maximum value for the index cycle.
Returns:
The next value, or zero if max is reached.

previous

public static int previous(int current,
                           int max)
Cycles the indices of an array one at a time in a backwards fashion.

Parameters:
current - The index array value to be decremented.
max - The maximum value for the index cycle.
Returns:
The next value, or max - 1 if current is zero.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.