Class VolumeKeepPriority

  • All Implemented Interfaces:
    Comparable<VolumeKeepPriority>

    public final class VolumeKeepPriority
    extends Object
    implements Comparable<VolumeKeepPriority>

    Provides a simple data type for volume keep priority, where 1 represents the highest priority and 9 the lowest. A high priority means that we do more effort to avoid splitting a volume within the area the priority is declared on.

    This class is modeled on Java's Optional and provides similar capabilities. As with Optional, setting a field with this type to null is strongly discouraged. Instead, use empty() to create an empty instance.

    The primary reason for creating a special class is to make the meaning of the number contained in it clearer. But in addition, it makes it possible to enforce internal bounds checks. The caller can therefore rely on this fact when getting the value.

    • Method Detail

      • of

        public static VolumeKeepPriority of​(int value)
        Creates an new instance with the specified priority.
        Parameters:
        value - the priority
        Returns:
        returns a new instance
      • ofNullable

        public static VolumeKeepPriority ofNullable​(Number value)
        Creates a new instance with the specified priority (may be null).
        Parameters:
        value - the priority, or null
        Returns:
        returns a new instance
      • empty

        public static VolumeKeepPriority empty()
        Returns an instance with no priority (lowest).
        Returns:
        returns an instance with no priority
      • getValue

        public int getValue()
        Gets the priority value, if present. The value is in the range [1, 9] where 1 represents the highest priority and 9 the lowest.
        Returns:
        returns the priority
        Throws:
        NoSuchElementException - if no priority is set.
      • hasValue

        public boolean hasValue()
        Returns true if a priority is set, false otherwise. If a priority is set, it can be retrieved using getValue().
        Returns:
        returns true if a priority is available, false otherwise
      • orElse

        public int orElse​(int other)
        Gets the priority if set, otherwise returns the supplied value.
        Parameters:
        other - the value to return if not set
        Returns:
        returns the priority, or the supplied value
      • compareTo

        public int compareTo​(VolumeKeepPriority o)

        Compares this priority with the specified priority.

        Returns a negative integer, zero, or a positive integer as this priority is lower, equal to, or higher than the specified priority. An absent priority is considered lower than the lowest priority.

        Note that this method does not compare the integer values returned by getValue(), but rather represents the "natural" ordering. (The fact that a higher priority is represented by a lower integer value may cause some confusion in this regard.)

        Specified by:
        compareTo in interface Comparable<VolumeKeepPriority>
        Parameters:
        o - The other priority
        Returns:
        The value 0 if the priority of this is equal to o; a value less than 0 if the priority of this is lower than the priority of o; and a value greater than 0 if the priority of this is greater than the priority of o; if this does not have a priority value and o does, a value greater than 0 is returned; if this has a priority value and o does not, a value less than 0 is returned; if neither this nor o has a priority value, the value 0 is returned.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object