Class CodeList<E extends CodeList<E>>

Object
CodeList<E>
Type Parameters:
E - the type of this code list.
All Implemented Interfaces:
Serializable, Comparable<E>, ControlledVocabulary
Direct Known Subclasses:
AssociationType, AxisDirection, BandDefinition, CellGeometry, CharacterSet, Classification, ComparisonOperatorName, Configuration.Key, Context, CoordinateDataType, CouplingType, CoverageContentType, Datatype, DateType, DimensionNameType, DistanceOperatorName, DistributedComputingPlatform, EvaluationMethodType, GeometricObjectType, GeometryType, ImagingCondition, IndeterminateValue, InitiativeType, KeywordType, LogicalOperatorName, MaintenanceFrequency, MediumFormat, MediumName, ObjectiveType, Obligation, OnLineFunction, OperationType, PixelInCell, PixelOrientation, PolarizationOrientation, PresentationForm, Priority, Progress, RangeMeaning, RealizationMethod, ReferenceSystemType, Restriction, Role, ScopeCode, Sequence, SpatialOperatorName, SpatialRepresentationType, TelephoneType, TemporalOperatorName, TopicCategory, TopologyLevel, TransferFunctionType, Trigger, ValueStructure, VerticalDatumType

@UML(identifier="CodeList", specification=ISO_19103) public abstract class CodeList<E extends CodeList<E>> extends Object implements ControlledVocabulary, Comparable<E>, Serializable
Base class for all code lists. Code lists are like enumerations, but extensible. For example, invoking the valueOf(String) method in any subclass with a name that was not previously defined will create a new CodeList element and automatically add it to the arrays returned by values().

Guidance for subclasses

The parameter type <E> shall be the same type as the code list subclass. In other words, if the subclass is Foo, then it must extend CodeList<Foo>. In addition, subclasses should provide values(String) and values() methods. The following code snippet is a suggested pattern for subclasses:
public final class Foo extends CodeList<Foo> {
    public static final Foo BAR = new Foo("BAR");
    public static final Foo BIZ = new Foo("BIZ");

    private Foo(String name) {
        super(name);
    }

    public static Foo valueOf(String name) {
        return valueOf(Foo.class, name, Foo::new).get();
    }

    public static Foo[] values() {
        return values(Foo.class);
    }

    @Override
    public Foo[] family() {
        return values();
    }
}
Above snippet is sufficient for classes in exported packages. If a code list is defined in a non-exported package, then its static fields may need to be initialized with valueOf(String) instead of new Foo(String). It will have a small performance cost, but is needed because of Java Module System restrictions on reflection.
Since:
1.0
See Also: