Class EnumerationUtils

  • All Implemented Interfaces:
    Utils

    public abstract class EnumerationUtils
    extends java.lang.Object
    implements Utils
    The utilities class for Java Enumeration
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Enumeration, Collections.enumeration(java.util.Collection<T>)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isEnumeration​(java.lang.Class<?> type)
      Checks if the given class type is assignable from Enumeration.
      static boolean isEnumeration​(java.lang.Object values)
      Checks if the given object is an instance of Enumeration.
      static <E> java.util.Enumeration<E> of​(E... elements)
      Creates an Enumeration from the provided elements.
      static <E> java.util.Enumeration<E> ofEnumeration​(E... elements)
      Creates an Enumeration from the provided elements array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isEnumeration

        public static boolean isEnumeration​(@Nullable
                                            java.lang.Object values)
        Checks if the given object is an instance of Enumeration.

        Example Usage

        
         boolean result = EnumerationUtils.isEnumeration(someObject);
         if (result) {
             Enumeration<?> enumeration = (Enumeration<?>) someObject;
             while (enumeration.hasMoreElements()) {
                 System.out.println(enumeration.nextElement());
             }
         }
         
        Parameters:
        values - the object to check
        Returns:
        true if the object is an instance of Enumeration, false otherwise
      • isEnumeration

        public static boolean isEnumeration​(@Nullable
                                            java.lang.Class<?> type)
        Checks if the given class type is assignable from Enumeration.

        Example Usage

        
         boolean result = EnumerationUtils.isEnumeration(SomeEnumClass.class);
         if (result) {
             // The class is an Enumeration
         }
         
        Parameters:
        type - the class type to check
        Returns:
        true if the class is assignable from Enumeration, false otherwise
      • of

        @Nonnull
        public static <E> java.util.Enumeration<E> of​(E... elements)
        Creates an Enumeration from the provided elements.

        Internally, this method delegates to ofEnumeration(Object[]) to create a new enumeration based on the given array of elements.

        Example Usage

        
         Enumeration<String> en = EnumerationUtils.of("one", "two", "three");
         while (en.hasMoreElements()) {
             System.out.println(en.nextElement());
         }
         
        Type Parameters:
        E - the type of the elements
        Parameters:
        elements - the array of elements to include in the enumeration
        Returns:
        a non-null Enumeration instance containing the specified elements
      • ofEnumeration

        @Nonnull
        public static <E> java.util.Enumeration<E> ofEnumeration​(E... elements)
        Creates an Enumeration from the provided elements array.

        This method constructs a new ArrayEnumeration instance backed by the given array, allowing sequential read-only access to the array elements.

        Example Usage

        
         Enumeration<String> en = EnumerationUtils.ofEnumeration("apple", "banana", "cherry");
         while (en.hasMoreElements()) {
             System.out.println(en.nextElement());
         }
         
        Type Parameters:
        E - the type of the elements
        Parameters:
        elements - the array of elements to include in the enumeration
        Returns:
        a non-null Enumeration instance containing the specified elements