Package org.apache.sis.metadata
Class PropertyComparator
java.lang.Object
org.apache.sis.metadata.PropertyComparator
- All Implemented Interfaces:
Comparator<Method>
The comparator for sorting the properties in a metadata object.
Since the comparator uses (among other criteria) the property names, this class
incidentally defines static methods for inferring those names from the methods.
This comparator uses the following criteria, in priority order:
- Deprecated properties are last.
- If the property order is specified by a
XmlType
annotation, then this comparator complies to that order. - Otherwise this comparator sorts mandatory methods first, followed by conditional methods, then optional ones.
- If the order cannot be inferred from the above, then the comparator fallbacks on alphabetical order.
- Since:
- 0.3
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
The prefix for getters (general case).private final Class<?>
The implementation class, or the interface is the implementation class is unknown.private static final String
The prefix for getters on boolean values.Methods and property names specified in theXmlType
annotation.(package private) static final String
The prefix for setters. -
Constructor Summary
ConstructorsConstructorDescriptionPropertyComparator
(Class<?> implementation, Class<?> standardImpl) Creates a new comparator for the given implementation class. -
Method Summary
Modifier and TypeMethodDescriptionint
Compares the given methods for order.private static void
defineOrder
(Class<?> implementation, Map<Object, Integer> order) Uses theXmlType
annotation for defining the property order.private int
Returns the index of the given method, or -1 if the method is not found.private static boolean
Returnstrue
if the specified string starting at the specified index contains no lower case characters.(package private) static boolean
isDeprecated
(Class<?> implementation, Method method) Returnstrue
if the given method is deprecated, either in the interface that declare the method or in the implementation class.private static int
order
(org.opengis.annotation.UML uml) Returns a higher number for obligation which should be first.(package private) static String
Returns the prefix of the specified method name.(package private) static String
toPropertyName
(String name, int base) Removes the"get"
or"is"
prefix and turn the first character after the prefix into lower case.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
IS
The prefix for getters on boolean values.- See Also:
-
GET
The prefix for getters (general case).- See Also:
-
SET
The prefix for setters.- See Also:
-
order
Methods and property names specified in theXmlType
annotation. Entries description:- Keys in this map are either
String
orMethod
instances:String
keys property names as given byXmlType.propOrder()
. They are computed at construction time and do not change after construction.Method
keys will be added after construction, only as needed.
- Key is associated to an index that specify its position in descending order. For example, the property associated to integer 0 shall be sorted last. This descending order is only an implementation convenience.
- Keys in this map are either
-
implementation
The implementation class, or the interface is the implementation class is unknown.
-
-
Constructor Details
-
PropertyComparator
Creates a new comparator for the given implementation class.- Parameters:
implementation
- the implementation class, or the interface if the implementation class is unknown.standardImpl
- the implementation specified by theMetadataStandard
, ornull
if none. This is the same thanimplementation
unless a custom implementation is used.
-
-
Method Details
-
defineOrder
Uses theXmlType
annotation for defining the property order.- Parameters:
implementation
- the implementation class where to search forXmlType
annotation.order
- theorder
map where to store the properties order.
-
isDeprecated
Returnstrue
if the given method is deprecated, either in the interface that declare the method or in the implementation class. A method may be deprecated in the implementation but not in the interface when the implementation has been updated for a new standard, while the interface is still reflecting the old standard.- Parameters:
implementation
- the implementation class, or the interface is the implementation class is unknown.method
- the method to check for deprecation.- Returns:
true
if the method is deprecated.
-
compare
Compares the given methods for order.- Specified by:
compare
in interfaceComparator<Method>
-
order
private static int order(org.opengis.annotation.UML uml) Returns a higher number for obligation which should be first. -
indexOf
Returns the index of the given method, or -1 if the method is not found. If positive, the index returned by this method correspond to a sorting in descending order. -
prefix
Returns the prefix of the specified method name. If the method name doesn't starts with a prefix (for exampleConformanceResult.pass()
), then this method returns an empty string. -
isAcronym
Returnstrue
if the specified string starting at the specified index contains no lower case characters. The characters don't have to be in upper case however (e.g. non-alphabetic characters) -
toPropertyName
Removes the"get"
or"is"
prefix and turn the first character after the prefix into lower case. For example, the method name"getTitle"
will be replaced by the property name"title"
. We will perform this operation only if there is at least 1 character after the prefix.- Parameters:
name
- the method name (cannot benull
).base
- must be the result ofprefix(name).length()
.- Returns:
- the property name (never
null
).
-