Optimize imports

Reformatted code (Java convention; tab is 4 spaces)
This commit is contained in:
robert-bor 2016-11-30 09:10:21 +01:00
parent 90d4645d49
commit b5aaa51fdd
12 changed files with 187 additions and 180 deletions

View File

@ -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> <modelVersion>4.0.0</modelVersion>
<groupId>org.ahocorasick</groupId> <groupId>org.ahocorasick</groupId>

View File

@ -1,10 +1,11 @@
package org.ahocorasick.interval; package org.ahocorasick.interval;
import static java.util.Collections.sort;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import static java.util.Collections.sort;
public class IntervalTree { public class IntervalTree {
private final IntervalNode rootNode; private final IntervalNode rootNode;

View File

@ -6,7 +6,7 @@ import java.util.*;
* <p> * <p>
* A state has various important tasks it must attend to: * A state has various important tasks it must attend to:
* </p> * </p>
* * <p>
* <ul> * <ul>
* <li>success; when a character points to another state, it must return that state</li> * <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 * <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 * <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> * 'emitted' so that they can be used later on.</li>
* </ul> * </ul>
* * <p>
* <p> * <p>
* The root state is special in the sense that it has no failure state; it cannot fail. If it 'fails' * 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 * 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 { public class State {
/** effective the size of the keyword */ /**
* effective the size of the keyword
*/
private final int depth; 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; private final State rootState;
/** /**
@ -37,10 +41,14 @@ public class State {
*/ */
private final Map<Character, State> success = new HashMap<>(); 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; 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; private Set<String> emits;
public State() { public State() {

View File

@ -1,17 +1,19 @@
package org.ahocorasick.trie; package org.ahocorasick.trie;
import static java.lang.Character.isAlphabetic; import org.ahocorasick.interval.IntervalTree;
import static java.lang.Character.isWhitespace; import org.ahocorasick.interval.Intervalable;
import static java.lang.Character.toLowerCase; import org.ahocorasick.trie.handler.DefaultEmitHandler;
import org.ahocorasick.trie.handler.EmitHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import org.ahocorasick.interval.IntervalTree;
import org.ahocorasick.interval.Intervalable; import static java.lang.Character.*;
import org.ahocorasick.trie.handler.DefaultEmitHandler;
import org.ahocorasick.trie.handler.EmitHandler; import java.lang.Character;
/** /**
* Based on the Aho-Corasick white paper, Bell technologies: * Based on the Aho-Corasick white paper, Bell technologies:
@ -34,7 +36,6 @@ public class Trie {
* Used by the builder to add a text search keyword. * Used by the builder to add a text search keyword.
* *
* @param keyword The search term to add to the list of search terms. * @param keyword The search term to add to the list of search terms.
*
* @throws NullPointerException if the keyword is null. * @throws NullPointerException if the keyword is null.
*/ */
private void addKeyword(String keyword) { private void addKeyword(String keyword) {
@ -296,13 +297,13 @@ public class Trie {
/** /**
* Default (empty) constructor. * Default (empty) constructor.
*/ */
private TrieBuilder() {} private TrieBuilder() {
}
/** /**
* Adds a keyword to the Trie's list of text search keywords. * Adds a keyword to the Trie's list of text search keywords.
* *
* @param keyword The keyword to add to the list. * @param keyword The keyword to add to the list.
*
* @return This builder. * @return This builder.
* @throws NullPointerException if the keyword is null. * @throws NullPointerException if the keyword is null.
*/ */
@ -315,7 +316,6 @@ public class Trie {
* Adds a list of keywords to the Trie's list of text search keywords. * Adds a list of keywords to the Trie's list of text search keywords.
* *
* @param keywords The keywords to add to the list. * @param keywords The keywords to add to the list.
*
* @return This builder. * @return This builder.
*/ */
public TrieBuilder addKeywords(final CharSequence... keywords) { public TrieBuilder addKeywords(final CharSequence... keywords) {
@ -330,7 +330,6 @@ public class Trie {
* Adds a list of keywords to the Trie's list of text search keywords. * Adds a list of keywords to the Trie's list of text search keywords.
* *
* @param keywords The keywords to add to the list. * @param keywords The keywords to add to the list.
*
* @return This builder. * @return This builder.
*/ */
public TrieBuilder addKeywords(final Collection<CharSequence> keywords) { public TrieBuilder addKeywords(final Collection<CharSequence> keywords) {

View File

@ -1,8 +1,9 @@
package org.ahocorasick.trie.handler; package org.ahocorasick.trie.handler;
import org.ahocorasick.trie.Emit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.ahocorasick.trie.Emit;
public class DefaultEmitHandler implements EmitHandler { public class DefaultEmitHandler implements EmitHandler {

View File

@ -2,11 +2,11 @@ package org.ahocorasick.interval;
import org.junit.Test; 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.*;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
public class IntervalTest { public class IntervalTest {

View File

@ -3,10 +3,9 @@ package org.ahocorasick.interval;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import static java.util.Collections.sort;
import java.util.List; import java.util.List;
import static java.util.Collections.sort;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
public class IntervalableComparatorByPositionTest { public class IntervalableComparatorByPositionTest {

View File

@ -3,11 +3,9 @@ package org.ahocorasick.interval;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import static java.util.Collections.sort;
import static java.util.Collections.sort;
import java.util.List; import java.util.List;
import static java.util.Collections.sort;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
public class IntervalableComparatorBySizeTest { public class IntervalableComparatorBySizeTest {

View File

@ -1,6 +1,5 @@
package org.ahocorasick.trie; package org.ahocorasick.trie;
import org.ahocorasick.trie.State;
import org.junit.Test; import org.junit.Test;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;

View File

@ -1,16 +1,17 @@
package org.ahocorasick.trie; package org.ahocorasick.trie;
import org.ahocorasick.trie.handler.EmitHandler;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import static java.util.concurrent.ThreadLocalRandom.current; import static java.util.concurrent.ThreadLocalRandom.current;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static org.ahocorasick.trie.Trie.builder; import static org.ahocorasick.trie.Trie.builder;
import org.ahocorasick.trie.handler.EmitHandler;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TrieTest { public class TrieTest {
private final static String[] ALPHABET = new String[]{ private final static String[] ALPHABET = new String[]{