Package gc.garcol.libcore
Class RingBufferUtil
java.lang.Object
gc.garcol.libcore.RingBufferUtil
Utility class for operations related to ring buffers.
Provides methods for checking message lengths, comparing circles, and manipulating positions.
- Since:
- 2024
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckMsgLength(int length, int maxMsgLength) Checks if the message length is within the valid range.static booleanflip(long position) Extracts the flip bit from a position.static intoffset(long position) Extracts the offset from a position.static longposition(int offset, boolean flip) Combines an offset and a flip bit into a position.static booleansameCircle(boolean firstFlip, boolean secondFlip) Checks if two positions are in the same circle.
-
Method Details
-
checkMsgLength
public static void checkMsgLength(int length, int maxMsgLength) Checks if the message length is within the valid range.- Parameters:
length- the length of the messagemaxMsgLength- the maximum allowed message length- Throws:
IllegalArgumentException- if the message length is invalid
-
sameCircle
public static boolean sameCircle(boolean firstFlip, boolean secondFlip) Checks if two positions are in the same circle.- Parameters:
firstFlip- the first flipsecondFlip- the second flip- Returns:
- true if both flips are in the same circle, false otherwise
-
offset
public static int offset(long position) Extracts the offset from a position.- Parameters:
position- the position- Returns:
- the offset part of the position
-
flip
public static boolean flip(long position) Extracts the flip bit from a position.- Parameters:
position- the position- Returns:
- true if the flip bit is set, false otherwise
-
position
public static long position(int offset, boolean flip) Combines an offset and a flip bit into a position.- Parameters:
offset- the offsetflip- the flip bit- Returns:
- the combined position
-