Package io.blt.util

Class En

java.lang.Object
io.blt.util.En

public final class En extends Object
Static utility methods for operating on Enum.
  • Method Details

    • of

      public static <E extends Enum<E>> Optional<E> of(Class<E> type, String name)
      Returns the enum constant matching name as an Optional; otherwise, returns empty. The name must match exactly.

      This method will not throw for an invalid enum name and instead will return empty.

      e.g.,
      
       of(DayOfWeek.class, "FRIDAY");    // Optional.of(DayOfWeek.FRIDAY)
       of(DayOfWeek.class, "friday");    // Optional.empty()
       of(DayOfWeek.class, "Worf");      // Optional.empty()
       of(DayOfWeek.class, "");          // Optional.empty()
       
      Type Parameters:
      E - The type of the Enum
      Parameters:
      type - The Class object of the enum class
      name - The name of the constant to return
      Returns:
      an Optional containing the enum constant if found
      Throws:
      NullPointerException - if type or name is null
    • ofIgnoreCase

      public static <E extends Enum<E>> Optional<E> ofIgnoreCase(Class<E> type, String name)
      Returns the enum constant matching name as an Optional; otherwise, returns empty. The name comparison is case-insensitive.

      This method will not throw for an invalid enum name and instead will return empty.

      
       ofIgnoreCase(DayOfWeek.class, "FRIDAY");    // Optional.of(DayOfWeek.FRIDAY)
       ofIgnoreCase(DayOfWeek.class, "friday");    // Optional.of(DayOfWeek.FRIDAY)
       ofIgnoreCase(DayOfWeek.class, "Worf");      // Optional.empty()
       ofIgnoreCase(DayOfWeek.class, "");          // Optional.empty()
       
      Type Parameters:
      E - The type of the Enum
      Parameters:
      type - The Class object of the enum class
      name - The name of the constant to return
      Returns:
      an Optional containing the enum constant if found
      Throws:
      NullPointerException - if type or name is null