org.springframework.beans
Class PropertyMatches

java.lang.Object
  extended by org.springframework.beans.PropertyMatches

final class PropertyMatches
extends java.lang.Object

Helper class for calculating bean property matches, according to. Used by BeanWrapperImpl to suggest alternatives for an invalid property name.

Since:
2.0
Author:
Alef Arendsen, Arjen Poutsma, Juergen Hoeller
See Also:
forProperty(String, Class)

Field Summary
static int DEFAULT_MAX_DISTANCE
          Default maximum property distance: 2
private  java.lang.String[] possibleMatches
           
private  java.lang.String propertyName
           
 
Constructor Summary
private PropertyMatches(java.lang.String propertyName, java.lang.Class beanClass, int maxDistance)
          Create a new PropertyMatches instance for the given property.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_DISTANCE

public static final int DEFAULT_MAX_DISTANCE
Default maximum property distance: 2

See Also:
Constant Field Values

propertyName

private final java.lang.String propertyName

possibleMatches

private java.lang.String[] possibleMatches
Constructor Detail

PropertyMatches

private PropertyMatches(java.lang.String propertyName,
                        java.lang.Class beanClass,
                        int maxDistance)
Create a new PropertyMatches instance for the given property.

Method Detail

forProperty

public static PropertyMatches forProperty(java.lang.String propertyName,
                                          java.lang.Class beanClass)
Create PropertyMatches for the given bean property.

Parameters:
propertyName - the name of the property to find possible matches for
beanClass - the bean class to search for matches

forProperty

public static PropertyMatches forProperty(java.lang.String propertyName,
                                          java.lang.Class beanClass,
                                          int maxDistance)
Create PropertyMatches for the given bean property.

Parameters:
propertyName - the name of the property to find possible matches for
beanClass - the bean class to search for matches
maxDistance - the maximum property distance allowed for matches

getPossibleMatches

public java.lang.String[] getPossibleMatches()
Return the calculated possible matches.


buildErrorMessage

public java.lang.String buildErrorMessage()
Build an error message for the given invalid property name, indicating the possible property matches.


calculateMatches

private java.lang.String[] calculateMatches(java.beans.PropertyDescriptor[] propertyDescriptors,
                                            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:
propertyDescriptors - the JavaBeans property descriptors to search
maxDistance - the maximum distance to accept

calculateStringDistance

private int calculateStringDistance(java.lang.String s1,
                                    java.lang.String s2)
Calculate the distance between the given two Strings according to the Levenshtein algorithm.

Parameters:
s1 - the first String
s2 - the second String
Returns:
the distance value