Skip to content

Commit 61ec6fd

Browse files
TheRealHauiTheRealHaui
andauthored
Removed unreachable threshold verification code from Levenshtein algorithm implementation classes (#730)
Co-authored-by: TheRealHaui <[email protected]>
1 parent 175fd68 commit 61ec6fd

File tree

3 files changed

+1
-10
lines changed

3 files changed

+1
-10
lines changed

src/main/java/org/apache/commons/text/similarity/DamerauLevenshteinDistance.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ private static <E> int limitedCompare(SimilarityInput<E> left, SimilarityInput<E
5454
throw new IllegalArgumentException("Left/right inputs must not be null");
5555
}
5656

57-
if (threshold < 0) {
58-
throw new IllegalArgumentException("Threshold can not be negative");
59-
}
60-
6157
// Implementation based on https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance
6258

6359
int leftLength = left.length();

src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ private static <E> LevenshteinResults limitedCompare(SimilarityInput<E> left, Si
159159
if (left == null || right == null) {
160160
throw new IllegalArgumentException("CharSequences must not be null");
161161
}
162-
if (threshold < 0) {
163-
throw new IllegalArgumentException("Threshold must not be negative");
164-
}
162+
165163
/*
166164
* This implementation only computes the distance if it's less than or equal to the threshold value, returning -1 if it's greater. The advantage is
167165
* performance: unbounded distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only computing a diagonal stripe of width 2k + 1

src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ private static <E> int limitedCompare(SimilarityInput<E> left, SimilarityInput<E
8181
if (left == null || right == null) {
8282
throw new IllegalArgumentException("CharSequences must not be null");
8383
}
84-
if (threshold < 0) {
85-
throw new IllegalArgumentException("Threshold must not be negative");
86-
}
8784

8885
/*
8986
* This implementation only computes the distance if it's less than or equal to the threshold value, returning -1 if it's greater. The advantage is

0 commit comments

Comments
 (0)