Class DynamicEnum<T>

java.lang.Object
eu.bandm.tools.util.DynamicEnum<T>
All Implemented Interfaces:
Index<DynamicEnum.Item<T>>, Serializable, Iterable<DynamicEnum.Item<T>>
Direct Known Subclasses:
DynamicEnum.Coproduct, DynamicEnum.Product

public class DynamicEnum<T> extends Object implements Index<DynamicEnum.Item<T>>, Serializable
See Also:
  • Constructor Details

    • DynamicEnum

      public DynamicEnum()
      Constructor for an emtpy enumeration. Must be filled by successive calls to add(T).
    • DynamicEnum

      public DynamicEnum(T... items)
      Constructor for an enumeration with fixed content. No further addtions may happen.
    • DynamicEnum

      public DynamicEnum(Collection<? extends T> items)
      Constructor for an enumeration with fixed content. No further addtions may happen.
  • Method Details

    • add

      public DynamicEnum.Item<T> add(T data)
      Add one item.
      Throws:
      IllegalStateException - if sealed flag is set.
    • seal

      public void seal()
      Set the sealed flag to indicate that the definition is complete. Must be called after the last call to add(T).
    • size

      public int size()
      Description copied from interface: Index
      Returns the number of objects in this index. This number is nonnegative.
      Specified by:
      size in interface Index<T>
      Returns:
      the number of objects in this index.
    • iterator

      public Iterator<DynamicEnum.Item<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • items

      public List<DynamicEnum.Item<T>> items()
      evident
    • get

      @Opt public @Opt DynamicEnum.Item<T> get(int i)
      Returns the added item by its position number, or null if no such found.
      Specified by:
      get in interface Index<T>
      Returns:
      the object associated with a given number.
    • indexOf

      public int indexOf(DynamicEnum.Item<T> i)
      Returns the number of the item in this enumeration, or -1 if not contained.
      Specified by:
      indexOf in interface Index<T>
    • indexOfUnchecked

      public int indexOfUnchecked(Object o)
      Returns the number of the item in this enumeration, or -1 if not contained.
      Specified by:
      indexOfUnchecked in interface Index<T>
    • contains

      public boolean contains(DynamicEnum.Item<T> i)
      Returns whether the argument is contained in this enumeration.
      Specified by:
      contains in interface Index<T>
    • containsSemichecked

      public boolean containsSemichecked(DynamicEnum.Item<?> i)
      Returns whether the argument is contained in this enumeration.
    • containsUnchecked

      public boolean containsUnchecked(Object o)
      Returns whether the argument is contained in this enumeration.
      Specified by:
      containsUnchecked in interface Index<T>