Package: org.codehaus.groovy.runtime

## [Java] Class MethodRankHelper

- org.codehaus.groovy.runtime.MethodRankHelper

-     public class MethodRankHelper
      extends Object

  Utility class for MissingMethodException, MissingPropertyException, etc. Contains methods for assisting in ranking and listing probable intended methods/fields when an exception is thrown.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static int` | `DL_CASE` | Cost for case change in Damerau-Levenshtein distance calculation.
    `static int` | `DL_DELETE` |
    `static int` | `DL_SUBSTITUTION` | Cost for substitution in Damerau-Levenshtein distance calculation.
    `static int` | `DL_TRANSPOSITION` | Cost for transposition in Damerau-Levenshtein distance calculation.
    `static int` | `MAX_CONSTRUCTOR_SCORE` | Maximum score threshold for constructor ranking.
    `static int` | `MAX_FIELD_SCORE` | Maximum score threshold for field ranking.
    `static int` | `MAX_METHOD_SCORE` | Maximum score threshold for method ranking.
    `static int` | `MAX_RECOMENDATIONS` | Maximum number of method recommendations to suggest.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected static Class` | `boxVar(Class c)` If c is a primitive class this method returns a boxed version otherwise c is returned.
    `` | `public static int` | `damerauLevenshteinDistance(Object[] s, Object[] t)` This is an implementation of DL distance between two Object arrays instead of character streams.
    `` | `public static int` | `delDistance(CharSequence s, CharSequence t)` This is a slightly modified version of the Damerau Levenshtein distance algorithm.
    `` | `public static String` | `getConstructorSuggestionString(Class type, Object[] arguments)` Returns a string detailing possible solutions to a missing constructor if no good solutions can be found an empty string is returned.
    `` | `public static String` | `getMethodSuggestionString(String methodName, Class type, Object[] arguments)` Returns a string detailing possible solutions to a missing method if no good solutions can be found an empty string is returned.
    `` | `public static String` | `getPropertySuggestionString(String name, Class type)` Returns a string detailing possible solutions to a missing field/property if no good solutions can be found an empty string is returned.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final int DL_CASE

      Cost for case change in Damerau-Levenshtein distance calculation.

    - #### public static final int DL_DELETE

    - #### public static final int DL_SUBSTITUTION

      Cost for substitution in Damerau-Levenshtein distance calculation.

    - #### public static final int DL_TRANSPOSITION

      Cost for transposition in Damerau-Levenshtein distance calculation.

    - #### public static final int MAX_CONSTRUCTOR_SCORE

      Maximum score threshold for constructor ranking.

    - #### public static final int MAX_FIELD_SCORE

      Maximum score threshold for field ranking.

    - #### public static final int MAX_METHOD_SCORE

      Maximum score threshold for method ranking.

    - #### public static final int MAX_RECOMENDATIONS

      Maximum number of method recommendations to suggest.

  - ### Method Detail

    - #### protected static Class boxVar(Class c)

      If c is a primitive class this method returns a boxed version otherwise c is returned. In java 1.5 this can be simplified thanks to the Type class.

      Parameters:
        c
      Returns:
        a boxed version of c if c can be boxed, else c

    - #### public static int damerauLevenshteinDistance(Object[] s, Object[] t)

      This is an implementation of DL distance between two Object arrays instead of character streams. The objects are compared using their equals method. No objects may be null. This implementation is based on Chas Emerick's implementation of Levenshtein Distance for jakarta commons.

      Parameters:
        `s` - an Object array
        `t` - this array is compared to s
      Returns:
        the edit distance between the two arrays

    - #### public static int delDistance(CharSequence s, CharSequence t)

      This is a slightly modified version of the Damerau Levenshtein distance algorithm. It has an additional test to see if a character has switched case, in the original algorithm this counts as a substitution. The "cost" for a substitution is given as 10 instead of 1 in this version, this enables transpositions and case modifications to have a lower cost than substitutions. Currently the lowercase versions of t_j and s_i isn't cached, its probable that some speed could be gained from this. This version is based on Chas Emerick's implementation of Levenshtein Distance for jakarta commons.

      Parameters:
        `s` - a CharSequence
        `t` - the CharSequence to be compared to s
      Returns:
        a value representing the edit distance between s and t

    - #### public static String getConstructorSuggestionString(Class type, Object[] arguments)

      Returns a string detailing possible solutions to a missing constructor if no good solutions can be found an empty string is returned.

      Parameters:
        `arguments` - the arguments passed to the constructor
        `type` - the class on which the constructor is invoked
      Returns:
        a string with probable solutions to the exception

    - #### public static String getMethodSuggestionString(String methodName, Class type, Object[] arguments)

      Returns a string detailing possible solutions to a missing method if no good solutions can be found an empty string is returned.

      Parameters:
        `methodName` - the name of the method that doesn't exist
        `type` - the class on which the method is invoked
        `arguments` - the arguments passed to the method
      Returns:
        a string with probable solutions to the exception

    - #### public static String getPropertySuggestionString(String name, Class type)

      Returns a string detailing possible solutions to a missing field/property if no good solutions can be found an empty string is returned.

      Parameters:
        `name` - the missing field/property
        `type` - the class on which the field is sought
      Returns:
        a string with probable solutions to the exception