Package com.google.gerrit.server.util
Class MostSpecificComparator
- java.lang.Object
-
- com.google.gerrit.server.util.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.
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.
-
-
Constructor Summary
Constructors Constructor Description MostSpecificComparator(String refName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(AccessSection a, AccessSection b)
int
compare(String pattern1, String pattern2)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Constructor Detail
-
MostSpecificComparator
public MostSpecificComparator(String refName)
-
-
Method Detail
-
compare
public int compare(AccessSection a, AccessSection b)
- Specified by:
compare
in interfaceComparator<AccessSection>
-
-