package NET.worlds.network; import java.util.StringTokenizer; import java.util.Vector; public class FilthyPhrase { private long compareValue; private Vector filthyWords; private String rawData; public FilthyPhrase(String phrase) { this.rawData = new String(phrase); this.filthyWords = new Vector(); StringTokenizer st = new StringTokenizer(phrase, "\t\n\r.,;'\"!?*:/()[]{} ,「」『』《》?【】。!、;:", true); if (st.hasMoreTokens()) { String firstToken = st.nextToken().toLowerCase(); this.compareValue = firstToken.hashCode(); this.filthyWords.addElement(firstToken); } while (st.hasMoreTokens()) { String nextWord = st.nextToken(); this.filthyWords.addElement(nextWord.toLowerCase()); } } public boolean check(String toCheck) { StringTokenizer st = new StringTokenizer(toCheck, "\t\n\r.,;'\"!?*:/()[]{} ,「」『』《》?【】。!、;:", true); for (int idx = 0; idx < this.filthyWords.size(); idx++) { if (!st.hasMoreTokens()) { return false; } String token = st.nextToken().toLowerCase(); String comparator = this.filthyWords.elementAt(idx); if (comparator.compareTo(token) != 0) { return false; } } return true; } public String getReplacement() { String funnyChars = new String("$!@%#@&*!%#@%!@#$%@#@!@%!@#$%*&%$!"); String retVal = new String(); for (int idx = 0; idx < this.filthyWords.size(); idx++) { int numChars = this.filthyWords.elementAt(idx).length(); new String(); String replacementWord; if (numChars > 1) { replacementWord = funnyChars.substring(0, numChars); } else { replacementWord = this.filthyWords.elementAt(idx); } retVal = retVal + replacementWord; } return retVal; } public long size() { return this.filthyWords.size(); } public long compareValue() { return this.compareValue; } public String firstWord() { return this.filthyWords.size() > 0 ? this.filthyWords.elementAt(0) : new String(""); } public String asString() { return this.rawData; } }