2525using System ;
2626using System . Linq ;
2727using F23 . StringSimilarity . Interfaces ;
28+ // ReSharper disable SuggestVarOrType_Elsewhere
29+ // ReSharper disable LoopCanBeConvertedToQuery
2830
2931namespace F23 . StringSimilarity
3032{
@@ -38,9 +40,9 @@ namespace F23.StringSimilarity
3840 /// The distance is computed as 1 - Jaro-Winkler similarity.
3941 public class JaroWinkler : INormalizedStringSimilarity , INormalizedStringDistance
4042 {
41- private static readonly double DEFAULT_THRESHOLD = 0.7 ;
42- private static readonly int THREE = 3 ;
43- private static readonly double JW_COEF = 0.1 ;
43+ private const double DEFAULT_THRESHOLD = 0.7 ;
44+ private const int THREE = 3 ;
45+ private const double JW_COEF = 0.1 ;
4446
4547 /// <summary>
4648 /// The current value of the threshold used for adding the Winkler bonus. The default value is 0.7.
@@ -64,19 +66,30 @@ public JaroWinkler(double threshold)
6466 {
6567 Threshold = threshold ;
6668 }
67-
68- /**
69- * Compute JW similarity.
70- * @param s1
71- * @param s2
72- * @return
73- */
69+
70+ /// <summary>
71+ /// Compute Jaro-Winkler similarity.
72+ /// </summary>
73+ /// <param name="s1">The first string to compare.</param>
74+ /// <param name="s2">The second string to compare.</param>
75+ /// <returns>The Jaro-Winkler similarity in the range [0, 1]</returns>
76+ /// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
7477 public double Similarity ( string s1 , string s2 )
7578 {
76- if ( s1 == null ) s1 = string . Empty ;
77- if ( s2 == null ) s2 = string . Empty ;
79+ if ( s1 == null )
80+ {
81+ throw new ArgumentNullException ( nameof ( s1 ) ) ;
82+ }
7883
79- if ( string . Equals ( s1 , s2 ) ) return 1f ;
84+ if ( s2 == null )
85+ {
86+ throw new ArgumentNullException ( nameof ( s2 ) ) ;
87+ }
88+
89+ if ( s1 . Equals ( s2 ) )
90+ {
91+ return 1f ;
92+ }
8093
8194 int [ ] mtp = Matches ( s1 , s2 ) ;
8295 float m = mtp [ 0 ] ;
@@ -94,19 +107,20 @@ public double Similarity(string s1, string s2)
94107 }
95108 return jw ;
96109 }
97-
110+
98111 /// <summary>
99112 /// Return 1 - similarity.
100113 /// </summary>
101- /// <param name="s1"></param>
102- /// <param name="s2"></param>
114+ /// <param name="s1">The first string to compare. </param>
115+ /// <param name="s2">The second string to compare. </param>
103116 /// <returns>1 - similarity</returns>
117+ /// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
104118 public double Distance ( string s1 , string s2 )
105119 => 1.0 - Similarity ( s1 , s2 ) ;
106120
107121 private int [ ] Matches ( string s1 , string s2 )
108122 {
109- String max , min ;
123+ string max , min ;
110124 if ( s1 . Length > s2 . Length )
111125 {
112126 max = s1 ;
0 commit comments