Class AtomicEnum<T extends Enum<T>>

  • Type Parameters:
    T - the type of the Enum

    public final class AtomicEnum<T extends Enum<T>>
    extends Object
    An Enum value that may be updated atomically.

    See the java.util.concurrent.atomic package specification for description of the properties of atomic variables.

    Since:
    21.12
    Author:
    bo
    • Method Detail

      • compareAndSet

        public boolean compareAndSet​(T expect,
                                     T newValue)
        Atomically sets the value to the new value if the current value == the expected value.
        Parameters:
        expect - the expected value
        newValue - the new value
        Returns:
        true if successful false indicates that the current value was not equal to the expected value.
      • get

        public T get()
        Gets the current value.
        Returns:
        the current value
      • getAndSet

        public T getAndSet​(T newValue)
        Atomically sets the AtomicEnum to the given new value and returns the previous value.
        Parameters:
        newValue - the new value
        Returns:
        the previous value
      • set

        public void set​(T value)
        Sets the AtomicEnum to the new value.
        Parameters:
        value - the new value
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • of

        public static <T extends Enum<T>> AtomicEnum<T> of​(T value)
        Constructs an AtomicEnum given a Enum value.
        Type Parameters:
        T - the type of the Enum
        Parameters:
        value - the Enum value (may be null)
        Returns:
        the AtomicEnum