public final class Types extends Static
CodeList
values.
This class provides:
getStandardName(Class)
for ISO namegetListName(CodeList)
for ISO namegetDescription(Class)
for a descriptiongetCodeName(CodeList)
for ISO name,getCodeTitle(CodeList)
for a label or titlegetDescription(CodeList)
for a more verbose descriptionget
methods):CodeList
value.
<gmi:type>
value is normally a <gco:CharacterString>
but has been replaced by a SensorType
code below:
<gmi:MI_Instrument> <gmi:type> <gmi:MI_SensorTypeCode codeList="http://navigator.eumetsat.int/metadata_schema/eum/resources/Codelist/eum_gmxCodelists.xml#CI_SensorTypeCode" codeListValue="RADIOMETER">Radiometer</gmi:MI_SensorTypeCode> </gmi:type> </gmi:MI_Instrument>
getCodeTitle(CodeList)
for getting the InternationalString
instance
to store in a metadata property.forCodeTitle(CharSequence)
for retrieving the CodeList
previously stored as an
InternationalString
.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 the name.
|
static CodeList<?> |
forCodeTitle(CharSequence title)
Returns the code list or enumeration value for the given title, or
null if none. |
static <T extends Enum<T>> |
forEnumName(Class<T> enumType,
String name)
Returns the enumeration value of the given type that matches the given name, or
null if none. |
static Class<?> |
forStandardName(String identifier)
Returns the Java type (usually a GeoAPI interface) for the given ISO name, or
null if none. |
static String |
getCodeLabel(CodeList<?> code)
Returns a unlocalized title for the given enumeration or code list value.
|
static String |
getCodeName(CodeList<?> code)
Returns the ISO name (if available) or the Java name (as a fallback) of the given enumeration or code list
value.
|
static InternationalString |
getCodeTitle(CodeList<?> code)
Returns the title of the given enumeration or code list value.
|
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 enumeration or code list value, 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
enumeration or code list value.
|
static String |
getStandardName(Class<?> type)
Returns the ISO name for the given class, or
null if none. |
static InternationalString |
toInternationalString(CharSequence string)
Returns the given characters sequence as an international string.
|
static InternationalString |
toInternationalString(Map<String,?> properties,
String prefix)
Returns an international string for the values in the given properties map, or
null if none. |
static InternationalString[] |
toInternationalStrings(CharSequence... strings)
Returns the given array of
CharSequence s as an array of InternationalString s. |
static String |
toString(InternationalString i18n,
Locale locale)
Returns the given international string in the given locale, or
null if the given string is null. |
public static String getStandardName(Class<?> type)
null
if none.
This method can be used for GeoAPI interfaces or CodeList
.
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.
getListName(ParameterDirection.IN_OUT)
returns "SV_ParameterDirection"
.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.
getCodeName(ParameterDirection.IN_OUT)
returns "in/out"
.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.
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)
The code or enumeration value given in argument to this method can be retrieved from the returned title
with the forCodeTitle(CharSequence)
method. See Substituting a free text by a code list
in this class javadoc for more information.
code
- the code for which to get the title, or null
.null
if the given code is null.getDescription(CodeList)
,
forCodeTitle(CharSequence)
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.Class.getEnumConstants()
public static Class<?> forStandardName(String identifier)
null
if none.
The identifier argument shall be the value documented in the UML.identifier()
annotation on
the Java type.
forStandardName("CI_Citation")
returns Citation.class
forStandardName("CS_AxisDirection")
returns AxisDirection.class
geoapi-pending
module.
forStandardName("CI_Individual")
returns
DefaultIndividual.class
in Apache SIS versions
that depend on GeoAPI 3.0, but the return type may be changed to Individual.class
when Apache SIS will
be upgraded to GeoAPI 3.1.identifier
- the ISO UML identifier, or null
.null
if the given identifier is null
or unknown.public static <T extends Enum<T>> T forEnumName(Class<T> enumType, String name)
null
if none.
This method is similar to the standard Enum.valueOf(…)
method, except that this method is more
tolerant on string comparisons:
'_'
and '-'
are ignored.null
— it does not thrown an exception,
unless the given class is not an enumeration.T
- the compile-time type given as the enumType
parameter.enumType
- the type of enumeration.name
- the name of the enumeration value to obtain, or null
.null
if the name is null
or if no matching enumeration is found.Enum.valueOf(Class, String)
public static <T extends CodeList<T>> T forCodeName(Class<T> codeType, String name, boolean canCreate)
CodeList.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
.getCodeName(CodeList)
,
CodeList.valueOf(Class, String)
public static CodeList<?> forCodeTitle(CharSequence title)
null
if none.
The current implementation performs the following choice:
getCodeTitle(CodeList)
,
returns the code or enumeration value used for creating that title.null
.title
- the title for which to get a code or enumeration value, or null
.null
.getCodeTitle(CodeList)
public static InternationalString toInternationalString(Map<String,?> properties, String prefix) throws IllegalArgumentException
null
if none.
This method is used when a property in a Map
may have many localized variants.
For example the given map may contains a "remarks"
property defined by values associated to
the "remarks_en"
and "remarks_fr"
keys, for English and French locales respectively.
If the given map is null
, then this method returns null
.
Otherwise this method iterates over the entries having a key that starts with the specified prefix,
followed by the '_'
character. For each such key:
prefix
, selects Locale.ROOT
.'_'
are parsed as an ISO language and country code
by the Locales.parse(String, int)
method. Note that 3-letters codes are replaced
by their 2-letters counterparts on a best effort basis.properties
- the map from which to get the string values for an international string, or null
.prefix
- the prefix of keys to use for creating the international string.null
if the given map is null or does not contain values
associated to keys starting with the given prefix.IllegalArgumentException
- if a key starts by the given prefix and:
Locale
code,CharSequence
.Locales.parse(String, int)
,
DefaultInternationalString.DefaultInternationalString(Map)
public static InternationalString toInternationalString(CharSequence string)
InternationalString
, then 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
casted 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 String toString(InternationalString i18n, Locale locale)
null
if the given string is null.
If the given locale is null
, then the i18n
default locale is used.i18n
- the international string to get as a localized string, or null
if none.locale
- the desired locale, or null
for the i18n
default locale.null
if i18n
is null
.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.