Added missing override annotations. Added final modifier to Interval member variables. Updated documentation for ignoreCase (issue #33) and moved the ignore methods to the top of the builder to reflect their preferred calling order.
This commit is contained in:
parent
2f1ec8d041
commit
267e895059
@ -2,8 +2,8 @@ package org.ahocorasick.interval;
|
|||||||
|
|
||||||
public class Interval implements Intervalable {
|
public class Interval implements Intervalable {
|
||||||
|
|
||||||
private int start;
|
private final int start;
|
||||||
private int end;
|
private final int end;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an interval with a start and end position.
|
* Constructs an interval with a start and end position.
|
||||||
@ -21,6 +21,7 @@ public class Interval implements Intervalable {
|
|||||||
*
|
*
|
||||||
* @return A number between 0 (start of text) and the text length.
|
* @return A number between 0 (start of text) and the text length.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getStart() {
|
public int getStart() {
|
||||||
return this.start;
|
return this.start;
|
||||||
}
|
}
|
||||||
@ -30,6 +31,7 @@ public class Interval implements Intervalable {
|
|||||||
*
|
*
|
||||||
* @return A number between getStart() + 1 and the text length.
|
* @return A number between getStart() + 1 and the text length.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getEnd() {
|
public int getEnd() {
|
||||||
return this.end;
|
return this.end;
|
||||||
}
|
}
|
||||||
@ -39,6 +41,7 @@ public class Interval implements Intervalable {
|
|||||||
*
|
*
|
||||||
* @return The end position less the start position, plus one.
|
* @return The end position less the start position, plus one.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return end - start + 1;
|
return end - start + 1;
|
||||||
}
|
}
|
||||||
@ -47,6 +50,7 @@ public class Interval implements Intervalable {
|
|||||||
* Answers whether the given interval overlaps this interval
|
* Answers whether the given interval overlaps this interval
|
||||||
* instance.
|
* instance.
|
||||||
*
|
*
|
||||||
|
* @param other
|
||||||
* @return true The intervals overlap.
|
* @return true The intervals overlap.
|
||||||
*/
|
*/
|
||||||
public boolean overlapsWith(final Interval other) {
|
public boolean overlapsWith(final Interval other) {
|
||||||
|
|||||||
@ -20,5 +20,4 @@ public class Emit extends Interval implements Intervalable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + "=" + this.keyword;
|
return super.toString() + "=" + this.keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,10 +147,17 @@ public class Trie {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first matching text sequence.
|
||||||
|
*
|
||||||
|
* @param text The text to search for keywords.
|
||||||
|
* @return null if no matches found.
|
||||||
|
*/
|
||||||
public Emit firstMatch(final CharSequence text) {
|
public Emit firstMatch(final CharSequence text) {
|
||||||
if (!trieConfig.isAllowOverlaps()) {
|
if (!trieConfig.isAllowOverlaps()) {
|
||||||
// Slow path. Needs to find all the matches to detect overlaps.
|
// Slow path. Needs to find all the matches to detect overlaps.
|
||||||
Collection<Emit> parseText = parseText(text);
|
final Collection<Emit> parseText = parseText(text);
|
||||||
|
|
||||||
if (parseText != null && !parseText.isEmpty()) {
|
if (parseText != null && !parseText.isEmpty()) {
|
||||||
return parseText.iterator().next();
|
return parseText.iterator().next();
|
||||||
}
|
}
|
||||||
@ -170,7 +177,7 @@ public class Trie {
|
|||||||
Collection<String> emitStrs = currentState.emit();
|
Collection<String> emitStrs = currentState.emit();
|
||||||
|
|
||||||
if (emitStrs != null && !emitStrs.isEmpty()) {
|
if (emitStrs != null && !emitStrs.isEmpty()) {
|
||||||
for (String emitStr : emitStrs) {
|
for (final String emitStr : emitStrs) {
|
||||||
final Emit emit = new Emit(position - emitStr.length() + 1, position, emitStr);
|
final Emit emit = new Emit(position - emitStr.length() + 1, position, emitStr);
|
||||||
if (trieConfig.isOnlyWholeWords()) {
|
if (trieConfig.isOnlyWholeWords()) {
|
||||||
if (!isPartialMatch(text, emit)) {
|
if (!isPartialMatch(text, emit)) {
|
||||||
@ -309,6 +316,29 @@ public class Trie {
|
|||||||
*/
|
*/
|
||||||
private TrieBuilder() {}
|
private TrieBuilder() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the Trie to ignore case when searching for keywords in
|
||||||
|
* the text. This must be called before calling addKeyword because
|
||||||
|
* the algorithm converts keywords to lowercase as they are added,
|
||||||
|
* depending on this case sensitivity setting.
|
||||||
|
*
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public TrieBuilder ignoreCase() {
|
||||||
|
this.trieConfig.setCaseInsensitive(true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the Trie to ignore overlapping keywords.
|
||||||
|
*
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public TrieBuilder ignoreOverlaps() {
|
||||||
|
this.trieConfig.setAllowOverlaps(false);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a keyword to the Trie's list of text search keywords.
|
* Adds a keyword to the Trie's list of text search keywords.
|
||||||
*
|
*
|
||||||
@ -346,27 +376,6 @@ public class Trie {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the Trie to ignore case when searching for keywords in
|
|
||||||
* the text.
|
|
||||||
*
|
|
||||||
* @return This builder.
|
|
||||||
*/
|
|
||||||
public TrieBuilder ignoreCase() {
|
|
||||||
this.trieConfig.setCaseInsensitive(true);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the Trie to ignore overlapping keywords.
|
|
||||||
*
|
|
||||||
* @return This builder.
|
|
||||||
*/
|
|
||||||
public TrieBuilder ignoreOverlaps() {
|
|
||||||
this.trieConfig.setAllowOverlaps(false);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Trie to match whole keywords in the text.
|
* Configure the Trie to match whole keywords in the text.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user