Package io.pravega.common.util
Class EnumHelpers
- java.lang.Object
-
- io.pravega.common.util.EnumHelpers
-
public final class EnumHelpers extends java.lang.ObjectGeneral helpers on Enum types.
-
-
Constructor Summary
Constructors Constructor Description EnumHelpers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Enum<T>>
T[]indexById(java.lang.Class<T> enumClass, java.util.function.ToIntFunction<T> getId)Indexes the values of the given Enum by a specified Id function.
-
-
-
Method Detail
-
indexById
public static <T extends java.lang.Enum<T>> T[] indexById(java.lang.Class<T> enumClass, java.util.function.ToIntFunction<T> getId)Indexes the values of the given Enum by a specified Id function. This method maps getId on an integer interval from 0 to max()+1, and fills in the slots where getId returns a value. Empty slots will contain null.Notes:
- This method will create an array of size max(getId(all-enum-values)), so it could get very large. It is not recommended for sparse Enums (in which case a Map would be better suited).
- This method has undefined behavior if getId does not return unique values. It does not check, so Enum values that have the same result from getId may not be indexed correctly.
- Type Parameters:
T- Type of the enum.- Parameters:
enumClass- The Enum Class.getId- A function that returns an Id for each enum value.- Returns:
- An array of type T with Enum values indexed by the result of the getId function.
-
-