Class MostSpecificComparator

  • All Implemented Interfaces:
    Comparator<AccessSection>

    public final class MostSpecificComparator
    extends Object
    implements Comparator<AccessSection>
    Order the Ref Pattern by the most specific. This sort is done by:
    • 1 - The minor value of Levenshtein string distance between the branch name and the regex string shortest example. A shorter distance is a more specific match.
    • 2 - Finites first, infinities after.
    • 3 - Number of transitions. More transitions is more specific.
    • 4 - Length of the expression text.
    Levenshtein distance is a measure of the similarity between two strings. The distance is the number of deletions, insertions, or substitutions required to transform one string into another.

    For example, if given refs/heads/m* and refs/heads/*, the distances are 5 and 6. It means that refs/heads/m* is more specific because it's closer to refs/heads/master than refs/heads/*.

    Another example could be refs/heads/* and refs/heads/[a-zA-Z]*, the distances are both 6. Both are infinite, but refs/heads/[a-zA-Z]* has more transitions, which after all turns it more specific.