- Record Components:
name
- The name of the prioritypriority
- The priority value
- All Implemented Interfaces:
Comparable<Priority>
,EnumLike<Priority>
The priority can be used to determine the order of elements in a list.
The priority is an integer value that can be compared to other priorities.
Higher priorities are considered to be more important than lower priorities.
A higher priority has a higher value than a lower priority.
The default priorities LOWEST
, LOW
, NORMAL
, HIGH
, and HIGHEST
are using integer values to represent the priority.
This allows the creation of priorities below the lowest priority and above the highest priority.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Priority
A high priority with the value ofInteger.MAX_VALUE
divided by 2.static final Priority
The highest priority with the value ofInteger.MAX_VALUE
.static final Priority
A low priority with the value ofInteger.MIN_VALUE
divided by 2.static final Priority
The lowest priority with the value ofInteger.MIN_VALUE
.private final @NotNull String
The field for thename
record component.static final Priority
A normal priority with the value of0
.private final long
The field for thepriority
record component. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
static @NotNull Priority
createAbove
(@NotNull Priority priority) Creates a new priority above the given priority.static @NotNull Priority
createBelow
(@NotNull Priority priority) Creates a new priority below the given priority.static @NotNull Priority
createBetween
(@NotNull Priority first, @NotNull Priority second) Creates a new priority between the two given priorities.final boolean
Indicates whether some other object is "equal to" this one.static @NotNull Priority
getNearest
(long priority) Returns the priority with the nearest value to the given priority.final int
hashCode()
Returns a hash code value for this object.static @NotNull Priority
Gets the highest priority from the given priorities.
If the list of priorities is null or empty, the nearest priority toLong.MAX_VALUE
is returned.static @NotNull Priority
Gets the lowest priority from the given priorities.
If the list of priorities is null or empty, the nearest priority toLong.MIN_VALUE
is returned.@NotNull String
name()
Returns the value of thename
record component.long
priority()
Returns the value of thepriority
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
name
The field for thename
record component. -
priority
private final long priorityThe field for thepriority
record component. -
VALUES
-
LOWEST
The lowest priority with the value ofInteger.MIN_VALUE
.
The lowest priority does not use
Long.MIN_VALUE
to allow the creation of priorities below the lowest priority.
-
LOW
A low priority with the value ofInteger.MIN_VALUE
divided by 2. -
NORMAL
A normal priority with the value of0
. -
HIGH
A high priority with the value ofInteger.MAX_VALUE
divided by 2. -
HIGHEST
The highest priority with the value ofInteger.MAX_VALUE
.
The highest priority does not use
Long.MAX_VALUE
to allow the creation of priorities above the highest priority.
-
-
Constructor Details
-
Priority
Constructs a new priority with the given name and priority value.- Parameters:
name
- The name of the prioritypriority
- The priority value- Throws:
NullPointerException
- If the name is null
-
-
Method Details
-
createBelow
Creates a new priority below the given priority.- Parameters:
priority
- The target priority- Returns:
- The created priority
-
createAbove
Creates a new priority above the given priority.- Parameters:
priority
- The target priority- Returns:
- The created priority
-
createBetween
@NotNull public static @NotNull Priority createBetween(@NotNull @NotNull Priority first, @NotNull @NotNull Priority second) Creates a new priority between the two given priorities.- Parameters:
first
- The first prioritysecond
- The second priority- Returns:
- The created priority
-
lowest
Gets the lowest priority from the given priorities.
If the list of priorities is null or empty, the nearest priority toLong.MIN_VALUE
is returned.- Parameters:
priorities
- The list of priorities- Returns:
- The lowest priority
-
highest
Gets the highest priority from the given priorities.
If the list of priorities is null or empty, the nearest priority toLong.MAX_VALUE
is returned.- Parameters:
priorities
- The list of priorities- Returns:
- The highest priority
-
getNearest
Returns the priority with the nearest value to the given priority.- Parameters:
priority
- The target priority- Returns:
- The nearest priority
-
compareTo
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
name
Returns the value of thename
record component. -
priority
public long priority()Returns the value of thepriority
record component.- Returns:
- the value of the
priority
record component
-