All Implemented Interfaces:
IDatatype, IDatatypeVisitable, IModelElement
Direct Known Subclasses:
OrderedEnum

public class Enum extends CustomDatatype
Enumerations allow the definition of sets of named values.
Author:
heiko beck, Holger Eichelberger
  • Field Details

    • DTYPE

      static final DelegatingType DTYPE
    • TYPE

      public static final IDatatype TYPE
      This constant represents the common type of all enums. Each specific enum type is assignable to this type.
    • TYPE_OF

      public static final Operation TYPE_OF
    • EQUALS

      public static final Operation EQUALS
    • NOTEQUALS

      public static final Operation NOTEQUALS
    • NOTEQUALS_ALIAS

      public static final Operation NOTEQUALS_ALIAS
    • ASSIGNMENT

      public static final Operation ASSIGNMENT
    • IS_DEFINED

      public static final Operation IS_DEFINED
    • IF_DEFINED

      public static final Operation IF_DEFINED
    • ORDINAL

      public static final Operation ORDINAL
    • literals

      private List<EnumLiteral> literals
  • Constructor Details

    • Enum

      private Enum()
      Creates the singleton instance for TYPE.
    • Enum

      protected Enum(String name, ModelElement parent)
      Constructor for an empty enum.
      Parameters:
      name - Name of the enum
      parent - the object, in which this specific one is embedded
    • Enum

      protected Enum(String name, DelegatingType singleton, ModelElement parent)
      Constructor for an empty enum.
      Parameters:
      name - Name of the enum
      singleton - the instance which knows the operations
      parent - the object, in which this specific one is embedded
    • Enum

      public Enum(String name, ModelElement parent, String... literals)
      Constructor for the enum.
      Parameters:
      name - Name of the enum
      parent - the object, in which this specific one is embedded
      literals - literals to put into this Enum
  • Method Details

    • add

      private void add(String literal)
      Method to add an literal to the enumeration.
      Parameters:
      literal - the literal to add
    • add

      public boolean add(EnumLiteral literal)
      Method to add an literal to the enumeration.
      Parameters:
      literal - the literal to add
      Returns:
      true if the operation was successful, false
    • has

      public boolean has(EnumLiteral literal)
      Returns whether this enum defines the specified literal.
      Parameters:
      literal - the literal to test for
      Returns:
      true if it is defined, false else
    • get

      public EnumLiteral get(String name)
      Returns the enum literal with name name.
      Parameters:
      name - the name to search for
      Returns:
      the literal or null
    • accept

      public void accept(IModelVisitor visitor)
      Accept method for the visitor.
      Parameters:
      visitor - The visitor, which should process this model element.
    • getLiteralCount

      public int getLiteralCount()
      Returns the number of literals.
      Returns:
      the number of literals
    • getLiteral

      public EnumLiteral getLiteral(int index)
      Returns the specified literal.
      Parameters:
      index - the index of the literal to be returned
      Returns:
      the specified literal
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getLiteralCount()
    • getLiteralByOrdinal

      public EnumLiteral getLiteralByOrdinal(int ordinal)
      Returns a literal by its ordinal.
      Parameters:
      ordinal - the ordinal of the enumeration literal
      Returns:
      the literal or null if not found
    • getLiteralIndex

      public int getLiteralIndex(EnumLiteral literal)
      Returns the index of the given literal.
      Parameters:
      literal - the literal to search for
      Returns:
      the index of the literal, -1 if not found
    • isOrdered

      public boolean isOrdered()
      Returns whether this enum is ordered.
      Returns:
      true if it is ordered, false else (default false)
    • accept

      public void accept(IDatatypeVisitor visitor)
      Description copied from interface: IDatatypeVisitable
      Accepts a specialized visitor for creating a textual representation of the identity of this type.
      Specified by:
      accept in interface IDatatypeVisitable
      Overrides:
      accept in class ContainableModelElement
      Parameters:
      visitor - the visitor to accept