Class VolumeKeepPriority
- java.lang.Object
-
- org.daisy.dotify.formatter.impl.search.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(VolumeKeepPriority o)Compares this priority with the specified priority.static VolumeKeepPriorityempty()Returns an instance with no priority (lowest).booleanequals(Object obj)intgetValue()Gets the priority value, if present.inthashCode()booleanhasValue()Returns true if a priority is set, false otherwise.static Comparator<VolumeKeepPriority>naturalOrder()Returns a comparator that imposes the natural ordering onVolumeKeepPriorityobjects.static VolumeKeepPriorityof(int value)Creates an new instance with the specified priority.static VolumeKeepPriorityofNullable(Number value)Creates a new instance with the specified priority (may be null).intorElse(int other)Gets the priority if set, otherwise returns the supplied 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 usinggetValue().- 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
absentpriority 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:
compareToin interfaceComparable<VolumeKeepPriority>- Parameters:
o- The other priority- Returns:
- The value
0if the priority ofthisis equal too; a value less than0if the priority ofthisis lower than the priority ofo; and a value greater than0if the priority ofthisis greater than the priority ofo; ifthisdoes not have a priority value andodoes, a value greater than0is returned; ifthishas a priority value andodoes not, a value less than0is returned; if neitherthisnorohas a priority value, the value0is returned.
-
naturalOrder
public static Comparator<VolumeKeepPriority> naturalOrder()
Returns a comparator that imposes the natural ordering on
VolumeKeepPriorityobjects.Objects are ordered according to
compareTo(VolumeKeepPriority), from lower to higher priority.- Returns:
- a comparator that imposes the natural ordering on
VolumeKeepPriorityobjects.
-
-