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
-
Constructor Summary
ModifierConstructorDescriptionprotected
CodeList
(String name, Collection<E> values) Creates a new code list element and add it to the given collection. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Compares this code with the specified object for order.abstract E[]
family()
Returns the list of codes of the same kind than this code.Returns the identifier declared in theUML
annotation, ornull
if none.final String
name()
Returns the programmatic name of this code list constant.String[]
names()
Returns all the names of this code.final int
ordinal()
Returns the ordinal of this code constant.protected Object
Resolves the code list to an unique instance after deserialization.toString()
Returns a string representation of this code list.static <T extends CodeList<T>>
TReturns 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>>
TReturns 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>>
TvalueOf
(Class<T> codeType, CodeList.Filter filter) Deprecated.Since deprecation ofCodeList.Filter
, replaced byvalueOf(Class, Predicate, String)
.
-
Constructor Details
-
CodeList
Creates a new code list element and add it to the given collection. Subclasses will typically give a static reference to anArrayList
for thevalues
argument. This list is used forvalues()
method implementations.- Parameters:
name
- the code name.values
- the collection to add the element to.- Throws:
IllegalArgumentException
- ifvalues
is not the same collection than the one specified for previous instances of the same code list class.
-
-
Method Details
-
valueOf
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 whichname().equals(name)
istrue
. If no such instance is found, then a new instance is created using the constructor expecting a singleString
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 thecodeType
parameter.- Parameters:
codeType
- the type of code list.name
- the name of the code to obtain, ornull
.- 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 JavaEnum
class.
-
valueOf
@Deprecated public static <T extends CodeList<T>> T valueOf(Class<T> codeType, CodeList.Filter filter) Deprecated.Since deprecation ofCodeList.Filter
, replaced byvalueOf(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 wherefilter.accept(code)
returnstrue
. If no such element is found, then there is a choice:- If
CodeList.Filter.codename()
returnsnull
, then this method returnsnull
. - Otherwise a new instance is created using the constructor expecting a single
String
argument, which is given the value returned bycodename()
.
- Type Parameters:
T
- the compile-time type given as thecodeType
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 andCodeList.Filter.codename()
returnsnull
.
- If
-
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 wherefilter.test(code)
returnstrue
. If no such element is found, then there is a choice:- If
nameIfNew
isnull
, then this method returnsnull
. - Otherwise a new instance is created using the constructor expecting a single
String
argument, which is given thenameIfNew
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 thecodeType
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, ornull
for not creating any new code list.- Returns:
- a code matching the given criterion, or
null
if none andnameIfNew
is null. - Since:
- 3.1
- If
-
family
Returns the list of codes of the same kind than this code. Invoking this method gives identical results than invoking the staticvalues()
methods provided inCodeList
subclasses, except thatfamily()
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 interfaceControlledVocabulary
- 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 withEnum.family()
, which was defined in a initial draft of Java 5 before the final release.
-
names
Returns all the names of this code. The returned array contains the following elements, with duplicated values and null values removed:- The programmatic name
- The UML identifier
- Any other special case, if any. Examples:
- The legacy name of
Restriction.LICENCE
. - The alternative name of
PixelInCell.CELL_CENTER
.
- The legacy name of
'-'
.- Specified by:
names
in interfaceControlledVocabulary
- 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 eachCodeList
has at least two names, the Java programmatic name and the UML identifier, while some subclasses have additional names.
-
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 interfaceControlledVocabulary
- 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 JavaEnum
class.
-
identifier
Returns the identifier declared in theUML
annotation, ornull
if none. The UML identifier shall be the ISO or OGC name for this code constant.- Specified by:
identifier
in interfaceControlledVocabulary
- 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 eachCodeList
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 interfaceControlledVocabulary
- 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 JavaEnum
class.
-
compareTo
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 interfaceComparable<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
Returns a string representation of this code list. -
readResolve
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.
-
Predicate
from the standard Java library.