From c156c988aa21ab54ef9a4e9c072f5e710627cca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 15:40:15 +0100 Subject: [PATCH] Improved string utils class, added javaDocs --- .../java/fr/xephi/authme/util/StringUtils.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index 92b14c5c..eab7ea15 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -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); } }