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, CouplingType, CoverageContentType, Datatype, DateType, DimensionNameType, DistanceOperatorName, DistributedComputingPlatform, EvaluationMethodType, GeometricObjectType, GeometryType, ImagingCondition, InitiativeType, KeywordType, LogicalOperatorName, MaintenanceFrequency, MediumFormat, MediumName, ObjectiveType, Obligation, OnLineFunction, OperationType, PixelInCell, PixelOrientation, PolarizationOrientation, PresentationForm, Priority, Progress, RangeMeaning, 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. Subclasses shall provides a values() method which returns all CodeList element in an array of the appropriate class.

Code lists are extensible, i.e. invoking the valueOf(String) method in any subclass will automatically add the newly created CodeList element in the array to be returned by values().

Since:
1.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Deprecated.
    Replaced by Predicate from the standard Java library.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    CodeList(String name, Collection<E> values)
    Creates a new code list element and add it to the given collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    compareTo(E other)
    Compares this code with the specified object for order.
    abstract E[]
    Returns the list of codes of the same kind than this code.
    Returns the identifier declared in the UML annotation, or null if none.
    final String
    Returns the programmatic name of this code list constant.
    Returns all the names of this code.
    final int
    Returns the ordinal of this code constant.
    protected Object
    Resolves the code list to an unique instance after deserialization.
    Returns a string representation of this code list.
    static <T extends CodeList<T>>
    T
    valueOf(Class<T> codeType, String name)
    Returns the code of the given type that matches the given name, or returns a new one if none match it.
    static <T extends CodeList<T>>
    T
    valueOf(Class<T> codeType, Predicate<CodeList<?>> filter, String nameIfNew)
    Returns the code of the given type that matches the given criterion, or optionally creates a new code if there is no match.
    static <T extends CodeList<T>>
    T
    valueOf(Class<T> codeType, CodeList.Filter filter)
    Deprecated.
    Since deprecation of CodeList.Filter, replaced by valueOf(Class, Predicate, String).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CodeList

      protected CodeList(String name, Collection<E> values)
      Creates a new code list element and add it to the given collection. Subclasses will typically give a static reference to an ArrayList for the values argument. This list is used for values() method implementations.
      Parameters:
      name - the code name.
      values - the collection to add the element to.
      Throws:
      IllegalArgumentException - if values is not the same collection than the one specified for previous instances of the same code list class.
  • Method Details

    • valueOf

      public static <T extends CodeList<T>> T valueOf(Class<T> codeType, String name)
      Returns the code of the given type that matches the given name, or returns a new one if none match it. More specifically, this methods returns the first instance of the given class for which name().equals(name) is true. If no such instance is found, then a new instance is created using the constructor expecting a single String argument.

      Note that invoking this method may result in the creation of a new code value. If this is not desired, use valueOf(Class, Predicate, String) instead.

      Type Parameters:
      T - the compile-time type given as the codeType parameter.
      Parameters:
      codeType - the type of code list.
      name - the name of the code to obtain, or null.
      Returns:
      a code matching the given name (possible a new code), or null if the given name is null.
      Departure from OGC/ISO abstract specification:
      Departure for closer integration with the Java environment Provided by analogy with the methods in the Java Enum class.
    • valueOf

      @Deprecated public static <T extends CodeList<T>> T valueOf(Class<T> codeType, CodeList.Filter filter)
      Deprecated.
      Since deprecation of CodeList.Filter, replaced by valueOf(Class, Predicate, String).
      Returns the code of the given type that matches the given criterion, or returns a new one if none match it. More specifically, this methods returns the first element (in declaration order) of the given class where filter.accept(code) returns true. If no such element is found, then there is a choice:
      • If CodeList.Filter.codename() returns null, then this method returns null.
      • Otherwise a new instance is created using the constructor expecting a single String argument, which is given the value returned by codename().
      Type Parameters:
      T - the compile-time type given as the codeType parameter.
      Parameters:
      codeType - the type of code list.
      filter - the criterion for the code to obtain.
      Returns:
      a code matching the given criterion, or null if there is no match and CodeList.Filter.codename() returns null.
    • valueOf

      public static <T extends CodeList<T>> T valueOf(Class<T> codeType, Predicate<CodeList<?>> filter, String nameIfNew)
      Returns the code of the given type that matches the given criterion, or optionally creates a new code if there is no match. More specifically, this methods returns the first element (in declaration order) of the given class where filter.test(code) returns true. If no such element is found, then there is a choice:
      • If nameIfNew is null, then this method returns null.
      • Otherwise a new instance is created using the constructor expecting a single String argument, which is given the nameIfNew value.

      This method is useful when a lenient comparisons of names is desired (for example ignoring cases or taking in account all names enumerated by names(), or when the caller does not want to create new code value in case of no match.

      Type Parameters:
      T - the compile-time type given as the codeType parameter.
      Parameters:
      codeType - the type of code list.
      filter - the criterion for the code to obtain.
      nameIfNew - the name to use if a new code list needs to be created, or null for not creating any new code list.
      Returns:
      a code matching the given criterion, or null if none and nameIfNew is null.
      Since:
      3.1
    • family

      public abstract E[] family()
      Returns the list of codes of the same kind than this code. Invoking this method gives identical results than invoking the static values() methods provided in CodeList subclasses, except that family() does not require the class to be known at compile-time — provided that at least one instance of the family is available.
      Specified by:
      family in interface ControlledVocabulary
      Returns:
      the codes of the same kind than this code.
      Departure from OGC/ISO abstract specification:
      Departure for closer integration with the Java environment Provided by analogy with Enum.family(), which was defined in a initial draft of Java 5 before the final release.
    • names

      public String[] names()
      Returns all the names of this code. The returned array contains the following elements, with duplicated values and null values removed: Those names are typically equal except for the case (programmatic names are upper case while UML names are lower case) and special characters like '-'.
      Specified by:
      names in interface ControlledVocabulary
      Returns:
      all names of this code constant. This array is never null and never empty.
      Departure from OGC/ISO abstract specification:
      Addition of element not in the ISO/OGC specification Defined because each CodeList has at least two names, the Java programmatic name and the UML identifier, while some subclasses have additional names.
    • name

      public final String name()
      Returns the programmatic name of this code list constant. This is the name of the public static field which declare the code.
      Specified by:
      name in interface ControlledVocabulary
      Returns:
      the name of this code constant.
      Departure from OGC/ISO abstract specification:
      Departure for closer integration with the Java environment Provided by analogy with the methods in the Java Enum class.
    • identifier

      public String identifier()
      Returns the identifier declared in the UML annotation, or null if none. The UML identifier shall be the ISO or OGC name for this code constant.
      Specified by:
      identifier in interface ControlledVocabulary
      Returns:
      the ISO/OGC identifier for this code constant, or null if none.
      Departure from OGC/ISO abstract specification:
      Addition of element not in the ISO/OGC specification Defined because each CodeList has a UML identifier in addition of the Java programmatic name.
    • ordinal

      public final int ordinal()
      Returns the ordinal of this code constant. This is its position in its elements declaration, where the initial constant is assigned an ordinal of zero.
      Specified by:
      ordinal in interface ControlledVocabulary
      Returns:
      the position of this code constants in elements declaration.
      Departure from OGC/ISO abstract specification:
      Departure for closer integration with the Java environment Provided by analogy with the methods in the Java Enum class.
    • compareTo

      public final int compareTo(E other)
      Compares this code with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

      Code list constants are only comparable to other code list constants of the same type. The natural order implemented by this method is the order in which the constants are declared.

      Specified by:
      compareTo in interface Comparable<E extends CodeList<E>>
      Parameters:
      other - the code constant to compare with this code.
      Returns:
      a negative value if the given code is less than this code, a positive value if greater or 0 if equal.
    • toString

      public String toString()
      Returns a string representation of this code list.
      Overrides:
      toString in class Object
    • readResolve

      protected Object readResolve() throws ObjectStreamException
      Resolves the code list to an unique instance after deserialization. The instance is resolved using its name only (not its ordinal).
      Returns:
      this code list as an unique instance.
      Throws:
      ObjectStreamException - if the deserialization failed.