Class RingBufferUtil

java.lang.Object
gc.garcol.libcore.RingBufferUtil

public class RingBufferUtil extends Object
Utility class for operations related to ring buffers. Provides methods for checking message lengths, comparing circles, and manipulating positions.
Since:
2024
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    static void
    checkMsgLength(int length, int maxMsgLength)
    Checks if the message length is within the valid range.
    static boolean
    flip(long position)
    Extracts the flip bit from a position.
    static int
    offset(long position)
    Extracts the offset from a position.
    static long
    position(int offset, boolean flip)
    Combines an offset and a flip bit into a position.
    static boolean
    sameCircle(boolean firstFlip, boolean secondFlip)
    Checks if two positions are in the same circle.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details Link icon

    • checkMsgLength Link icon

      public static void checkMsgLength(int length, int maxMsgLength)
      Checks if the message length is within the valid range.
      Parameters:
      length - the length of the message
      maxMsgLength - the maximum allowed message length
      Throws:
      IllegalArgumentException - if the message length is invalid
    • sameCircle Link icon

      public static boolean sameCircle(boolean firstFlip, boolean secondFlip)
      Checks if two positions are in the same circle.
      Parameters:
      firstFlip - the first flip
      secondFlip - the second flip
      Returns:
      true if both flips are in the same circle, false otherwise
    • offset Link icon

      public static int offset(long position)
      Extracts the offset from a position.
      Parameters:
      position - the position
      Returns:
      the offset part of the position
    • flip Link icon

      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 Link icon

      public static long position(int offset, boolean flip)
      Combines an offset and a flip bit into a position.
      Parameters:
      offset - the offset
      flip - the flip bit
      Returns:
      the combined position