Enum Class WrapMode

java.lang.Object
java.lang.Enum<WrapMode>
dev.prozilla.pine.common.property.selection.WrapMode
All Implemented Interfaces:
Serializable, Comparable<WrapMode>, Constable

public enum WrapMode extends Enum<WrapMode>
Determines how values outside of bounds are transformed.

Can be used to transform any given number into an index for an item in an array.

  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Values outside the bounds are forced to the nearest valid bound.
    Values outside the bounds are considered invalid and return -1 to indicate no valid result.
    Values outside the bounds wrap around and re-enter from the opposite side, creating a continuous loop.
  • Method Summary

    Modifier and Type
    Method
    Description
    <E> E
    getElement(int index, E[] array)
    Applies this wrap mode to an index for an array and returns the corresponding element.
    <E> E
    getElement(int index, List<E> list)
    Applies this wrap mode to an index for a list and returns the corresponding element.
    abstract int
    transform(int value, int min, int max)
    Transforms a value based on the given bounds.
    <E> int
    transformIndex(int index, E[] array)
    Transforms an index based on the index range of an array (0 to array.length - 1).
    int
    transformIndex(int index, Collection<?> collection)
    Transforms an index based on the index range of a list (0 to list.size() - 1).
    static WrapMode
    Returns the enum constant of this class with the specified name.
    static WrapMode[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • REPEAT

      public static final WrapMode REPEAT
      Values outside the bounds wrap around and re-enter from the opposite side, creating a continuous loop.

      Example: With bounds 0–4, an input of 5 becomes 0, and an input of -1 becomes 4.

    • CLIP

      public static final WrapMode CLIP
      Values outside the bounds are considered invalid and return -1 to indicate no valid result.

      Example: With bounds 0–4, inputs like -2 or 6 will return -1.

    • CLAMP

      public static final WrapMode CLAMP
      Values outside the bounds are forced to the nearest valid bound.

      Example: With bounds 0–4, an input of 6 becomes 4, and an input of -2 becomes 0.

  • Method Details

    • values

      public static WrapMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static WrapMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getElement

      public <E> E getElement(int index, List<E> list)
      Applies this wrap mode to an index for a list and returns the corresponding element.

      The transformation is based on the list's index range (0 to list.size() - 1).

      Type Parameters:
      E - The type of elements in the list
      Parameters:
      index - The raw index value to transform
      list - The list from which to retrieve the element
      Returns:
      The element at the transformed index, or null if the transformed index represents an empty value.
      See Also:
    • getElement

      public <E> E getElement(int index, E[] array)
      Applies this wrap mode to an index for an array and returns the corresponding element.

      The transformation is based on the array's index range (0 to array.length - 1).

      Type Parameters:
      E - The type of elements in the array
      Parameters:
      index - The raw index value to transform
      array - The array from which to retrieve the element
      Returns:
      The element at the transformed index, or null if the transformed index represents an empty value.
      See Also:
    • transformIndex

      public int transformIndex(int index, Collection<?> collection)
      Transforms an index based on the index range of a list (0 to list.size() - 1).
      Parameters:
      index - The index to transform
      collection - The collection
      Returns:
      The transformed index. (-1 represents an empty value.)
    • transformIndex

      public <E> int transformIndex(int index, E[] array)
      Transforms an index based on the index range of an array (0 to array.length - 1).
      Parameters:
      index - The index to transform
      array - The array
      Returns:
      The transformed index. (-1 represents an empty value.)
    • transform

      public abstract int transform(int value, int min, int max) throws IllegalArgumentException
      Transforms a value based on the given bounds.
      Parameters:
      value - The value to wrap
      min - The lower bound
      max - The upper bound
      Returns:
      The transformed value. (-1 represents an empty value.)
      Throws:
      IllegalArgumentException - If the bounds are invalid.