Class CodeList<E extends CodeList<E>>
- java.lang.Object
-
- org.opengis.util.CodeList<E>
-
- Type Parameters:
E
- The type of this code list.
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<E>
- Direct Known Subclasses:
AssociationType
,AxisDirection
,BandDefinition
,CellGeometry
,CharacterSet
,Classification
,Context
,CoverageContentType
,Datatype
,DateType
,DimensionNameType
,EvaluationMethodType
,GeometricObjectType
,GeometryType
,ImagingCondition
,InitiativeType
,KeywordType
,MaintenanceFrequency
,MediumFormat
,MediumName
,ObjectiveType
,Obligation
,OnLineFunction
,OperationType
,PixelInCell
,PixelOrientation
,PolarizationOrientation
,PresentationForm
,Priority
,Progress
,RangeMeaning
,Restriction
,Role
,ScopeCode
,Sequence
,SpatialRepresentationType
,TopicCategory
,TopologyLevel
,TransferFunctionType
,Trigger
,VerticalDatumType
@UML(identifier="CodeList", specification=ISO_19103) public abstract class CodeList<E extends CodeList<E>> extends java.lang.Object implements java.lang.Comparable<E>, java.io.Serializable
Base class for all code lists. Subclasses shall provides avalues()
method which returns allCodeList
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 createdCodeList
element in the array to be returned byvalues()
.- Since:
- 1.0
- Version:
- 3.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CodeList.Filter
Used byvalueOf(Class, Filter)
to select codes matching an arbitrary criterion.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<java.lang.String>[]
CONSTRUCTOR_PARAMETERS
The types expected in constructors.private java.lang.String
identifier
The identifier declared in theUML
annotation, or an empty string if there is no such annotation or if the annotation contains an empty string.private java.lang.String
name
The code name.private int
ordinal
The code value.private static long
serialVersionUID
Serial number for compatibility with different versions.private static java.util.Map<java.lang.Class<? extends CodeList>,java.util.Collection<? extends CodeList>>
VALUES
The values for each code list.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(E other)
Compares this code with the specified object for order.boolean
equals(java.lang.Object object)
Compares the specified object with this code list for equality.abstract E[]
family()
Returns the list of codes of the same kind than this code.java.lang.String
identifier()
Returns the identifier declared in theUML
annotation, ornull
if none.java.lang.String
name()
Returns the programmatic name of this code list constant.java.lang.String[]
names()
Returns all the names of this code.int
ordinal()
Returns the ordinal of this code constant.protected java.lang.Object
readResolve()
Resolves the code list to an unique instance after deserialization.java.lang.String
toString()
Returns a string representation of this code list.static <T extends CodeList<T>>
TvalueOf(java.lang.Class<T> codeType, java.lang.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>>
TvalueOf(java.lang.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.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serial number for compatibility with different versions.- See Also:
- Constant Field Values
-
VALUES
private static final java.util.Map<java.lang.Class<? extends CodeList>,java.util.Collection<? extends CodeList>> VALUES
The values for each code list.
-
CONSTRUCTOR_PARAMETERS
private static final java.lang.Class<java.lang.String>[] CONSTRUCTOR_PARAMETERS
The types expected in constructors.
-
ordinal
private final transient int ordinal
The code value.
-
name
private final java.lang.String name
The code name.
-
identifier
private transient java.lang.String identifier
The identifier declared in theUML
annotation, or an empty string if there is no such annotation or if the annotation contains an empty string. This field will be computed only when first needed.
-
-
Constructor Detail
-
CodeList
protected CodeList(java.lang.String name, java.util.Collection<E> values)
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.
-
-
Method Detail
-
valueOf
public static <T extends CodeList<T>> T valueOf(java.lang.Class<T> codeType, java.lang.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 element of the given class wherename().equals(name)
returnedtrue
. If no such element is found, then a new instance is created using the constructor expecting a singleString
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 thecodeType
class. However in other situations, callers may need to initialize explicitely the given class.- 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, or
null
if the name is null.
-
valueOf
public static <T extends CodeList<T>> T valueOf(java.lang.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 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 their is no match andCodeList.Filter.codename()
returnsnull
. - Since:
- 2.3
- If
-
family
public abstract E[] family()
Returns the list of codes of the same kind than this code. This is similar to the staticvalues()
method provided inCodeList
subclasses, except thatfamily()
does not require the class to be known at compile-time - provided that at leat one instance of the family is available. The staticvalues()
method has the opposite constraints (does not require a code instance, but the class needs to be known at compile time unless reflection is used).- Returns:
- The codes of the same kind than this code.
-
names
public java.lang.String[] 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
- The charset name
(
CharacterSet
code list only)
Those names are typically equal except for the case (programmatic names are upper case while UML names are lower case) and special characters like
'-'
.- Returns:
- All names of this code constant. This array is never null and never empty.
- Since:
- 2.3
-
name
public final java.lang.String name()
Returns the programmatic name of this code list constant. This is the name of the public static field which declare the code.- Returns:
- The name of this code constant.
-
identifier
public java.lang.String 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.- Returns:
- The ISO/OGC identifier for this code constant, or
null
if none. - Since:
- 2.2
-
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.- Returns:
- The position of this code constants in elements declaration.
-
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.
-
equals
public final boolean equals(java.lang.Object object)
Compares the specified object with this code list for equality. This method compares only ordinal values for consistency with thecompareTo(CodeList)
method. Ordinal values are unique for each code list element of the same class.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- The object to compare with this code.- Returns:
true
if the given object is equals to this code.- Since:
- 2.2
-
toString
public java.lang.String toString()
Returns a string representation of this code list.- Overrides:
toString
in classjava.lang.Object
-
readResolve
protected java.lang.Object readResolve() throws java.io.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:
java.io.ObjectStreamException
- if the deserialization failed.
-
-