code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
private static String findAppNameFromAgentId(String id) { int index = id.indexOf('_'); if (index < 0 || index >= id.length()) { return null; } return id.substring(0, index); }
check if agentId exists @param agentId @return
findAppNameFromAgentId
java
alibaba/arthas
tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java
https://github.com/alibaba/arthas/blob/master/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java
Apache-2.0
@Override protected ReactActivityDelegate createReactActivityDelegate() { return new MainActivityDelegate(this, getMainComponentName()); }
Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and you can specify the rendered you wish to use (Fabric or the older renderer).
createReactActivityDelegate
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
MIT
@Override protected ReactRootView createRootView() { ReactRootView reactRootView = new ReactRootView(getContext()); // If you opted-in for the New Architecture, we enable the Fabric Renderer. reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); return reactRootView; }
Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and you can specify the rendered you wish to use (Fabric or the older renderer).
createRootView
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/MainActivity.java
MIT
@Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getUseDeveloperSupport
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override protected List<ReactPackage> getPackages() { List<ReactPackage> packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: // packages.add(new TurboReactPackage() { ... }); // If you have custom Fabric Components, their ViewManagers should also be loaded here // inside a ReactPackage. return packages; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getPackages
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override protected String getJSMainModuleName() { return "index"; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getJSMainModuleName
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@NonNull @Override protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboModuleManagerDelegateBuilder() { // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary // for the new architecture and to use TurboModules correctly. return new MainApplicationTurboModuleManagerDelegate.Builder(); }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getReactPackageTurboModuleManagerDelegateBuilder
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override protected JSIModulePackage getJSIModulePackage() { return new JSIModulePackage() { @Override public List<JSIModuleSpec> getJSIModules( final ReactApplicationContext reactApplicationContext, final JavaScriptContextHolder jsContext) { final List<JSIModuleSpec> specs = new ArrayList<>(); // Here we provide a new JSIModuleSpec that will be responsible of providing the // custom Fabric Components. specs.add( new JSIModuleSpec() { @Override public JSIModuleType getJSIModuleType() { return JSIModuleType.UIManager; } @Override public JSIModuleProvider<UIManager> getJSIModuleProvider() { final ComponentFactory componentFactory = new ComponentFactory(); CoreComponentsRegistry.register(componentFactory); // Here we register a Components Registry. // The one that is generated with the template contains no components // and just provides you the one from React Native core. MainComponentsRegistry.register(componentFactory); final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry( reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); return new FabricJSIModuleProvider( reactApplicationContext, componentFactory, new EmptyReactNativeConfig(), viewManagerRegistry); } }); return specs; } }; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getJSIModulePackage
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override public List<JSIModuleSpec> getJSIModules( final ReactApplicationContext reactApplicationContext, final JavaScriptContextHolder jsContext) { final List<JSIModuleSpec> specs = new ArrayList<>(); // Here we provide a new JSIModuleSpec that will be responsible of providing the // custom Fabric Components. specs.add( new JSIModuleSpec() { @Override public JSIModuleType getJSIModuleType() { return JSIModuleType.UIManager; } @Override public JSIModuleProvider<UIManager> getJSIModuleProvider() { final ComponentFactory componentFactory = new ComponentFactory(); CoreComponentsRegistry.register(componentFactory); // Here we register a Components Registry. // The one that is generated with the template contains no components // and just provides you the one from React Native core. MainComponentsRegistry.register(componentFactory); final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry( reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); return new FabricJSIModuleProvider( reactApplicationContext, componentFactory, new EmptyReactNativeConfig(), viewManagerRegistry); } }); return specs; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getJSIModules
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override public JSIModuleType getJSIModuleType() { return JSIModuleType.UIManager; }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getJSIModuleType
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@Override public JSIModuleProvider<UIManager> getJSIModuleProvider() { final ComponentFactory componentFactory = new ComponentFactory(); CoreComponentsRegistry.register(componentFactory); // Here we register a Components Registry. // The one that is generated with the template contains no components // and just provides you the one from React Native core. MainComponentsRegistry.register(componentFactory); final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry( reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); return new FabricJSIModuleProvider( reactApplicationContext, componentFactory, new EmptyReactNativeConfig(), viewManagerRegistry); }
A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both TurboModule delegates and the Fabric Renderer. <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
getJSIModuleProvider
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/MainApplicationReactNativeHost.java
MIT
@DoNotStrip public static MainComponentsRegistry register(ComponentFactory componentFactory) { return new MainComponentsRegistry(componentFactory); }
Class responsible to load the custom Fabric Components. This class has native methods and needs a corresponding C++ implementation/header file to work correctly (already placed inside the jni/ folder for you). <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
register
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/components/MainComponentsRegistry.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/components/MainComponentsRegistry.java
MIT
protected MainApplicationTurboModuleManagerDelegate build( ReactApplicationContext context, List<ReactPackage> packages) { return new MainApplicationTurboModuleManagerDelegate(context, packages); }
Class responsible to load the TurboModules. This class has native methods and needs a corresponding C++ implementation/header file to work correctly (already placed inside the jni/ folder for you). <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
build
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java
MIT
@Override protected synchronized void maybeLoadOtherSoLibraries() { if (!sIsSoLibraryLoaded) { // If you change the name of your application .so file in the Android.mk file, // make sure you update the name here as well. SoLoader.loadLibrary("rn_68_appmodules"); sIsSoLibraryLoaded = true; } }
Class responsible to load the TurboModules. This class has native methods and needs a corresponding C++ implementation/header file to work correctly (already placed inside the jni/ folder for you). <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the `newArchEnabled` property). Is ignored otherwise.
maybeLoadOtherSoLibraries
java
wix/react-native-notifications
example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java
https://github.com/wix/react-native-notifications/blob/master/example/android/myapplication/src/main/java/com/wix/reactnativenotifications/app/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java
MIT
@Override public int getStart() { return this.start; }
Returns the starting offset into the text for this interval. @return A number between 0 (start of text) and the text length.
getStart
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public int getEnd() { return this.end; }
Returns the ending offset into the text for this interval. @return A number between getStart() + 1 and the text length.
getEnd
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public int size() { return end - start + 1; }
Returns the length of the interval. @return The end position less the start position, plus one.
size
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
public boolean overlapsWith(final Interval other) { return this.start <= other.getEnd() && this.end >= other.getStart(); }
Answers whether the given interval overlaps this interval instance. @param other the other interval to check for overlap @return true The intervals overlap.
overlapsWith
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
public boolean overlapsWith(int point) { return this.start <= point && point <= this.end; }
Answers whether the given interval overlaps this interval instance. @param other the other interval to check for overlap @return true The intervals overlap.
overlapsWith
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public boolean equals(Object o) { if (!(o instanceof Intervalable)) { return false; } Intervalable other = (Intervalable) o; return this.start == other.getStart() && this.end == other.getEnd(); }
Answers whether the given interval overlaps this interval instance. @param other the other interval to check for overlap @return true The intervals overlap.
equals
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public int hashCode() { return this.start % 100 + this.end % 100; }
Answers whether the given interval overlaps this interval instance. @param other the other interval to check for overlap @return true The intervals overlap.
hashCode
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public int compareTo(Object o) { if (!(o instanceof Intervalable)) { return -1; } Intervalable other = (Intervalable) o; int comparison = this.start - other.getStart(); return comparison != 0 ? comparison : this.end - other.getEnd(); }
Answers whether the given interval overlaps this interval instance. @param other the other interval to check for overlap @return true The intervals overlap.
compareTo
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
@Override public String toString() { return this.start + ":" + this.end; }
Returns the starting offset and ending offset separated by a full colon (:). @return A non-null String, never empty.
toString
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/interval/Interval.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/interval/Interval.java
Apache-2.0
public String getKeyword() { return this.keyword; }
Responsible for tracking the bounds of matched terms.
getKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Emit.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Emit.java
Apache-2.0
@Override public String toString() { return super.toString() + "=" + this.keyword; }
Responsible for tracking the bounds of matched terms.
toString
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Emit.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Emit.java
Apache-2.0
public String getKeyword() { return keyword; }
Contains the matched keyword and some payload data. @author Daniel Beck @param <T> The type of the wrapped payload data.
getKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Payload.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Payload.java
Apache-2.0
public T getData() { return data; }
Contains the matched keyword and some payload data. @author Daniel Beck @param <T> The type of the wrapped payload data.
getData
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Payload.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Payload.java
Apache-2.0
@Override public int compareTo(Payload<T> other) { return keyword.compareTo(other.getKeyword()); }
Contains the matched keyword and some payload data. @author Daniel Beck @param <T> The type of the wrapped payload data.
compareTo
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Payload.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Payload.java
Apache-2.0
private void addKeyword(String keyword) { if (keyword.isEmpty()) { return; } addState(keyword).addEmit(new Payload<>(keyword, null)); }
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.
addKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private PayloadState<T> addState(final String keyword) { PayloadState<T> state = getRootState(); for (final Character character : keyword.toCharArray()) { Character adjustedChar = isCaseInsensitive() ? Character.toLowerCase(character) : character; state = state.addState(adjustedChar); } return state; }
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.
addState
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public boolean containsMatch(final CharSequence text) { return firstMatch(text) != null; }
Returns true if the text contains one of the search terms; otherwise, returns false. @param text Specified text. @return true if the text contains one of the search terms. Else, returns false.
containsMatch
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadEmit<T> firstMatch(final CharSequence text) { assert text != null; if (!trieConfig.isAllowOverlaps()) { // Slow path. Needs to find all the matches to detect overlaps. final Collection<PayloadEmit<T>> parseText = parseText(text); if (parseText != null && !parseText.isEmpty()) { return parseText.iterator().next(); } } else { // Fast path. Returns first match found. PayloadState<T> currentState = getRootState(); for (int position = 0; position < text.length(); position++) { char character = text.charAt( position); if (trieConfig.isCaseInsensitive()) { character = Character.toLowerCase(character); } currentState = getState(currentState, character); Collection<Payload<T>> payloads = currentState.emit(); if (payloads != null && !payloads.isEmpty()) { for (final Payload<T> payload : payloads) { final PayloadEmit<T> emit = new PayloadEmit<>(position - payload.getKeyword().length() + 1, position, payload.getKeyword(), payload.getData()); if (trieConfig.isOnlyWholeWords()) { if (!isPartialMatch(text, emit)) { return emit; } } else { return emit; } } } } } return null; }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
firstMatch
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private boolean isPartialMatch(final CharSequence searchText, final PayloadEmit<T> emit) { return (emit.getStart() != 0 && Character.isAlphabetic(searchText.charAt(emit.getStart() - 1))) || (emit.getEnd() + 1 != searchText.length() && Character.isAlphabetic(searchText.charAt(emit.getEnd() + 1))); }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
isPartialMatch
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private boolean isPartialMatchWhiteSpaceSeparated(final CharSequence searchText, final PayloadEmit<T> emit) { final long size = searchText.length(); return (emit.getStart() != 0 && !isWhitespace(searchText.charAt(emit.getStart() - 1))) || (emit.getEnd() + 1 != size && !isWhitespace(searchText.charAt(emit.getEnd() + 1))); }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
isPartialMatchWhiteSpaceSeparated
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private PayloadState<T> getState(PayloadState<T> currentState, final Character character) { PayloadState<T> newCurrentState = currentState.nextState(character); while (newCurrentState == null) { currentState = currentState.failure(); newCurrentState = currentState.nextState(character); } return newCurrentState; }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
getState
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private void constructFailureStates() { final Queue<PayloadState<T>> queue = new LinkedBlockingDeque<>(); final PayloadState<T> startState = getRootState(); // First, set the fail state of all depth 1 states to the root state for (PayloadState<T> depthOneState : startState.getStates()) { depthOneState.setFailure(startState); queue.add(depthOneState); } // Second, determine the fail state for all depth > 1 state while (!queue.isEmpty()) { final PayloadState<T> currentState = queue.remove(); for (final Character transition : currentState.getTransitions()) { PayloadState<T> targetState = currentState.nextState(transition); queue.add(targetState); PayloadState<T> traceFailureState = currentState.failure(); while (traceFailureState.nextState(transition) == null) { traceFailureState = traceFailureState.failure(); } final PayloadState<T> newFailureState = traceFailureState.nextState(transition); targetState.setFailure(newFailureState); targetState.addEmit(newFailureState.emit()); } } }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
constructFailureStates
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private boolean processEmits(final CharSequence text, final int position, final Collection<Payload<T>> payloads, final PayloadEmitHandler<T> emitHandler) { boolean emitted = false; for (final Payload<T> payload : payloads) { final PayloadEmit<T> payloadEmit = new PayloadEmit<>(position - payload.getKeyword().length() + 1, position, payload.getKeyword(), payload.getData()); if (!(trieConfig.isOnlyWholeWords() && isPartialMatch(text, payloadEmit)) && !(trieConfig.isOnlyWholeWordsWhiteSpaceSeparated() && isPartialMatchWhiteSpaceSeparated(text, payloadEmit))) { emitted = emitHandler.emit(payloadEmit) || emitted; if (emitted && trieConfig.isStopOnHit()) { break; } } } return emitted; }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
processEmits
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private boolean isCaseInsensitive() { return trieConfig.isCaseInsensitive(); }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
isCaseInsensitive
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
private PayloadState<T> getRootState() { return this.rootState; }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
getRootState
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> ignoreCase() { this.trieConfig.setCaseInsensitive(true); return this; }
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.
ignoreCase
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> ignoreOverlaps() { this.trieConfig.setAllowOverlaps(false); return this; }
Configure the Trie to ignore overlapping keywords. @return This builder.
ignoreOverlaps
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> addKeyword(final String keyword) { this.trie.addKeyword(keyword); return this; }
Adds a keyword to the {@link Trie}'s list of text search keywords. No {@link Payload} is supplied. @param keyword The keyword to add to the list. @return This builder. @throws NullPointerException if the keyword is null.
addKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> addKeyword(final String keyword, final T payload) { this.trie.addKeyword(keyword, payload); return this; }
Adds a keyword and a payload to the {@link Trie}'s list of text search keywords. @param keyword The keyword to add to the list. @param payload the payload to add @return This builder. @throws NullPointerException if the keyword is null.
addKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> addKeywords(final Collection<Payload<T>> keywords) { for (Payload<T> payload : keywords) { this.trie.addKeyword(payload.getKeyword(), payload.getData()); } return this; }
Adds a list of keywords and payloads to the {@link Trie}'s list of text search keywords. @param keywords The keywords to add to the list. @return This builder.
addKeywords
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> onlyWholeWords() { this.trieConfig.setOnlyWholeWords(true); return this; }
Configure the Trie to match whole keywords in the text. @return This builder.
onlyWholeWords
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> onlyWholeWordsWhiteSpaceSeparated() { this.trieConfig.setOnlyWholeWordsWhiteSpaceSeparated(true); return this; }
Configure the Trie to match whole keywords that are separated by whitespace in the text. For example, "this keyword thatkeyword" would only match the first occurrence of "keyword". @return This builder.
onlyWholeWordsWhiteSpaceSeparated
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrieBuilder<T> stopOnHit() { trie.trieConfig.setStopOnHit(true); return this; }
Configure the Trie to stop after the first keyword is found in the text. @return This builder.
stopOnHit
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public PayloadTrie<T> build() { this.trie.constructFailureStates(); return this.trie; }
Configure the PayloadTrie based on the builder settings. @return The configured PayloadTrie.
build
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
@Deprecated public PayloadTrieBuilder<T> caseInsensitive() { return ignoreCase(); }
@return This builder. @deprecated Use ignoreCase()
caseInsensitive
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
@Deprecated public PayloadTrieBuilder<T> removeOverlaps() { return ignoreOverlaps(); }
@return This builder. @deprecated Use ignoreOverlaps()
removeOverlaps
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/PayloadTrie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/PayloadTrie.java
Apache-2.0
public Collection<Token> tokenize(final String text) { Collection<PayloadToken<String>> tokens = this.payloadTrie.tokenize(text); return asTokens(tokens); }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
tokenize
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
private static Collection<Token> asTokens(Collection<PayloadToken<String>> tokens) { Collection<Token> result = new ArrayList<>(); for (PayloadToken<String> payloadToken : tokens) { result.add(new DefaultToken(payloadToken)); } return result; }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
asTokens
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
private static Collection<Emit> asEmits(Collection<PayloadEmit<String>> emits) { Collection<Emit> result = new ArrayList<>(); for (PayloadEmit<String> emit : emits) { result.add(asEmit(emit)); } return result; }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
asEmits
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
private static Emit asEmit(PayloadEmit<String> payloadEmit) { return new Emit(payloadEmit.getStart(), payloadEmit.getEnd(), payloadEmit.getKeyword()); }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
asEmit
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public Collection<Emit> parseText(final CharSequence text) { Collection<PayloadEmit<String>> parsedText = this.payloadTrie.parseText(text); return asEmits(parsedText); }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
parseText
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
@SuppressWarnings("UnusedReturnValue") public Collection<Emit> parseText( final CharSequence text, final StatefulEmitHandler emitHandler) { Collection<PayloadEmit<String>> parsedText = this.payloadTrie.parseText(text, new StatefulPayloadEmitDelegateHandler(emitHandler)); return asEmits(parsedText); }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
parseText
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public boolean containsMatch(final CharSequence text) { return firstMatch(text) != null; }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
containsMatch
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public void parseText(final CharSequence text, final EmitHandler emitHandler) { this.payloadTrie.parseText(text, new PayloadEmitDelegateHandler(emitHandler)); }
Based on the <a href="http://cr.yp.to/bib/1975/aho.pdf">Aho-Corasick white paper</a>, from Bell technologies. @author Robert Bor
parseText
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public Emit firstMatch(final CharSequence text) { assert text != null; final PayloadEmit<String> payload = this.payloadTrie.firstMatch( text ); return payload == null ? null : new Emit( payload.getStart(), payload.getEnd(), payload.getKeyword() ); }
The first matching text sequence. @param text The text to search for keywords, must not be {@code null}. @return {@code null} if no matches found.
firstMatch
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public static TrieBuilder builder() { return new TrieBuilder(); }
Provides a fluent interface for constructing Trie instances. @return The builder used to configure its Trie.
builder
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder ignoreCase() { delegate.ignoreCase(); // this.trieConfig.setCaseInsensitive(true); return this; }
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.
ignoreCase
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder ignoreOverlaps() { delegate.ignoreOverlaps(); return this; }
Configure the Trie to ignore overlapping keywords. @return This builder.
ignoreOverlaps
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder addKeyword(final String keyword) { delegate.addKeyword(keyword, null); return this; }
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.
addKeyword
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder addKeywords(final String... keywords) { for (String keyword : keywords) { delegate.addKeyword(keyword, null); } return this; }
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.
addKeywords
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
@SuppressWarnings("unused") public TrieBuilder addKeywords( final Collection<String> keywords ) { for (String keyword : keywords) { this.delegate.addKeyword(keyword, null); } return this; }
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.
addKeywords
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder onlyWholeWords() { this.delegate.onlyWholeWords(); return this; }
Configure the Trie to match whole keywords in the text. @return This builder.
onlyWholeWords
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder onlyWholeWordsWhiteSpaceSeparated() { this.delegate.onlyWholeWordsWhiteSpaceSeparated(); return this; }
Configure the Trie to match whole keywords that are separated by whitespace in the text. For example, "this keyword thatkeyword" would only match the first occurrence of "keyword". @return This builder.
onlyWholeWordsWhiteSpaceSeparated
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder stopOnHit() { this.delegate.stopOnHit(); return this; }
Configure the Trie to stop after the first keyword is found in the text. @return This builder.
stopOnHit
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public Trie build() { PayloadTrie<String> payloadTrie = this.delegate.build(); return new Trie(payloadTrie); }
Configure the Trie based on the builder settings. @return The configured Trie.
build
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder caseInsensitive() { return ignoreCase(); }
@return This builder. @deprecated Use ignoreCase()
caseInsensitive
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
public TrieBuilder removeOverlaps() { return ignoreOverlaps(); }
@return This builder. @deprecated Use ignoreOverlaps()
removeOverlaps
java
robert-bor/aho-corasick
src/main/java/org/ahocorasick/trie/Trie.java
https://github.com/robert-bor/aho-corasick/blob/master/src/main/java/org/ahocorasick/trie/Trie.java
Apache-2.0
@SuppressWarnings( "SameParameterValue" ) static void injectKeyword( final StringBuilder source, final String keyword, final int interval ) { final int length = source.length(); for( int i = 0; i < length; i += interval ) { source.replace( i, i + keyword.length(), keyword ); } }
Injects keywords into a string builder. @param source Should contain a bunch of random data that cannot match any keyword. @param keyword A keyword to inject repeatedly in the text. @param interval How often to inject the keyword.
injectKeyword
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TestHelper.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TestHelper.java
Apache-2.0
@SuppressWarnings( "SameParameterValue" ) public static StringBuilder randomNumbers( int count ) { final StringBuilder sb = new StringBuilder( count ); while( --count > 0 ) { sb.append( current().nextInt( 0, 10 ) ); } return sb; }
Generates a random sequence of ASCII numbers. @param count The number of numbers to generate. @return A character sequence filled with random digits.
randomNumbers
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TestHelper.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TestHelper.java
Apache-2.0
private static Trie trie( final String keyword ) { return Trie.builder() .addKeyword( keyword ) .build(); }
Test the {@link Trie} class functionality.
trie
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
private static Trie trie( final String[] keywords ) { return Trie.builder() .addKeywords( keywords ) .build(); }
Test the {@link Trie} class functionality.
trie
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_KeywordAndTextAreTheSame() { final Trie trie = trie( ALPHABET[ 0 ] ); final Collection<Emit> emits = trie.parseText( ALPHABET[ 0 ] ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 0, 2, ALPHABET[ 0 ] ); }
Test the {@link Trie} class functionality.
test_KeywordAndTextAreTheSame
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_KeywordAndTextAreTheSameFirstMatch() { final Trie trie = trie( ALPHABET[ 0 ] ); final Emit firstMatch = trie.firstMatch( ALPHABET[ 0 ] ); checkEmit( firstMatch, 0, 2, ALPHABET[ 0 ] ); }
Test the {@link Trie} class functionality.
test_KeywordAndTextAreTheSameFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_TextIsLongerThanKeyword() { final Trie trie = trie( ALPHABET[ 0 ] ); final Collection<Emit> emits = trie.parseText( " " + ALPHABET[ 0 ] ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 1, 3, ALPHABET[ 0 ] ); }
Test the {@link Trie} class functionality.
test_TextIsLongerThanKeyword
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_TextIsLongerThanKeywordFirstMatch() { final Trie trie = trie( ALPHABET[ 0 ] ); final Emit firstMatch = trie.firstMatch( " " + ALPHABET[ 0 ] ); checkEmit( firstMatch, 1, 3, ALPHABET[ 0 ] ); }
Test the {@link Trie} class functionality.
test_TextIsLongerThanKeywordFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_VariousKeywordsOneMatch() { final Trie trie = trie( ALPHABET ); final Collection<Emit> emits = trie.parseText( "bcd" ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 0, 2, "bcd" ); }
Test the {@link Trie} class functionality.
test_VariousKeywordsOneMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_VariousKeywordsFirstMatch() { final Trie trie = trie( ALPHABET ); final Emit firstMatch = trie.firstMatch( "bcd" ); checkEmit( firstMatch, 0, 2, "bcd" ); }
Test the {@link Trie} class functionality.
test_VariousKeywordsFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test(expected=AssertionError.class) public void test_NullInputTextFirstMatch() { final Trie trie = trie( ALPHABET ); final Emit firstMatch = trie.firstMatch( null ); assertNull( firstMatch ); }
Test the {@link Trie} class functionality.
test_NullInputTextFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTestAndStopOnHit() { final Trie trie = Trie.builder() .addKeywords( PRONOUNS ) .stopOnHit() .build(); final Collection<Emit> emits = trie.parseText( "ushers" ); assertEquals( 1, emits.size() ); // she @ 3, he @ 3, hers @ 5 final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 2, 3, "he" ); }
Test the {@link Trie} class functionality.
test_UshersTestAndStopOnHit
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTestStopOnHitSkipOne() { final Trie trie = Trie.builder() .addKeywords( PRONOUNS ) .stopOnHit() .build(); final StatefulEmitHandler testEmitHandler = new AbstractStatefulEmitHandler() { boolean first = true; @Override public boolean emit( final Emit emit ) { if( first ) { // return false for the first element first = false; return false; } addEmit( emit ); return true; } }; trie.parseText( "ushers", testEmitHandler ); final Collection<Emit> emits = testEmitHandler.getEmits(); assertEquals( 1, emits.size() ); // she @ 3, he @ 3, hers @ 5 final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 1, 3, "she" ); }
Test the {@link Trie} class functionality.
test_UshersTestStopOnHitSkipOne
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Override public boolean emit( final Emit emit ) { if( first ) { // return false for the first element first = false; return false; } addEmit( emit ); return true; }
Test the {@link Trie} class functionality.
emit
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTest() { final Trie trie = trie( PRONOUNS ); final Collection<Emit> emits = trie.parseText( "ushers" ); assertEquals( 3, emits.size() ); // she @ 3, he @ 3, hers @ 5 final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 2, 3, "he" ); checkEmit( iterator.next(), 1, 3, "she" ); checkEmit( iterator.next(), 2, 5, "hers" ); }
Test the {@link Trie} class functionality.
test_UshersTest
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTestWithCapitalKeywords() { final Trie trie = Trie.builder() .ignoreCase() .addKeyword( "HERS" ) .addKeyword( "HIS" ) .addKeyword( "SHE" ) .addKeyword( "HE" ) .build(); final Collection<Emit> emits = trie.parseText( "ushers" ); assertEquals( 3, emits.size() ); // she @ 3, he @ 3, hers @ 5 final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 2, 3, "HE" ); checkEmit( iterator.next(), 1, 3, "SHE" ); checkEmit( iterator.next(), 2, 5, "HERS" ); }
Test the {@link Trie} class functionality.
test_UshersTestWithCapitalKeywords
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTestFirstMatch() { final Trie trie = trie( PRONOUNS ); final Emit firstMatch = trie.firstMatch( "ushers" ); checkEmit( firstMatch, 2, 3, "he" ); }
Test the {@link Trie} class functionality.
test_UshersTestFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_UshersTestByCallback() { final Trie trie = trie( PRONOUNS ); final List<Emit> emits = new ArrayList<>(); final EmitHandler emitHandler = emit -> { emits.add( emit ); return true; }; trie.parseText( "ushers", emitHandler ); assertEquals( 3, emits.size() ); // she @ 3, he @ 3, hers @ 5 final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 2, 3, "he" ); checkEmit( iterator.next(), 1, 3, "she" ); checkEmit( iterator.next(), 2, 5, "hers" ); }
Test the {@link Trie} class functionality.
test_UshersTestByCallback
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_MisleadingTest() { final Trie trie = trie( "hers" ); final Collection<Emit> emits = trie.parseText( "h he her hers" ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 9, 12, "hers" ); }
Test the {@link Trie} class functionality.
test_MisleadingTest
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_MisleadingTestFirstMatch() { final Trie trie = trie( "hers" ); final Emit firstMatch = trie.firstMatch( "h he her hers" ); checkEmit( firstMatch, 9, 12, "hers" ); }
Test the {@link Trie} class functionality.
test_MisleadingTestFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_Recipes() { final Trie trie = trie( FOOD ); final Collection<Emit> emits = trie.parseText( "2 cauliflowers, 3 tomatoes, 4 slices of veal, 100g broccoli" ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 2, 12, "cauliflower" ); checkEmit( iterator.next(), 18, 25, "tomatoes" ); checkEmit( iterator.next(), 40, 43, "veal" ); checkEmit( iterator.next(), 51, 58, "broccoli" ); }
Test the {@link Trie} class functionality.
test_Recipes
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_RecipesFirstMatch() { final Trie trie = trie( FOOD ); final Emit firstMatch = trie.firstMatch( "2 cauliflowers, 3 tomatoes, 4 slices of veal, 100g broccoli" ); checkEmit( firstMatch, 2, 12, "cauliflower" ); }
Test the {@link Trie} class functionality.
test_RecipesFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_LongAndShortOverlappingMatch() { final Trie trie = Trie.builder() .addKeyword( "he" ) .addKeyword( "hehehehe" ) .build(); final Collection<Emit> emits = trie.parseText( "hehehehehe" ); final Iterator<Emit> iterator = emits.iterator(); checkEmit( iterator.next(), 0, 1, "he" ); checkEmit( iterator.next(), 2, 3, "he" ); checkEmit( iterator.next(), 4, 5, "he" ); checkEmit( iterator.next(), 6, 7, "he" ); checkEmit( iterator.next(), 0, 7, "hehehehe" ); checkEmit( iterator.next(), 8, 9, "he" ); checkEmit( iterator.next(), 2, 9, "hehehehe" ); }
Test the {@link Trie} class functionality.
test_LongAndShortOverlappingMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_NonOverlapping() { final Trie trie = Trie.builder() .ignoreOverlaps() .addKeyword( "ab" ) .addKeyword( "cba" ) .addKeyword( "ababc" ) .build(); final Collection<Emit> emits = trie.parseText( "ababcbab" ); assertEquals( 2, emits.size() ); final Iterator<Emit> iterator = emits.iterator(); // With overlaps: ab@1, ab@3, ababc@4, cba@6, ab@7 checkEmit( iterator.next(), 0, 4, "ababc" ); checkEmit( iterator.next(), 6, 7, "ab" ); }
Test the {@link Trie} class functionality.
test_NonOverlapping
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_NonOverlappingFirstMatch() { final Trie trie = Trie.builder() .ignoreOverlaps() .addKeyword( "ab" ) .addKeyword( "cba" ) .addKeyword( "ababc" ) .build(); final Emit firstMatch = trie.firstMatch( "ababcbab" ); checkEmit( firstMatch, 0, 4, "ababc" ); }
Test the {@link Trie} class functionality.
test_NonOverlappingFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_ContainsMatch() { final Trie trie = Trie.builder() .ignoreOverlaps() .addKeyword( "ab" ) .addKeyword( "cba" ) .addKeyword( "ababc" ) .build(); assertTrue( trie.containsMatch( "ababcbab" ) ); }
Test the {@link Trie} class functionality.
test_ContainsMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_StartOfChurchillSpeech() { final Trie trie = Trie.builder() .ignoreOverlaps() .addKeyword( "T" ) .addKeyword( "u" ) .addKeyword( "ur" ) .addKeyword( "r" ) .addKeyword( "urn" ) .addKeyword( "ni" ) .addKeyword( "i" ) .addKeyword( "in" ) .addKeyword( "n" ) .addKeyword( "urning" ) .build(); final Collection<Emit> emits = trie.parseText( "Turning" ); assertEquals( 2, emits.size() ); }
Test the {@link Trie} class functionality.
test_StartOfChurchillSpeech
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_PartialMatch() { final Trie trie = Trie.builder() .onlyWholeWords() .addKeyword( "sugar" ) .build(); final Collection<Emit> emits = trie.parseText( "sugarcane sugarcane sugar canesugar" ); // left, middle, right test assertEquals( 1, emits.size() ); // Match must not be made checkEmit( emits.iterator().next(), 20, 24, "sugar" ); }
Test the {@link Trie} class functionality.
test_PartialMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0
@Test public void test_PartialMatchFirstMatch() { final Trie trie = Trie.builder() .onlyWholeWords() .addKeyword( "sugar" ) .build(); // left, middle, right test final Emit firstMatch = trie.firstMatch( "sugarcane sugarcane sugar canesugar" ); checkEmit( firstMatch, 20, 24, "sugar" ); }
Test the {@link Trie} class functionality.
test_PartialMatchFirstMatch
java
robert-bor/aho-corasick
src/test/java/org/ahocorasick/trie/TrieTest.java
https://github.com/robert-bor/aho-corasick/blob/master/src/test/java/org/ahocorasick/trie/TrieTest.java
Apache-2.0