Class Flags

  • All Implemented Interfaces:
    java.io.Serializable

    public class Flags
    extends java.lang.Object
    implements java.io.Serializable
    Represents a collection of 64 boolean (on/off) flags. Individual flags are represented by powers of 2. For example,
    Flag 1 = 1
    Flag 2 = 2
    Flag 3 = 4
    Flag 4 = 8

    or using shift operator to make numbering easier:
    Flag 1 = 1 << 0
    Flag 2 = 1 << 1
    Flag 3 = 1 << 2
    Flag 4 = 1 << 3

    There cannot be a flag with a value of 3 because that represents Flag 1 and Flag 2 both being on/true.

    Version:
    $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long flags
      Represents the current flag state.
    • Constructor Summary

      Constructors 
      Constructor Description
      Flags()
      Create a new Flags object.
      Flags​(long flags)
      Initialize a new Flags object with the given flags.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Turn off all flags.
      java.lang.Object clone()
      Clone this Flags object.
      boolean equals​(java.lang.Object obj)
      Tests if two Flags objects are in the same state.
      long getFlags()
      Returns the current flags.
      int hashCode()
      The hash code is based on the current state of the flags.
      boolean isOff​(long flag)
      Tests whether the given flag is off.
      boolean isOn​(long flag)
      Tests whether the given flag is on.
      java.lang.String toString()
      Returns a 64 length String with the first flag on the right and the 64th flag on the left.
      void turnOff​(long flag)
      Turns off the given flag.
      void turnOffAll()
      Turn off all flags.
      void turnOn​(long flag)
      Turns on the given flag.
      void turnOnAll()
      Turn on all 64 flags.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • flags

        private long flags
        Represents the current flag state.
    • Constructor Detail

      • Flags

        public Flags()
        Create a new Flags object.
      • Flags

        public Flags​(long flags)
        Initialize a new Flags object with the given flags.
        Parameters:
        flags - collection of boolean flags to represent.
    • Method Detail

      • getFlags

        public long getFlags()
        Returns the current flags.
        Returns:
        collection of boolean flags represented.
      • isOn

        public boolean isOn​(long flag)
        Tests whether the given flag is on. If the flag is not a power of 2 (ie. 3) this tests whether the combination of flags is on.
        Parameters:
        flag - Flag value to check.
        Returns:
        whether the specified flag value is on.
      • isOff

        public boolean isOff​(long flag)
        Tests whether the given flag is off. If the flag is not a power of 2 (ie. 3) this tests whether the combination of flags is off.
        Parameters:
        flag - Flag value to check.
        Returns:
        whether the specified flag value is off.
      • turnOn

        public void turnOn​(long flag)
        Turns on the given flag. If the flag is not a power of 2 (ie. 3) this turns on multiple flags.
        Parameters:
        flag - Flag value to turn on.
      • turnOff

        public void turnOff​(long flag)
        Turns off the given flag. If the flag is not a power of 2 (ie. 3) this turns off multiple flags.
        Parameters:
        flag - Flag value to turn off.
      • turnOffAll

        public void turnOffAll()
        Turn off all flags.
      • clear

        public void clear()
        Turn off all flags. This is a synonym for turnOffAll().
        Since:
        Validator 1.1.1
      • turnOnAll

        public void turnOnAll()
        Turn on all 64 flags.
      • clone

        public java.lang.Object clone()
        Clone this Flags object.
        Overrides:
        clone in class java.lang.Object
        Returns:
        a copy of this object.
        See Also:
        Object.clone()
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests if two Flags objects are in the same state.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - object being tested
        Returns:
        whether the objects are equal.
        See Also:
        Object.equals(java.lang.Object)
      • hashCode

        public int hashCode()
        The hash code is based on the current state of the flags.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code for this object.
        See Also:
        Object.hashCode()
      • toString

        public java.lang.String toString()
        Returns a 64 length String with the first flag on the right and the 64th flag on the left. A 1 indicates the flag is on, a 0 means it's off.
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of this object.