Enum Class WrapMode
- All Implemented Interfaces:
Serializable
,Comparable<WrapMode>
,Constable
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 ConstantsEnum ConstantDescriptionValues 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 TypeMethodDescription<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
toarray.length - 1
).int
transformIndex
(int index, Collection<?> collection) Transforms an index based on the index range of a list (0
tolist.size() - 1
).static WrapMode
Returns the enum constant of this class with the specified name.static WrapMode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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
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
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
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
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 nameNullPointerException
- if the argument is null
-
getElement
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
tolist.size() - 1
).- Type Parameters:
E
- The type of elements in the list- Parameters:
index
- The raw index value to transformlist
- 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
toarray.length - 1
).- Type Parameters:
E
- The type of elements in the array- Parameters:
index
- The raw index value to transformarray
- 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
Transforms an index based on the index range of a list (0
tolist.size() - 1
).- Parameters:
index
- The index to transformcollection
- 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
toarray.length - 1
).- Parameters:
index
- The index to transformarray
- The array- Returns:
- The transformed index. (
-1
represents an empty value.)
-
transform
Transforms a value based on the given bounds.- Parameters:
value
- The value to wrapmin
- The lower boundmax
- The upper bound- Returns:
- The transformed value. (
-1
represents an empty value.) - Throws:
IllegalArgumentException
- If the bounds are invalid.
-