Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.commons.text.similarity;

import java.util.Objects;

/**
* A similarity algorithm indicating the length of the longest common subsequence between two strings.
*
Expand Down Expand Up @@ -284,12 +286,15 @@ public CharSequence longestCommonSubsequence(final CharSequence left, final Char
* @param left first character sequence.
* @param right second character sequence.
* @return longest common substring length array.
* @throws NullPointerException if either input is {@code null}.
* @deprecated Deprecated as of 1.10. A more efficient implementation for calculating LCS is now available.
* Use {@link #longestCommonSubsequence(CharSequence, CharSequence)} instead to directly calculate the LCS.
* This method will be removed in 2.0.
*/
@Deprecated
public int[][] longestCommonSubstringLengthArray(final CharSequence left, final CharSequence right) {
Objects.requireNonNull(left, "left");
Objects.requireNonNull(right, "right");
final int[][] lcsLengthArray = new int[left.length() + 1][right.length() + 1];
for (int i = 0; i < left.length(); i++) {
for (int j = 0; j < right.length(); j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ void testGettingLongestCommonSubsequenceApplyStringNull() {
assertThrows(IllegalArgumentException.class, () -> subject.apply(" ", null));
}

@Test
@SuppressWarnings("deprecation")
void testGettingLongestCommonSubstringLengthArrayNullNull() {
assertThrows(NullPointerException.class, () -> subject.longestCommonSubstringLengthArray(null, null));
}

@Test
@SuppressWarnings("deprecation")
void testGettingLongestCommonSubstringLengthArrayNullString() {
assertThrows(NullPointerException.class, () -> subject.longestCommonSubstringLengthArray(null, "right"));
}

@Test
@SuppressWarnings("deprecation")
void testGettingLongestCommonSubstringLengthArrayStringNull() {
assertThrows(NullPointerException.class, () -> subject.longestCommonSubstringLengthArray(" ", null));
}

@Test
void testGettingLongestCommonSubsequenceNullNull() {
assertThrows(IllegalArgumentException.class, () -> subject.longestCommonSubsequence(null, null));
Expand Down