com.force.i18n.commons.text.TrieMatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grammaticus Show documentation
Show all versions of grammaticus Show documentation
Localization Framework that allows grammatically correct renaming of nouns
/*
* Copyright, 1999-2008, salesforce.com
* All Rights Reserved
* Company Confidential
*/
package com.force.i18n.commons.text;
/**
* Struct returned by {@link TrieMatcher#match(CharSequence, int)} to represent a match.
*
* @author koliver
* @see TrieMatcher
*/
public class TrieMatch {
private final int position;
private final String word;
private final String replacement;
TrieMatch(int position, String word, String replacement) {
if (position < 0) throw new IllegalArgumentException(Integer.toString(position));
if (word == null) throw new NullPointerException();
if (replacement == null) throw new NullPointerException();
this.position = position;
this.word = word;
this.replacement = replacement;
}
/**
* @return position of where the match was in the source.
* Eg,
* Trie trie = new Trie(String[]{"x"}, String[]{"Y"});
* TrieMatch match = trie.match("abcxdef");
* Assert.assertEquals(3, match.getPosition());
*
*/
public int getPosition() {
return this.position;
}
/**
* @return word in the trie that matched.
* Eg,
* Trie trie = new Trie(String[]{"x"}, String[]{"Y"});
* TrieMatch match = trie.match("abcxdef");
* Assert.assertEquals("x", match.getWord());
*
*/
public String getWord() {
return this.word;
}
/**
* @return the replacement for word in the trie that matched.
* Eg,
* Trie trie = new Trie(String[]{"x"}, String[]{"Y"});
* TrieMatch match = trie.match("abcxdef");
* Assert.assertEquals("Y", match.getReplacement());
*
*/
public String getReplacement() {
return this.replacement;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy