Package org.opengis.util
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
,Context
,CouplingType
,CoverageContentType
,Datatype
,DateType
,DimensionNameType
,DistributedComputingPlatform
,EvaluationMethodType
,GeometricObjectType
,GeometryType
,ImagingCondition
,InitiativeType
,KeywordType
,MaintenanceFrequency
,MediumFormat
,MediumName
,ObjectiveType
,Obligation
,OnLineFunction
,OperationType
,PixelInCell
,PixelOrientation
,PolarizationOrientation
,PresentationForm
,Priority
,Progress
,RangeMeaning
,ReferenceSystemType
,Restriction
,Role
,ScopeCode
,Sequence
,SpatialRepresentationType
,TelephoneType
,TopicCategory
,TopologyLevel
,TransferFunctionType
,Trigger
,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 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
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CodeList.Filter
Deprecated.Replaced byPredicate
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 int
compareTo(E other)
Compares this code with the specified object for order.abstract E[]
family()
Returns the list of codes of the same kind than this code.String
identifier()
Returns the identifier declared in theUML
annotation, ornull
if none.String
name()
Returns the programmatic name of this code list constant.String[]
names()
Returns all the names of this code.int
ordinal()
Returns the ordinal of this code constant.protected Object
readResolve()
Resolves the code list to an unique instance after deserialization.String
toString()
Returns a string representation of this code list.static <T extends CodeList<T>>
TvalueOf(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>>
TvalueOf(Class<T> codeType, Predicate<CodeList<?>> filter, String nameIfNew)
Returns the code of the given type that matches the given criterion, or potentially 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 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 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(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 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 specification:
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 potentially 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
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 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 specification:
Provided by analogy withEnum.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:- 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 specification:
Defined because eachCodeList
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 interfaceControlledVocabulary
- Returns:
- the name of this code constant.
Departure from OGC/ISO specification:
Provided by analogy with the methods in the JavaEnum
class.
-
identifier
public 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.- Specified by:
identifier
in interfaceControlledVocabulary
- Returns:
- the ISO/OGC identifier for this code constant, or
null
if none.
Departure from OGC/ISO 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 specification:
Provided by analogy with the methods in the JavaEnum
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 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
public String toString()
Returns a string representation of this code list.
-
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.
-
-