Record Class Priority

java.lang.Object
java.lang.Record
net.luis.utils.util.Priority
Record Components:
name - The name of the priority
priority - The priority value
All Implemented Interfaces:
Comparable<Priority>, EnumLike<Priority>

public record Priority(@NotNull String name, long priority) extends Record implements EnumLike<Priority>
A record that represents a 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 Details

    • name

      @NotNull private final @NotNull String name
      The field for the name record component.
    • priority

      private final long priority
      The field for the priority record component.
    • VALUES

      @ReflectiveUsage private static final List<Priority> VALUES
      The list of all priority values.
      Required for the EnumLike interface.
    • LOWEST

      public static final Priority LOWEST
      The lowest priority with the value of Integer.MIN_VALUE.

      The lowest priority does not use Long.MIN_VALUE
      to allow the creation of priorities below the lowest priority.

    • LOW

      public static final Priority LOW
      A low priority with the value of Integer.MIN_VALUE divided by 2.
    • NORMAL

      public static final Priority NORMAL
      A normal priority with the value of 0.
    • HIGH

      public static final Priority HIGH
      A high priority with the value of Integer.MAX_VALUE divided by 2.
    • HIGHEST

      public static final Priority HIGHEST
      The highest priority with the value of Integer.MAX_VALUE.

      The highest priority does not use Long.MAX_VALUE
      to allow the creation of priorities above the highest priority.

  • Constructor Details

    • Priority

      public Priority(@NotNull @NotNull String name, long priority)
      Constructs a new priority with the given name and priority value.
      Parameters:
      name - The name of the priority
      priority - The priority value
      Throws:
      NullPointerException - If the name is null
  • Method Details

    • createBelow

      @NotNull public static @NotNull Priority createBelow(@NotNull @NotNull Priority priority)
      Creates a new priority below the given priority.
      Parameters:
      priority - The target priority
      Returns:
      The created priority
    • createAbove

      @NotNull public static @NotNull Priority createAbove(@NotNull @NotNull Priority priority)
      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 priority
      second - The second priority
      Returns:
      The created priority
    • lowest

      @NotNull public static @NotNull Priority lowest(Priority @Nullable ... priorities)
      Gets the lowest priority from the given priorities.
      If the list of priorities is null or empty, the nearest priority to Long.MIN_VALUE is returned.
      Parameters:
      priorities - The list of priorities
      Returns:
      The lowest priority
    • highest

      @NotNull public static @NotNull Priority highest(Priority @Nullable ... priorities)
      Gets the highest priority from the given priorities.
      If the list of priorities is null or empty, the nearest priority to Long.MAX_VALUE is returned.
      Parameters:
      priorities - The list of priorities
      Returns:
      The highest priority
    • getNearest

      @NotNull public static @NotNull Priority getNearest(long priority)
      Returns the priority with the nearest value to the given priority.
      Parameters:
      priority - The target priority
      Returns:
      The nearest priority
    • compareTo

      public int compareTo(@NotNull @NotNull Priority object)
      Specified by:
      compareTo in interface Comparable<Priority>
      Specified by:
      compareTo in interface EnumLike<Priority>
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      @NotNull public @NotNull String name()
      Returns the value of the name record component.
      Specified by:
      name in interface EnumLike<Priority>
      Returns:
      the value of the name record component
    • priority

      public long priority()
      Returns the value of the priority record component.
      Returns:
      the value of the priority record component