public final class Types extends Static
CodeList
values.
This class provides:
toInternationalString(CharSequence)
and toGenericName(Object, NameFactory)
for creating name-related objects from various objects.getStandardName(Class)
, getListName(CodeList)
and getCodeName(CodeList)
for fetching ISO names if possible.getCodeTitle(CodeList)
, getDescription(CodeList)
and
getDescription(Class)
for fetching human-readable descriptions.forStandardName(String)
and forCodeName(Class, String, boolean)
for
fetching an instance from a name (converse of above get
methods).Defined in the sis-utility module
Modifier and Type | Method and Description |
---|---|
static <T extends CodeList<T>> |
forCodeName(Class<T> codeType,
String name,
boolean canCreate)
Returns the code of the given type that matches the given name, or optionally returns a new
one if none match it.
|
static Class<?> |
forStandardName(String identifier)
Returns the GeoAPI interface for the given ISO name, or
null if none. |
static String |
getCodeLabel(CodeList<?> code)
Returns a unlocalized title for the given code.
|
static String |
getCodeName(CodeList<?> code)
Returns the ISO name (if available) or the Java name (as a fallback) of the given code.
|
static InternationalString |
getCodeTitle(CodeList<?> code)
Returns the title of the given code.
|
static <T extends CodeList<?>> |
getCodeValues(Class<T> codeType)
Returns all known values for the given type of code list.
|
static InternationalString |
getDescription(Class<?> type)
Returns a description for the given class, or
null if none. |
static InternationalString |
getDescription(Class<?> type,
String property)
Returns a description for the given property, or
null if none. |
static InternationalString |
getDescription(CodeList<?> code)
Returns the description of the given code, or
null if none. |
static String |
getListName(CodeList<?> code)
Returns the ISO classname (if available) or the Java classname (as a fallback)
of the given code.
|
static String |
getStandardName(Class<?> type)
Returns the ISO name for the given class, or
null if none. |
static GenericName[] |
toGenericNames(Object value,
NameFactory factory)
Converts the given value to an array of generic names.
|
static InternationalString |
toInternationalString(CharSequence string)
Returns the given characters sequence as an international string.
|
static InternationalString[] |
toInternationalStrings(CharSequence... strings)
Returns the given array of
CharSequence s as an array of InternationalString s. |
public static String getStandardName(Class<?> type)
null
if none.
This method can be used for GeoAPI interfaces or CodeList
.
Examples:
getStandardName(Citation.class)
(an interface) returns "CI_Citation"
.getStandardName(AxisDirection.class)
(a code list) returns "CS_AxisDirection"
.UML
annotation on the given type. It does not search for
parent classes or interfaces if the given type is not directly annotated (i.e. @UML
annotations are not inherited). If no annotation is found, then this method does not fallback
on the Java name since, as the name implies, this method is about standard names.type
- The GeoAPI interface or code list from which to get the ISO name, or null
.null
if none or if the given type is null
.forStandardName(String)
public static String getListName(CodeList<?> code)
UML
annotation if it exists, or
fallback on the simple class name otherwise.
Examples:
getListName(AxisDirection.NORTH)
returns "CS_AxisDirection"
.getListName(CharacterSet.UTF_8)
returns "MD_CharacterSetCode"
.getListName(ImagingCondition.BLURRED_IMAGE)
returns "MD_ImagingConditionCode"
.code
- The code for which to get the class name, or null
.null
if the given code is null.public static String getCodeName(CodeList<?> code)
UML
identifier, then the programmatic name is used as a fallback.
Examples:
getCodeName(AxisDirection.NORTH)
returns "north"
.getCodeName(CharacterSet.UTF_8)
returns "utf8"
.getCodeName(ImagingCondition.BLURRED_IMAGE)
returns "blurredImage"
.code
- The code for which to get the name, or null
.null
if the given code is null.getCodeLabel(CodeList)
,
getCodeTitle(CodeList)
,
getDescription(CodeList)
,
forCodeName(Class, String, boolean)
public static String getCodeLabel(CodeList<?> code)
getCodeTitle(CodeList)
instead.
The current heuristic implementation iterates over all code names, selects the longest one excluding the field name if possible, then makes a sentence from that name. Examples:
getCodeLabel(AxisDirection.NORTH)
returns "North"
.getCodeLabel(CharacterSet.UTF_8)
returns "UTF-8"
.getCodeLabel(ImagingCondition.BLURRED_IMAGE)
returns "Blurred image"
.code
- The code from which to get a title, or null
.null
if the given code is null.getCodeName(CodeList)
,
getCodeTitle(CodeList)
,
getDescription(CodeList)
public static InternationalString getCodeTitle(CodeList<?> code)
code
- The code for which to get the title, or null
.null
if the given code is null.getDescription(CodeList)
public static InternationalString getDescription(CodeList<?> code)
null
if none.
For a description of the code list as a whole instead than a particular code,
see getDescription(Class)
.code
- The code for which to get the localized description, or null
.null
if none or if the given code is null.getCodeTitle(CodeList)
,
getDescription(Class)
public static InternationalString getDescription(Class<?> type)
null
if none.
This method can be used for GeoAPI interfaces or CodeList
.type
- The GeoAPI interface or code list from which to get the description, or null
.null
if none or if the given type is null
.getDescription(CodeList)
public static InternationalString getDescription(Class<?> type, String property)
null
if none.
The given type shall be a GeoAPI interface, and the given property shall
be a UML identifier. If any of the input argument is null
, then
this method returns null
.type
- The GeoAPI interface from which to get the description of a property, or null
.property
- The ISO name of the property for which to get the description, or null
.null
if none or if the given type or property name is null
.public static <T extends CodeList<?>> T[] getCodeValues(Class<T> codeType)
T
- The compile-time type given as the codeType
parameter.codeType
- The type of code list.public static Class<?> forStandardName(String identifier)
null
if none.
The identifier argument shall be the value documented in the UML.identifier()
annotation associated with the GeoAPI interface.
Examples:
forStandardName("CI_Citation")
returns Citation.class
forStandardName("CS_AxisDirection")
returns AxisDirection.class
geoapi-pending
module.identifier
- The ISO UML identifier, or null
.null
if the given identifier is null
or unknown.public static <T extends CodeList<T>> T forCodeName(Class<T> codeType, String name, boolean canCreate)
valueOf(…)
method, except that this method is more tolerant on string comparisons when looking for an
existing code:
'_'
and '-'
are ignored.canCreate
argument is
true
. Otherwise this method returns null
.T
- The compile-time type given as the codeType
parameter.codeType
- The type of code list.name
- The name of the code to obtain, or null
.canCreate
- true
if this method is allowed to create new code.null
if the name is null
or if no matching code is found and canCreate
is false
.CodeList.valueOf(Class, String)
public static InternationalString toInternationalString(CharSequence string)
InternationalString
, this this method returns it unchanged.
Otherwise, this method copies the InternationalString.toString()
value in a new
SimpleInternationalString
instance and returns it.string
- The characters sequence to convert, or null
.null
if the given sequence was null.DefaultNameFactory.createInternationalString(Map)
public static InternationalString[] toInternationalStrings(CharSequence... strings)
CharSequence
s as an array of InternationalString
s.
If the given array is null or an instance of InternationalString[]
, then this method
returns it unchanged. Otherwise a new array of type InternationalString[]
is created
and every elements from the given array is copied or
converted in the new array.
If a defensive copy of the strings
array is wanted, then the caller needs to check
if the returned array is the same instance than the one given in argument to this method.
strings
- The characters sequences to convert, or null
.InternationalString[]
,
or null
if the given array was null.public static GenericName[] toGenericNames(Object value, NameFactory factory) throws ClassCastException
GenericName
, String
or any other type enumerated below, then it is converted
and returned in an array of length 1. If the given value is an array or a collection, then an
array of same length is returned where each element has been converted.
Allowed types or element types are:
GenericName
, to be casted and returned as-is.CharSequence
(usually a String
or an InternationalString
),
to be parsed as a generic name using the
58 separator.Identifier
, its code to be parsed as a generic name
using the 58 separator.value
is an array or a collection containing null
elements,
then the corresponding element in the returned array will also be null
.value
- The object to cast into an array of generic names, or null
.factory
- The factory to use for creating names, or null
for the default.null
if the given value
was null.
Note that it may be the value
reference itself casted to GenericName[]
.ClassCastException
- if value
can't be casted.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.