Class CodeList<E extends CodeList<E>>

    • Constructor Detail

      • 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.
    • Method Detail

      • 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.

        Implementation note: The codeType class needs to be initialized before to invoke this method. This is usually the case when the caller is a static method of the codeType class. However in other situations, callers may need to initialize explicitely the given class.

        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, or null if the name is null.
        Departure from OGC/ISO specification:
        Provided by analogy with the methods in the Java Enum class.
      • valueOf

        public static <T extends CodeList<T>> T valueOf​(Class<T> codeType,
                                                        CodeList.Filter filter)
        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 their is no match and CodeList.Filter.codename() returns null.
        Since:
        2.3
      • 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 leat 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 specification:
        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.
        Since:
        2.3
        Departure from OGC/ISO 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 specification:
        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.
        Since:
        2.2
        Departure from OGC/ISO 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 specification:
        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.