Class NamedIntegerBitmask<T extends NamedIntegerBitmask<T>>

java.lang.Object
org.newsclub.net.unix.NamedIntegerBitmask<T>
Type Parameters:
T - The subclass's type itself.
All Implemented Interfaces:
Serializable

@NonNullByDefault public abstract class NamedIntegerBitmask<T extends NamedIntegerBitmask<T>> extends Object implements Serializable
Describes a 32-bit bitmask that supports named flags.
Author:
Christian Kohlschütter
See Also:
  • Constructor Details

    • NamedIntegerBitmask

      protected NamedIntegerBitmask(@Nullable String name, int flags)
      Creates a new named flag.
      Parameters:
      name - The name of the flag / flag set.
      flags - The flag value.
  • Method Details

    • name

      public final String name()
      Returns the name of the flag / flag set.
      Returns:
      The name.
    • value

      public final int value()
      Returns the value of the flag / flag set.
      Returns:
      The value.
    • hasFlag

      public final boolean hasFlag(T flag)
      Checks if the given flag is set.
      Parameters:
      flag - The flag to check.
      Returns:
      true iff set.
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • combineWith

      protected final T combineWith(T[] allFlags, T flagsNone, NamedIntegerBitmask.Constructor<@NonNull T> constr, T other)
      Combines two flags / flag sets (use this to implement combineWith(NamedIntegerBitmask)).
      Parameters:
      allFlags - The array of all defined flags, expected "none".
      flagsNone - The "none" flag set.
      constr - The constructor.
      other - The other flag / flag set to merge.
      Returns:
      An instance combining both.
    • combineWith

      public abstract T combineWith(T other)
      Combines two flags / flag sets.
      Parameters:
      other - The other flag / flag set.
      Returns:
      An instance combining both.
    • resolve

      protected static final <T extends NamedIntegerBitmask<T>> T resolve(T[] allFlags, T flagsNone, NamedIntegerBitmask.Constructor<T> constr, int v)
      Returns a NamedIntegerBitmask instance given a flag value.
      Type Parameters:
      T - The subclass's type itself.
      Parameters:
      allFlags - The array of all defined flags, expected "none".
      flagsNone - The "none" flag set.
      constr - The constructor.
      v - The flag value.
      Returns:
      An instance representing the flag value.
    • resolve

      protected static final <T extends NamedIntegerBitmask<T>> T resolve(T[] allFlags, T flagsNone, NamedIntegerBitmask.Constructor<T> constr, @NonNull T[] setFlags)
      Returns a NamedIntegerBitmask instance given a series of flags.
      Type Parameters:
      T - The subclass's type itself.
      Parameters:
      allFlags - The array of all defined flags, expected "none".
      flagsNone - The "none" flag set.
      constr - The constructor.
      setFlags - The flags to set, potentially empty.
      Returns:
      An instance representing the flag values.