Top Description Inners Fields Constructors Methods
org.springframework.beans

public abstract Class PropertyMatches

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.beans.PropertyMatches.BeanPropertyMatches, org.springframework.beans.PropertyMatches.FieldPropertyMatches
Imports
java.beans.PropertyDescriptor, java.util.ArrayList, .Collections, .List, org.springframework.util.ObjectUtils, .ReflectionUtils, .StringUtils

Helper class for calculating property matches, according to a configurable distance. Provide the list of potential matches and an easy way to generate an error message. Works for both java bean properties and fields.

Mainly for use within the framework and in particular the binding facility.

Authors
Alef Arendsen, Arjen Poutsma, Juergen Hoeller, Stephane Nicoll
Since
2.0
See Also
forProperty(String, Class), forField(String, Class)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_MAX_DISTANCE

Default maximum property distance: 2.

private final String[]
private final String

Constructor Summary

AccessConstructor and Description
private
PropertyMatches(String propertyName, String[] possibleMatches)

Create a new PropertyMatches instance for the given property and possible matches.

Method Summary

Modifier and TypeMethod and Description
protected void
public abstract String
buildErrorMessage()

Build an error message for the given invalid property name, indicating the possible property matches.

private static int

Returns:

the distance value
calculateStringDistance
(String
the first String
s1
,
String
the second String
s2
)

Calculate the distance between the given two Strings according to the Levenshtein algorithm.

public static PropertyMatches
forField(String
the name of the field to find possible matches for
propertyName
,
Class<?>
the bean class to search for matches
beanClass
)

Create PropertyMatches for the given field property.

public static PropertyMatches
forField(String
the name of the field to find possible matches for
propertyName
,
Class<?>
the bean class to search for matches
beanClass
,
int
the maximum property distance allowed for matches
maxDistance
)

Create PropertyMatches for the given field property.

public static PropertyMatches
forProperty(String
the name of the property to find possible matches for
propertyName
,
Class<?>
the bean class to search for matches
beanClass
)

Create PropertyMatches for the given bean property.

public static PropertyMatches
forProperty(String
the name of the property to find possible matches for
propertyName
,
Class<?>
the bean class to search for matches
beanClass
,
int
the maximum property distance allowed for matches
maxDistance
)

Create PropertyMatches for the given bean property.

public String[]
getPossibleMatches()

Return the calculated possible matches.

public String
getPropertyName()

Return the name of the requested property.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MAX_DISTANCEback to summary
public static final int DEFAULT_MAX_DISTANCE

Default maximum property distance: 2.

possibleMatchesback to summary
private final String[] possibleMatches
propertyNameback to summary
private final String propertyName

Constructor Detail

PropertyMatchesback to summary
private PropertyMatches(String propertyName, String[] possibleMatches)

Create a new PropertyMatches instance for the given property and possible matches.

Method Detail

appendHintMessageback to summary
protected void appendHintMessage(StringBuilder msg)
buildErrorMessageback to summary
public abstract String buildErrorMessage()

Build an error message for the given invalid property name, indicating the possible property matches.

calculateStringDistanceback to summary
private static int calculateStringDistance(String s1, String s2)

Calculate the distance between the given two Strings according to the Levenshtein algorithm.

Parameters
s1:String

the first String

s2:String

the second String

Returns:int

the distance value

forFieldback to summary
public static PropertyMatches forField(String propertyName, Class<?> beanClass)

Create PropertyMatches for the given field property.

Parameters
propertyName:String

the name of the field to find possible matches for

beanClass:Class<?>

the bean class to search for matches

forFieldback to summary
public static PropertyMatches forField(String propertyName, Class<?> beanClass, int maxDistance)

Create PropertyMatches for the given field property.

Parameters
propertyName:String

the name of the field to find possible matches for

beanClass:Class<?>

the bean class to search for matches

maxDistance:int

the maximum property distance allowed for matches

forPropertyback to summary
public static PropertyMatches forProperty(String propertyName, Class<?> beanClass)

Create PropertyMatches for the given bean property.

Parameters
propertyName:String

the name of the property to find possible matches for

beanClass:Class<?>

the bean class to search for matches

forPropertyback to summary
public static PropertyMatches forProperty(String propertyName, Class<?> beanClass, int maxDistance)

Create PropertyMatches for the given bean property.

Parameters
propertyName:String

the name of the property to find possible matches for

beanClass:Class<?>

the bean class to search for matches

maxDistance:int

the maximum property distance allowed for matches

getPossibleMatchesback to summary
public String[] getPossibleMatches()

Return the calculated possible matches.

getPropertyNameback to summary
public String getPropertyName()

Return the name of the requested property.

org.springframework.beans back to summary

private Class PropertyMatches.BeanPropertyMatches

extends PropertyMatches
Class Inheritance

Field Summary

Inherited from org.springframework.beans.PropertyMatches:
DEFAULT_MAX_DISTANCE

Constructor Summary

AccessConstructor and Description
public
BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance)

Method Summary

Modifier and TypeMethod and Description
public String
buildErrorMessage()

Implements abstract org.springframework.beans.PropertyMatches.buildErrorMessage.

Build an error message for the given invalid property name, indicating the possible property matches.
private static String[]
calculateMatches(String name, PropertyDescriptor[]
the JavaBeans property descriptors to search
descriptors
,
int
the maximum distance to accept
maxDistance
)

Generate possible property alternatives for the given property and class.

Inherited from org.springframework.beans.PropertyMatches:
appendHintMessageforFieldforFieldforPropertyforPropertygetPossibleMatchesgetPropertyName

Constructor Detail

BeanPropertyMatchesback to summary
public BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance)

Method Detail

buildErrorMessageback to summary
public String buildErrorMessage()

Implements abstract org.springframework.beans.PropertyMatches.buildErrorMessage.

Doc from org.springframework.beans.PropertyMatches.buildErrorMessage.

Build an error message for the given invalid property name, indicating the possible property matches.

Annotations
@Override
calculateMatchesback to summary
private static String[] calculateMatches(String name, PropertyDescriptor[] descriptors, int maxDistance)

Generate possible property alternatives for the given property and class. Internally uses the getStringDistance method, which in turn uses the Levenshtein algorithm to determine the distance between two Strings.

Parameters
descriptors:PropertyDescriptor[]

the JavaBeans property descriptors to search

maxDistance:int

the maximum distance to accept

org.springframework.beans back to summary

private Class PropertyMatches.FieldPropertyMatches

extends PropertyMatches
Class Inheritance

Field Summary

Inherited from org.springframework.beans.PropertyMatches:
DEFAULT_MAX_DISTANCE

Constructor Summary

AccessConstructor and Description
public
FieldPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance)

Method Summary

Modifier and TypeMethod and Description
public String
buildErrorMessage()

Implements abstract org.springframework.beans.PropertyMatches.buildErrorMessage.

Build an error message for the given invalid property name, indicating the possible property matches.
private static String[]
calculateMatches(final String name, Class<?> clazz, final int maxDistance)

Inherited from org.springframework.beans.PropertyMatches:
appendHintMessageforFieldforFieldforPropertyforPropertygetPossibleMatchesgetPropertyName

Constructor Detail

FieldPropertyMatchesback to summary
public FieldPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance)

Method Detail

buildErrorMessageback to summary
public String buildErrorMessage()

Implements abstract org.springframework.beans.PropertyMatches.buildErrorMessage.

Doc from org.springframework.beans.PropertyMatches.buildErrorMessage.

Build an error message for the given invalid property name, indicating the possible property matches.

Annotations
@Override
calculateMatchesback to summary
private static String[] calculateMatches(final String name, Class<?> clazz, final int maxDistance)