mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 20:57:35 +01:00
Improved string utils class, added javaDocs
This commit is contained in:
parent
ab8eee3be9
commit
c156c988aa
@ -6,14 +6,23 @@ import net.ricecode.similarity.StringSimilarityServiceImpl;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* Get the difference of two strings.
|
||||
*
|
||||
* @param first First string.
|
||||
* @param second Second string.
|
||||
*
|
||||
* @return The difference value.
|
||||
*/
|
||||
public static double getDifference(String first, String second) {
|
||||
// Make sure the strings are valid.
|
||||
if(first == null || second == null)
|
||||
return 1.0;
|
||||
|
||||
// Create a string similarity service instance, to allow comparison
|
||||
StringSimilarityService service = new StringSimilarityServiceImpl(new LevenshteinDistanceStrategy());
|
||||
|
||||
double score = service.score(first, second);
|
||||
|
||||
return Math.abs(score - 1.0);
|
||||
// Determine the difference value, return the result
|
||||
return Math.abs(service.score(first, second) - 1.0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user