Skip to content

Commit 3406d2c

Browse files
committed
Update JavaDoc to include throws for NPE
1 parent 75142c0 commit 3406d2c

15 files changed

+93
-59
lines changed

src/main/java/info/debatty/java/stringsimilarity/CharacterSubstitutionInterface.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
public interface CharacterSubstitutionInterface {
3838
/**
3939
* Indicate the cost of substitution c1 and c2.
40-
* @param c1
41-
* @param c2
42-
* @return
40+
* @param c1 The first character of the substitution.
41+
* @param c2 The second character of the substitution.
42+
* @return The cost in the range [0, 1].
4343
*/
4444
double cost(char c1, char c2);
4545
}

src/main/java/info/debatty/java/stringsimilarity/Cosine.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public Cosine() {
6565

6666
/**
6767
* Compute the cosine similarity between strings.
68-
* @param s1
69-
* @param s2
70-
* @return
68+
* @param s1 The first string to compare.
69+
* @param s2 The second string to compare.
70+
* @return The cosine similarity in the range [0, 1]
71+
* @throws NullPointerException if s1 or s2 is null.
7172
*/
7273
public final double similarity(final String s1, final String s2) {
7374
if (s1 == null) {
@@ -137,9 +138,10 @@ private static double dotProduct(
137138

138139
/**
139140
* Return 1.0 - similarity.
140-
* @param s1
141-
* @param s2
142-
* @return
141+
* @param s1 The first string to compare.
142+
* @param s2 The second string to compare.
143+
* @return 1.0 - the cosine similarity in the range [0, 1]
144+
* @throws NullPointerException if s1 or s2 is null.
143145
*/
144146
public final double distance(final String s1, final String s2) {
145147
return 1.0 - similarity(s1, s2);

src/main/java/info/debatty/java/stringsimilarity/Damerau.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public class Damerau implements MetricStringDistance {
5050
* needed to transform one string into the other (insertion, deletion,
5151
* substitution of a single character, or a transposition of two adjacent
5252
* characters).
53-
* @param s1
54-
* @param s2
55-
* @return
53+
* @param s1 The first string to compare.
54+
* @param s2 The second string to compare.
55+
* @return The computed distance.
56+
* @throws NullPointerException if s1 or s2 is null.
5657
*/
5758
public final double distance(final String s1, final String s2) {
5859

src/main/java/info/debatty/java/stringsimilarity/Jaccard.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ public Jaccard() {
6969
}
7070

7171
/**
72-
* Compute jaccard index: |A inter B| / |A union B|.
73-
* @param s1
74-
* @param s2
75-
* @return
72+
* Compute Jaccard index: |A inter B| / |A union B|.
73+
* @param s1 The first string to compare.
74+
* @param s2 The second string to compare.
75+
* @return The Jaccard index in the range [0, 1]
76+
* @throws NullPointerException if s1 or s2 is null.
7677
*/
7778
public final double similarity(final String s1, final String s2) {
7879
if (s1 == null) {
@@ -108,9 +109,10 @@ public final double similarity(final String s1, final String s2) {
108109

109110
/**
110111
* Distance is computed as 1 - similarity.
111-
* @param s1
112-
* @param s2
113-
* @return
112+
* @param s1 The first string to compare.
113+
* @param s2 The second string to compare.
114+
* @return 1 - the Jaccard similarity.
115+
* @throws NullPointerException if s1 or s2 is null.
114116
*/
115117
public final double distance(final String s1, final String s2) {
116118
return 1.0 - similarity(s1, s2);

src/main/java/info/debatty/java/stringsimilarity/JaroWinkler.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public final double getThreshold() {
5555
}
5656

5757
/**
58-
* Compute JW similarity.
59-
* @param s1
60-
* @param s2
61-
* @return
58+
* Compute Jaro-Winkler similarity.
59+
* @param s1 The first string to compare.
60+
* @param s2 The second string to compare.
61+
* @return The Jaro-Winkler similarity in the range [0, 1]
62+
* @throws NullPointerException if s1 or s2 is null.
6263
*/
6364
public final double similarity(final String s1, final String s2) {
6465
if (s1 == null) {
@@ -91,9 +92,10 @@ public final double similarity(final String s1, final String s2) {
9192

9293
/**
9394
* Return 1 - similarity.
94-
* @param s1
95-
* @param s2
96-
* @return
95+
* @param s1 The first string to compare.
96+
* @param s2 The second string to compare.
97+
* @return 1 - similarity.
98+
* @throws NullPointerException if s1 or s2 is null.
9799
*/
98100
public final double distance(final String s1, final String s2) {
99101
return 1.0 - similarity(s1, s2);

src/main/java/info/debatty/java/stringsimilarity/Levenshtein.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ public class Levenshtein implements MetricStringDistance {
3333
* only 2 rows of data. The space requirement is thus O(m) and the algorithm
3434
* runs in O(mn).
3535
*
36-
* @param s1
37-
* @param s2
38-
* @return
36+
* @param s1 The first string to compare.
37+
* @param s2 The second string to compare.
38+
* @return The computed Levenshtein distance.
39+
* @throws NullPointerException if s1 or s2 is null.
3940
*/
4041
public final double distance(final String s1, final String s2) {
4142
if (s1 == null) {

src/main/java/info/debatty/java/stringsimilarity/LongestCommonSubsequence.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ public class LongestCommonSubsequence implements StringDistance {
3030
* Return the LCS distance between strings s1 and s2, computed as |s1| +
3131
* |s2| - 2 * |LCS(s1, s2)|.
3232
*
33-
* @param s1
34-
* @param s2
33+
* @param s1 The first string to compare.
34+
* @param s2 The second string to compare.
3535
* @return the LCS distance between strings s1 and s2, computed as |s1| +
3636
* |s2| - 2 * |LCS(s1, s2)|
37+
* @throws NullPointerException if s1 or s2 is null.
3738
*/
3839
public final double distance(final String s1, final String s2) {
3940
if (s1 == null) {
@@ -55,11 +56,20 @@ public final double distance(final String s1, final String s2) {
5556
* Return the length of Longest Common Subsequence (LCS) between strings s1
5657
* and s2.
5758
*
58-
* @param s1
59-
* @param s2
59+
* @param s1 The first string to compare.
60+
* @param s2 The second string to compare.
6061
* @return the length of LCS(s1, s2)
62+
* @throws NullPointerException if s1 or s2 is null.
6163
*/
6264
public final int length(final String s1, final String s2) {
65+
if (s1 == null) {
66+
throw new NullPointerException("s1 must not be null");
67+
}
68+
69+
if (s2 == null) {
70+
throw new NullPointerException("s2 must not be null");
71+
}
72+
6373
/* function LCSLength(X[1..m], Y[1..n])
6474
C = array(0..m, 0..n)
6575

src/main/java/info/debatty/java/stringsimilarity/MetricLCS.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public class MetricLCS
4444
* Distance metric based on Longest Common Subsequence, computed as
4545
* 1 - |LCS(s1, s2)| / max(|s1|, |s2|).
4646
*
47-
* @param s1
48-
* @param s2
49-
* @return
47+
* @param s1 The first string to compare.
48+
* @param s2 The second string to compare.
49+
* @return The computed distance metric value.
50+
* @throws NullPointerException if s1 or s2 is null.
5051
*/
5152
public final double distance(final String s1, final String s2) {
5253
if (s1 == null) {
@@ -69,5 +70,4 @@ public final double distance(final String s1, final String s2) {
6970
- (1.0 * lcs.length(s1, s2))
7071
/ mLen;
7172
}
72-
7373
}

src/main/java/info/debatty/java/stringsimilarity/NGram.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public NGram() {
3737

3838
/**
3939
* Compute n-gram distance.
40-
* @param s0
41-
* @param s1
42-
* @return
40+
* @param s0 The first string to compare.
41+
* @param s1 The second string to compare.
42+
* @return The computed n-gram distance in the range [0, 1]
43+
* @throws NullPointerException if s0 or s1 is null.
4344
*/
4445
public final double distance(final String s0, final String s1) {
4546
if (s0 == null) {

src/main/java/info/debatty/java/stringsimilarity/NormalizedLevenshtein.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public class NormalizedLevenshtein implements
4343

4444
/**
4545
* Compute distance as Levenshtein(s1, s2) / max(|s1|, |s2|).
46-
* @param s1
47-
* @param s2
48-
* @return
46+
* @param s1 The first string to compare.
47+
* @param s2 The second string to compare.
48+
* @return The computed distance in the range [0, 1]
49+
* @throws NullPointerException if s1 or s2 is null.
4950
*/
5051
public final double distance(final String s1, final String s2) {
5152

@@ -72,9 +73,10 @@ public final double distance(final String s1, final String s2) {
7273

7374
/**
7475
* Return 1 - distance.
75-
* @param s1
76-
* @param s2
77-
* @return
76+
* @param s1 The first string to compare.
77+
* @param s2 The second string to compare.
78+
* @return 1.0 - the computed distance
79+
* @throws NullPointerException if s1 or s2 is null.
7880
*/
7981
public final double similarity(final String s1, final String s2) {
8082
return 1.0 - distance(s1, s2);

0 commit comments

Comments
 (0)