Package org.geotools.api.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>
- Direct Known Subclasses:
AxisDirection
,ColorInterpretation
,ContrastMethod
,Datatype
,EvaluationMethodType
,IndeterminateValue
,InterpolationMethod
,Obligation
,OnLineFunction
,PaletteInterpretation
,PixelInCell
,PixelOrientation
,PresentationForm
,RangeMeaning
,RelativePosition
,Role
,SampleDimensionType
,SemanticType
,SortOrder
,VerticalDatumType
public abstract class CodeList<E extends CodeList<E>> extends Object implements 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 list are extensible, i.e. invoking the public constructor in any subclass will automatically add the newly createdCodeList
element in the array to be returned byvalues()
.- Since:
- GeoAPI 1.0
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
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
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(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.int
hashCode()
String
identifier()
Returns the identifier declared in theUML
annotation, ornull
if none.boolean
matches(String name)
Returnstrue
if the given name matches the name, identifier or any other identification string of this code list element.String
name()
Returns the name of this code list constant.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>
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.
-
-
-
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 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 element of the given class wherematches(name)
returnedtrue
. If no such element is found, then a new instance is created using the constructor expecting a singleString
argument.- 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.- Returns:
- A code matching the given 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.- Returns:
- The position of this code constants in elements declaration.
-
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.- Returns:
- The ISO/OGC identifier for this code constant, or
null
if none. - Since:
- GeoAPI 2.2
-
name
public final String name()
Returns the name of this code list constant.- Returns:
- The name of this code constant.
-
matches
public boolean matches(String name)
Returnstrue
if the given name matches the name, identifier or any other identification string of this code list element. The comparison is case-insensitive.- Parameters:
name
- The name to check.- Returns:
true
if the given name matches the code name or identifier.- Since:
- GeoAPI 2.2
-
family
public abstract E[] family()
Returns the list of codes of the same kind than this code.- Returns:
- The codes of the same kind than this code.
-
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:
- -1 if the given code is less than this code, +1 if greater or 0 if equal.
-
equals
public final boolean equals(Object object)
Compares the specified object with this code list for equality. This method compares only ordinal values for consistency with thecompareTo(E)
method. Ordinal values are unique for each code list element of the same class.
-
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.
-
-