Class Enum
- java.lang.Object
-
- net.ssehub.easy.varModel.model.ModelElement
-
- net.ssehub.easy.varModel.model.ContainableModelElement
-
- net.ssehub.easy.varModel.model.datatypes.CustomDatatype
-
- net.ssehub.easy.varModel.model.datatypes.Enum
-
- 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 Summary
Fields Modifier and Type Field Description static OperationASSIGNMENT(package private) static DelegatingTypeDTYPEstatic OperationEQUALSstatic OperationIS_DEFINEDprivate java.util.List<EnumLiteral>literalsstatic OperationNOTEQUALSstatic OperationNOTEQUALS_ALIASstatic OperationORDINALstatic IDatatypeTYPEThis constant represents the common type of all enums.static OperationTYPE_OF
-
Constructor Summary
Constructors Modifier Constructor Description privateEnum()Creates the singleton instance forTYPE.protectedEnum(java.lang.String name, DelegatingType singleton, ModelElement parent)Constructor for an empty enum.protectedEnum(java.lang.String name, ModelElement parent)Constructor for an empty enum.Enum(java.lang.String name, ModelElement parent, java.lang.String... literals)Constructor for the enum.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IDatatypeVisitor visitor)Accepts a specialized visitor for creating a textual representation of the identity of this type.voidaccept(IModelVisitor visitor)Accept method for the visitor.private voidadd(java.lang.String literal)Method to add an literal to the enumeration.booleanadd(EnumLiteral literal)Method to add an literal to the enumeration.EnumLiteralget(java.lang.String name)Returns the enum literal with namename.EnumLiteralgetLiteral(int index)Returns the specified literal.EnumLiteralgetLiteralByOrdinal(int ordinal)Returns a literal by itsordinal.intgetLiteralCount()Returns the number of literals.intgetLiteralIndex(EnumLiteral literal)Returns the index of the given literal.booleanhas(EnumLiteral literal)Returns whether this enum defines the specifiedliteral.booleanisOrdered()Returns whether this enum is ordered.-
Methods inherited from class net.ssehub.easy.varModel.model.datatypes.CustomDatatype
getGenericType, getGenericTypeCount, getOperation, getOperationCount, getType, getTypeClass, isAssignableFrom, isPrimitive, isPseudoType, isType
-
Methods inherited from class net.ssehub.easy.varModel.model.ContainableModelElement
getNameSpace, getParent, getProject, getQualifiedName, getTopLevelParent, isTopLevel, setParent
-
Methods inherited from class net.ssehub.easy.varModel.model.ModelElement
findAttribute, getComment, getName, getUniqueName, isTransparent, propagateAttribute, setComment, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.varModel.model.datatypes.IDatatype
getName, getNameSpace, getQualifiedName, getUniqueName
-
-
-
-
Field Detail
-
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
-
ORDINAL
public static final Operation ORDINAL
-
literals
private java.util.List<EnumLiteral> literals
-
-
Constructor Detail
-
Enum
private Enum()
Creates the singleton instance forTYPE.
-
Enum
protected Enum(java.lang.String name, ModelElement parent)Constructor for an empty enum.- Parameters:
name- Name of the enumparent- the object, in which this specific one is embedded
-
Enum
protected Enum(java.lang.String name, DelegatingType singleton, ModelElement parent)Constructor for an empty enum.- Parameters:
name- Name of the enumsingleton- the instance which knows the operationsparent- the object, in which this specific one is embedded
-
Enum
public Enum(java.lang.String name, ModelElement parent, java.lang.String... literals)Constructor for the enum.- Parameters:
name- Name of the enumparent- the object, in which this specific one is embeddedliterals- literals to put into this Enum
-
-
Method Detail
-
add
private void add(java.lang.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:
trueif the operation was successful,false
-
has
public boolean has(EnumLiteral literal)
Returns whether this enum defines the specifiedliteral.- Parameters:
literal- the literal to test for- Returns:
trueif it is defined,falseelse
-
get
public EnumLiteral get(java.lang.String name)
Returns the enum literal with namename.- 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:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getLiteralCount()
-
getLiteralByOrdinal
public EnumLiteral getLiteralByOrdinal(int ordinal)
Returns a literal by itsordinal.- 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,
-1if not found
-
isOrdered
public boolean isOrdered()
Returns whether this enum is ordered.- Returns:
trueif it is ordered,falseelse (defaultfalse)
-
accept
public void accept(IDatatypeVisitor visitor)
Description copied from interface:IDatatypeVisitableAccepts a specialized visitor for creating a textual representation of the identity of this type.- Specified by:
acceptin interfaceIDatatypeVisitable- Overrides:
acceptin classContainableModelElement- Parameters:
visitor- the visitor to accept
-
-