LUCENE-5237: assert parameters validity as well as minor improvements

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1525813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-09-24 08:23:37 +00:00
parent ae72053351
commit 46729e8622
1 changed files with 13 additions and 7 deletions

View File

@ -17,7 +17,11 @@ package org.apache.lucene.analysis.util;
* limitations under the License. * limitations under the License.
*/ */
/** Some commonly-used stemming functions */ /**
* Some commonly-used stemming functions
*
* @lucene.internal
*/
public class StemmerUtil { public class StemmerUtil {
/** no instance */ /** no instance */
private StemmerUtil() {} private StemmerUtil() {}
@ -87,9 +91,10 @@ public class StemmerUtil {
* @return length of input buffer after deletion * @return length of input buffer after deletion
*/ */
public static int delete(char s[], int pos, int len) { public static int delete(char s[], int pos, int len) {
if (pos < len) assert pos < len;
if (pos < len - 1) { // don't arraycopy if asked to delete last character
System.arraycopy(s, pos + 1, s, pos, len - pos - 1); System.arraycopy(s, pos + 1, s, pos, len - pos - 1);
}
return len - 1; return len - 1;
} }
@ -103,9 +108,10 @@ public class StemmerUtil {
* @return length of input buffer after deletion * @return length of input buffer after deletion
*/ */
public static int deleteN(char s[], int pos, int len, int nChars) { public static int deleteN(char s[], int pos, int len, int nChars) {
// TODO: speed up, this is silly assert pos + nChars <= len;
for (int i = 0; i < nChars; i++) if (pos + nChars < len) { // don't arraycopy if asked to delete the last characters
len = delete(s, pos, len); System.arraycopy(s, pos + nChars, s, pos, len - pos - nChars);
return len; }
return len - nChars;
} }
} }