final class PropertyMatches
extends java.lang.Object
forProperty(String, Class)
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_DISTANCE
Default maximum property distance: 2
|
private java.lang.String[] |
possibleMatches |
private java.lang.String |
propertyName |
Modifier | Constructor and Description |
---|---|
private |
PropertyMatches(java.lang.String propertyName,
java.lang.Class beanClass,
int maxDistance)
Create a new PropertyMatches instance for the given property.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
buildErrorMessage()
Build an error message for the given invalid property name,
indicating the possible property matches.
|
private java.lang.String[] |
calculateMatches(java.beans.PropertyDescriptor[] propertyDescriptors,
int maxDistance)
Generate possible property alternatives for the given property and
class.
|
private int |
calculateStringDistance(java.lang.String s1,
java.lang.String s2)
Calculate the distance between the given two Strings
according to the Levenshtein algorithm.
|
static PropertyMatches |
forProperty(java.lang.String propertyName,
java.lang.Class beanClass)
Create PropertyMatches for the given bean property.
|
static PropertyMatches |
forProperty(java.lang.String propertyName,
java.lang.Class beanClass,
int maxDistance)
Create PropertyMatches for the given bean property.
|
java.lang.String[] |
getPossibleMatches()
Return the calculated possible matches.
|
public static final int DEFAULT_MAX_DISTANCE
private final java.lang.String propertyName
private java.lang.String[] possibleMatches
private PropertyMatches(java.lang.String propertyName, java.lang.Class beanClass, int maxDistance)
public static PropertyMatches forProperty(java.lang.String propertyName, java.lang.Class beanClass)
propertyName
- the name of the property to find possible matches forbeanClass
- the bean class to search for matchespublic static PropertyMatches forProperty(java.lang.String propertyName, java.lang.Class beanClass, int maxDistance)
propertyName
- the name of the property to find possible matches forbeanClass
- the bean class to search for matchesmaxDistance
- the maximum property distance allowed for matchespublic java.lang.String[] getPossibleMatches()
public java.lang.String buildErrorMessage()
private java.lang.String[] calculateMatches(java.beans.PropertyDescriptor[] propertyDescriptors, int maxDistance)
getStringDistance
method, which
in turn uses the Levenshtein algorithm to determine the distance between
two Strings.propertyDescriptors
- the JavaBeans property descriptors to searchmaxDistance
- the maximum distance to acceptprivate int calculateStringDistance(java.lang.String s1, java.lang.String s2)
s1
- the first Strings2
- the second String