Optimize imports
Reformatted code (Java convention; tab is 4 spaces)
This commit is contained in:
parent
267e895059
commit
255069624b
3
pom.xml
3
pom.xml
@ -1,4 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.ahocorasick</groupId>
|
||||
|
||||
@ -3,7 +3,9 @@ package org.ahocorasick.interval;
|
||||
public interface Intervalable extends Comparable {
|
||||
|
||||
public int getStart();
|
||||
|
||||
public int getEnd();
|
||||
|
||||
public int size();
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import java.util.*;
|
||||
* <p>
|
||||
* A state has various important tasks it must attend to:
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>success; when a character points to another state, it must return that state</li>
|
||||
* <li>failure; when a character has no matching state, the algorithm must be able to fall back on a
|
||||
@ -14,7 +14,7 @@ import java.util.*;
|
||||
* <li>emits; when this state is passed and keywords have been matched, the matches must be
|
||||
* 'emitted' so that they can be used later on.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* The root state is special in the sense that it has no failure state; it cannot fail. If it 'fails'
|
||||
* it will still parse the next character and start from the root node. This ensures that the algorithm
|
||||
@ -25,10 +25,14 @@ import java.util.*;
|
||||
*/
|
||||
public class State {
|
||||
|
||||
/** effective the size of the keyword */
|
||||
/**
|
||||
* effective the size of the keyword
|
||||
*/
|
||||
private final int depth;
|
||||
|
||||
/** only used for the root state to refer to itself in case no matches have been found */
|
||||
/**
|
||||
* only used for the root state to refer to itself in case no matches have been found
|
||||
*/
|
||||
private final State rootState;
|
||||
|
||||
/**
|
||||
@ -37,10 +41,14 @@ public class State {
|
||||
*/
|
||||
private final Map<Character, State> success = new HashMap<>();
|
||||
|
||||
/** if no matching states are found, the failure state will be returned */
|
||||
/**
|
||||
* if no matching states are found, the failure state will be returned
|
||||
*/
|
||||
private State failure;
|
||||
|
||||
/** whenever this state is reached, it will emit the matches keywords for future reference */
|
||||
/**
|
||||
* whenever this state is reached, it will emit the matches keywords for future reference
|
||||
*/
|
||||
private Set<String> emits;
|
||||
|
||||
public State() {
|
||||
|
||||
@ -1,15 +1,17 @@
|
||||
package org.ahocorasick.trie;
|
||||
|
||||
import static java.lang.Character.isWhitespace;
|
||||
import org.ahocorasick.interval.IntervalTree;
|
||||
import org.ahocorasick.interval.Intervalable;
|
||||
import org.ahocorasick.trie.handler.DefaultEmitHandler;
|
||||
import org.ahocorasick.trie.handler.EmitHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import org.ahocorasick.interval.IntervalTree;
|
||||
import org.ahocorasick.interval.Intervalable;
|
||||
import org.ahocorasick.trie.handler.DefaultEmitHandler;
|
||||
import org.ahocorasick.trie.handler.EmitHandler;
|
||||
|
||||
import static java.lang.Character.isWhitespace;
|
||||
|
||||
/**
|
||||
* Based on the Aho-Corasick white paper, Bell technologies:
|
||||
@ -32,7 +34,6 @@ public class Trie {
|
||||
* Used by the builder to add a text search keyword.
|
||||
*
|
||||
* @param keyword The search term to add to the list of search terms.
|
||||
*
|
||||
* @throws NullPointerException if the keyword is null.
|
||||
*/
|
||||
private void addKeyword(String keyword) {
|
||||
@ -314,7 +315,8 @@ public class Trie {
|
||||
/**
|
||||
* Default (empty) constructor.
|
||||
*/
|
||||
private TrieBuilder() {}
|
||||
private TrieBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the Trie to ignore case when searching for keywords in
|
||||
@ -343,7 +345,6 @@ public class Trie {
|
||||
* Adds a keyword to the Trie's list of text search keywords.
|
||||
*
|
||||
* @param keyword The keyword to add to the list.
|
||||
*
|
||||
* @return This builder.
|
||||
* @throws NullPointerException if the keyword is null.
|
||||
*/
|
||||
@ -356,7 +357,6 @@ public class Trie {
|
||||
* Adds a list of keywords to the Trie's list of text search keywords.
|
||||
*
|
||||
* @param keywords The keywords to add to the list.
|
||||
*
|
||||
* @return This builder.
|
||||
*/
|
||||
public TrieBuilder addKeywords(final String... keywords) {
|
||||
@ -368,7 +368,6 @@ public class Trie {
|
||||
* Adds a list of keywords to the Trie's list of text search keywords.
|
||||
*
|
||||
* @param keywords The keywords to add to the list.
|
||||
*
|
||||
* @return This builder.
|
||||
*/
|
||||
public TrieBuilder addKeywords(final Collection<String> keywords) {
|
||||
@ -420,18 +419,16 @@ public class Trie {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ignoreCase()
|
||||
*
|
||||
* @return This builder.
|
||||
* @deprecated Use ignoreCase()
|
||||
*/
|
||||
public TrieBuilder caseInsensitive() {
|
||||
return ignoreCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ignoreOverlaps()
|
||||
*
|
||||
* @return This builder.
|
||||
* @deprecated Use ignoreOverlaps()
|
||||
*/
|
||||
public TrieBuilder removeOverlaps() {
|
||||
return ignoreOverlaps();
|
||||
|
||||
@ -12,9 +12,13 @@ public class TrieConfig {
|
||||
|
||||
private boolean stopOnHit = false;
|
||||
|
||||
public boolean isStopOnHit() { return stopOnHit; }
|
||||
public boolean isStopOnHit() {
|
||||
return stopOnHit;
|
||||
}
|
||||
|
||||
public void setStopOnHit(boolean stopOnHit) { this.stopOnHit = stopOnHit; }
|
||||
public void setStopOnHit(boolean stopOnHit) {
|
||||
this.stopOnHit = stopOnHit;
|
||||
}
|
||||
|
||||
public boolean isAllowOverlaps() {
|
||||
return allowOverlaps;
|
||||
@ -32,7 +36,9 @@ public class TrieConfig {
|
||||
this.onlyWholeWords = onlyWholeWords;
|
||||
}
|
||||
|
||||
public boolean isOnlyWholeWordsWhiteSpaceSeparated() { return onlyWholeWordsWhiteSpaceSeparated; }
|
||||
public boolean isOnlyWholeWordsWhiteSpaceSeparated() {
|
||||
return onlyWholeWordsWhiteSpaceSeparated;
|
||||
}
|
||||
|
||||
public void setOnlyWholeWordsWhiteSpaceSeparated(boolean onlyWholeWordsWhiteSpaceSeparated) {
|
||||
this.onlyWholeWordsWhiteSpaceSeparated = onlyWholeWordsWhiteSpaceSeparated;
|
||||
|
||||
@ -2,11 +2,11 @@ package org.ahocorasick.interval;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.*;
|
||||
|
||||
public class IntervalTest {
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package org.ahocorasick.trie;
|
||||
|
||||
import org.ahocorasick.trie.State;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
package org.ahocorasick.trie;
|
||||
|
||||
import org.ahocorasick.trie.handler.EmitHandler;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import org.ahocorasick.trie.handler.EmitHandler;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TrieTest {
|
||||
private final static String[] ALPHABET = new String[]{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user