org.sape.carbon.core.util.enum
Class BaseEnum.EnumTypeAggregator

java.lang.Object
  |
  +--org.sape.carbon.core.util.enum.BaseEnum.EnumTypeAggregator
Enclosing class:
BaseEnum

private static class BaseEnum.EnumTypeAggregator
extends Object

This inner class of the BaseEnum system catalogs all enumeration instances for one particular class of enumerated values. It holds references by name and by ordinal value to those instances and is accessed through aggregation, by map, in the BaseEnum static methods.

This class should never be referenced outside of the BaseEnum class as we have given full aggregation control of all enumeration instances in the system to the BaseEnum type. This has the advantage of requiring that all instances of a single enum value will actually point at the same class negating the need for any complex equals or hashcode implementation.

Since:
carbon 1.0

Field Summary
private  Class enumType
          A reference to the class type of a BaseEnum subclass
private  Map nameMap
          A mapping of names to their Enumerated Instances
private  int nextOrdinal
          The value of the next ordinal to be created in this enumeration
private  SortedMap ordinalMap
          A mapping of ordinal values to their Enumerated Instances
 
Constructor Summary
BaseEnum.EnumTypeAggregator(Class enumType)
          This constructs a new EnumTypeCatalog that will catalog the types for one specific Class type of BaseEnum.
 
Method Summary
 void addEnumeratedInstance(BaseEnum enumeratedType)
          Adds a specific instance of an enumerated type to this catalogue for a specific subclass of BaseEnum.
 BaseEnum getByName(String name)
          Looks up a enumeration instance in this catalogue by name
 BaseEnum getByOrdinal(int ordinal)
          Looks up a enumeration instance in this catalogue by ordinal
 int getNextOrdinal()
          Retrieves the next available ordinal value for this aggregate of enumeration instances.
 Iterator iterator()
          Provides access to an umodifiable iterator over the instances of this enumeration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enumType

private Class enumType
A reference to the class type of a BaseEnum subclass


nextOrdinal

private int nextOrdinal
The value of the next ordinal to be created in this enumeration


nameMap

private Map nameMap
A mapping of names to their Enumerated Instances


ordinalMap

private SortedMap ordinalMap
A mapping of ordinal values to their Enumerated Instances

Constructor Detail

BaseEnum.EnumTypeAggregator

public BaseEnum.EnumTypeAggregator(Class enumType)
This constructs a new EnumTypeCatalog that will catalog the types for one specific Class type of BaseEnum.

Parameters:
enumType - the type of the enumeration being built
Method Detail

iterator

public Iterator iterator()
Provides access to an umodifiable iterator over the instances of this enumeration. This iterator will access the values by ascending ordinal order.

Returns:
an iterator of the enum instances for the type being mapped byt this EnumTypeAggregator

getNextOrdinal

public int getNextOrdinal()
Retrieves the next available ordinal value for this aggregate of enumeration instances. This value is incremented by 1 on each call, but may ignored by manually setting the value of a enumeration's ordinal value.

Returns:
the next int ordinal value

addEnumeratedInstance

public void addEnumeratedInstance(BaseEnum enumeratedType)
Adds a specific instance of an enumerated type to this catalogue for a specific subclass of BaseEnum.

Parameters:
enumeratedType - the enumerated type instance to add to this catalogue

getByName

public final BaseEnum getByName(String name)
Looks up a enumeration instance in this catalogue by name

Parameters:
name - the name of the enumeration instance to lookup
Returns:
an enumeration instance or null if none found

getByOrdinal

public BaseEnum getByOrdinal(int ordinal)
Looks up a enumeration instance in this catalogue by ordinal

Parameters:
ordinal - the ordinal value of the enumeration instance
Returns:
an enumeration instance or null if none found


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.