Class FlagCalculator

java.lang.Object
me.tayebyassine.homestead.flags.FlagCalculator

public final class FlagCalculator extends Object
Utility class for bitwise flag operations.

Provides methods for combining, removing, and checking bitwise flags. Includes type-safe overloads for PlayerFlag, WorldFlag, and ControlFlag enums to prevent mixing different flag types.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    addFlag(long... flags)
    Combines multiple bitwise flags into a single value.
    static long
    addFlag(ControlFlag... flags)
    Combines multiple control flags into a single bitmask.
    static long
    addFlag(PlayerFlag... flags)
    Combines multiple player flags into a single bitmask.
    static long
    addFlag(WorldFlag... flags)
    Combines multiple world flags into a single bitmask.
    static boolean
    areAllFlagsSet(long flags, long... requiredFlags)
    Checks if all specified flags are set in a combined bitmask.
    static boolean
    areAllFlagsSet(long flags, ControlFlag... requiredFlags)
    Checks if all specified control flags are set.
    static boolean
    areAllFlagsSet(long flags, PlayerFlag... requiredFlags)
    Checks if all specified player flags are set.
    static boolean
    areAllFlagsSet(long flags, WorldFlag... requiredFlags)
    Checks if all specified world flags are set.
    static int
    countFlagsSet(long flags, long... flagsToCheck)
    Counts how many of the specified flags are set in a combined bitmask.
    getSetControlFlags(long flags)
    Returns a list of ControlFlag enums that are set in the given bitmask.
    getSetPlayerFlags(long flags)
    Returns a list of PlayerFlag enums that are set in the given bitmask.
    static List<WorldFlag>
    getSetWorldFlags(long flags)
    Returns a list of WorldFlag enums that are set in the given bitmask.
    Returns a list of ControlFlag enums that are NOT set in the given bitmask.
    getUnsetPlayerFlags(long flags)
    Returns a list of PlayerFlag enums that are NOT set in the given bitmask.
    static List<WorldFlag>
    getUnsetWorldFlags(long flags)
    Returns a list of WorldFlag enums that are NOT set in the given bitmask.
    static boolean
    isAnyFlagSet(long flags, long... flagsToCheck)
    Checks if any of the specified flags are set in a combined bitmask.
    static boolean
    isAnyFlagSet(long flags, ControlFlag... flagsToCheck)
    Checks if any of the specified control flags are set.
    static boolean
    isAnyFlagSet(long flags, PlayerFlag... flagsToCheck)
    Checks if any of the specified player flags are set.
    static boolean
    isAnyFlagSet(long flags, WorldFlag... flagsToCheck)
    Checks if any of the specified world flags are set.
    static boolean
    isFlagSet(long flags, long flag)
    Checks if a specific flag is set in a combined bitmask.
    static boolean
    isFlagSet(long flags, ControlFlag flag)
    Checks if a control flag is set in a combined bitmask.
    static boolean
    isFlagSet(long flags, PlayerFlag flag)
    Checks if a player flag is set in a combined bitmask.
    static boolean
    isFlagSet(long flags, WorldFlag flag)
    Checks if a world flag is set in a combined bitmask.
    static long
    removeFlag(long flags, long flag)
    Removes a flag from a combined bitmask.
    static long
    removeFlag(long flags, ControlFlag flag)
    Removes a control flag from a combined bitmask.
    static long
    removeFlag(long flags, PlayerFlag flag)
    Removes a player flag from a combined bitmask.
    static long
    removeFlag(long flags, WorldFlag flag)
    Removes a world flag from a combined bitmask.
    static long
    removeFlags(long flags, long... flagsToRemove)
    Returns a new bitmask with the specified flags removed.
    static long
    Converts an array of ControlFlags to a combined bitmask.
    static long
    Converts an array of PlayerFlags to a combined bitmask.
    static long
    toBitmask(WorldFlag... flags)
    Converts an array of WorldFlags to a combined bitmask.
    static long
    toggleFlag(long flags, long flag)
    Toggles a flag in a combined bitmask (adds if not present, removes if present).
    static long
    toggleFlag(long flags, ControlFlag flag)
    Toggles a control flag in a combined bitmask.
    static long
    toggleFlag(long flags, PlayerFlag flag)
    Toggles a player flag in a combined bitmask.
    static long
    toggleFlag(long flags, WorldFlag flag)
    Toggles a world flag in a combined bitmask.

    Methods inherited from class Object

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

    • addFlag

      public static long addFlag(long... flags)
      Combines multiple bitwise flags into a single value.

      Do not mix PlayerFlag, WorldFlag, and ControlFlag in the same operation as they use overlapping bit positions.

      Parameters:
      flags - the flags to combine
      Returns:
      the combined bitmask
    • removeFlag

      public static long removeFlag(long flags, long flag)
      Removes a flag from a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the flag to remove
      Returns:
      the bitmask with the flag removed
    • isFlagSet

      public static boolean isFlagSet(long flags, long flag)
      Checks if a specific flag is set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the flag to check
      Returns:
      true if the flag is set, false otherwise
    • areAllFlagsSet

      public static boolean areAllFlagsSet(long flags, long... requiredFlags)
      Checks if all specified flags are set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      requiredFlags - the flags that must all be present
      Returns:
      true if all required flags are set
    • isAnyFlagSet

      public static boolean isAnyFlagSet(long flags, long... flagsToCheck)
      Checks if any of the specified flags are set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flagsToCheck - the flags to check for
      Returns:
      true if at least one flag is set
    • countFlagsSet

      public static int countFlagsSet(long flags, long... flagsToCheck)
      Counts how many of the specified flags are set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flagsToCheck - the flags to count
      Returns:
      the number of flags that are set
    • toggleFlag

      public static long toggleFlag(long flags, long flag)
      Toggles a flag in a combined bitmask (adds if not present, removes if present).
      Parameters:
      flags - the combined bitmask
      flag - the flag to toggle
      Returns:
      the new bitmask with the flag toggled
    • removeFlags

      public static long removeFlags(long flags, long... flagsToRemove)
      Returns a new bitmask with the specified flags removed.
      Parameters:
      flags - the combined bitmask
      flagsToRemove - the flags to remove
      Returns:
      the bitmask with flags removed
    • addFlag

      public static long addFlag(PlayerFlag... flags)
      Combines multiple player flags into a single bitmask.
      Parameters:
      flags - the player flags to combine
      Returns:
      the combined bitmask
    • removeFlag

      public static long removeFlag(long flags, PlayerFlag flag)
      Removes a player flag from a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the player flag to remove
      Returns:
      the bitmask with the flag removed
    • isFlagSet

      public static boolean isFlagSet(long flags, PlayerFlag flag)
      Checks if a player flag is set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the player flag to check
      Returns:
      true if the flag is set
    • areAllFlagsSet

      public static boolean areAllFlagsSet(long flags, PlayerFlag... requiredFlags)
      Checks if all specified player flags are set.
      Parameters:
      flags - the combined bitmask
      requiredFlags - the player flags that must all be present
      Returns:
      true if all are set
    • isAnyFlagSet

      public static boolean isAnyFlagSet(long flags, PlayerFlag... flagsToCheck)
      Checks if any of the specified player flags are set.
      Parameters:
      flags - the combined bitmask
      flagsToCheck - the player flags to check
      Returns:
      true if at least one is set
    • toggleFlag

      public static long toggleFlag(long flags, PlayerFlag flag)
      Toggles a player flag in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the player flag to toggle
      Returns:
      the new bitmask
    • addFlag

      public static long addFlag(WorldFlag... flags)
      Combines multiple world flags into a single bitmask.
      Parameters:
      flags - the world flags to combine
      Returns:
      the combined bitmask
    • removeFlag

      public static long removeFlag(long flags, WorldFlag flag)
      Removes a world flag from a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the world flag to remove
      Returns:
      the bitmask with the flag removed
    • isFlagSet

      public static boolean isFlagSet(long flags, WorldFlag flag)
      Checks if a world flag is set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the world flag to check
      Returns:
      true if the flag is set
    • areAllFlagsSet

      public static boolean areAllFlagsSet(long flags, WorldFlag... requiredFlags)
      Checks if all specified world flags are set.
      Parameters:
      flags - the combined bitmask
      requiredFlags - the world flags that must all be present
      Returns:
      true if all are set
    • isAnyFlagSet

      public static boolean isAnyFlagSet(long flags, WorldFlag... flagsToCheck)
      Checks if any of the specified world flags are set.
      Parameters:
      flags - the combined bitmask
      flagsToCheck - the world flags to check
      Returns:
      true if at least one is set
    • toggleFlag

      public static long toggleFlag(long flags, WorldFlag flag)
      Toggles a world flag in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the world flag to toggle
      Returns:
      the new bitmask
    • addFlag

      public static long addFlag(ControlFlag... flags)
      Combines multiple control flags into a single bitmask.
      Parameters:
      flags - the control flags to combine
      Returns:
      the combined bitmask
    • removeFlag

      public static long removeFlag(long flags, ControlFlag flag)
      Removes a control flag from a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the control flag to remove
      Returns:
      the bitmask with the flag removed
    • isFlagSet

      public static boolean isFlagSet(long flags, ControlFlag flag)
      Checks if a control flag is set in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the control flag to check
      Returns:
      true if the flag is set
    • areAllFlagsSet

      public static boolean areAllFlagsSet(long flags, ControlFlag... requiredFlags)
      Checks if all specified control flags are set.
      Parameters:
      flags - the combined bitmask
      requiredFlags - the control flags that must all be present
      Returns:
      true if all are set
    • isAnyFlagSet

      public static boolean isAnyFlagSet(long flags, ControlFlag... flagsToCheck)
      Checks if any of the specified control flags are set.
      Parameters:
      flags - the combined bitmask
      flagsToCheck - the control flags to check
      Returns:
      true if at least one is set
    • toggleFlag

      public static long toggleFlag(long flags, ControlFlag flag)
      Toggles a control flag in a combined bitmask.
      Parameters:
      flags - the combined bitmask
      flag - the control flag to toggle
      Returns:
      the new bitmask
    • toBitmask

      public static long toBitmask(PlayerFlag... flags)
      Converts an array of PlayerFlags to a combined bitmask.
      Parameters:
      flags - the player flags
      Returns:
      the combined bitmask
    • toBitmask

      public static long toBitmask(WorldFlag... flags)
      Converts an array of WorldFlags to a combined bitmask.
      Parameters:
      flags - the world flags
      Returns:
      the combined bitmask
    • toBitmask

      public static long toBitmask(ControlFlag... flags)
      Converts an array of ControlFlags to a combined bitmask.
      Parameters:
      flags - the control flags
      Returns:
      the combined bitmask
    • getSetPlayerFlags

      public static List<PlayerFlag> getSetPlayerFlags(long flags)
      Returns a list of PlayerFlag enums that are set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of set PlayerFlag enums
    • getSetWorldFlags

      public static List<WorldFlag> getSetWorldFlags(long flags)
      Returns a list of WorldFlag enums that are set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of set WorldFlag enums
    • getSetControlFlags

      public static List<ControlFlag> getSetControlFlags(long flags)
      Returns a list of ControlFlag enums that are set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of set ControlFlag enums
    • getUnsetPlayerFlags

      public static List<PlayerFlag> getUnsetPlayerFlags(long flags)
      Returns a list of PlayerFlag enums that are NOT set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of unset PlayerFlag enums
    • getUnsetWorldFlags

      public static List<WorldFlag> getUnsetWorldFlags(long flags)
      Returns a list of WorldFlag enums that are NOT set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of unset WorldFlag enums
    • getUnsetControlFlags

      public static List<ControlFlag> getUnsetControlFlags(long flags)
      Returns a list of ControlFlag enums that are NOT set in the given bitmask.
      Parameters:
      flags - the combined bitmask
      Returns:
      list of unset ControlFlag enums