?? word.java
字號:
package lolo.scans;/** A recognizer class to scan for a string (a word). * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd Kühl</a> (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) */public class Word extends Scan { /** The word. */ protected final char[] word; /** Marks the next character inside <tt>word</tt> to find. */ protected transient int index; private int hashCode; /** Constructs an instance scanning the string <tt>word</tt>. * * @param word the string to search. * @throws IllegalArgumentException if <tt>word</tt> is <tt>null</tt> or contains no character. */ public Word(String word) throws IllegalArgumentException { if (word == null) throw new IllegalArgumentException("null word"); if (word.length() == 0) throw new IllegalArgumentException("word.length() == 0"); this.word = word.toCharArray(); this.hashCode = word.hashCode(); } public void reset() { index = 0; } public State nextChar(char ch) { boolean okay = ch == word[index++]; return stateObject.set( okay && index < word.length, // more okay && index == word.length // found ); } /** Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { return super.toString()+"["+new String(word)+"]"; } /** Returns a hash code value for this object. * * @return a hash code value for this object. */ public int hashCode() { return hashCode; } /** Compares the receiver to the specified object. The result is <tt>true</tt> if and only if * the argument is not <tt>null</tt> and is a <tt>Word</tt> object that represents the String * as this object.. * * @return Compares the receiver to the specified object. The result is <tt>true</tt> if and only if * the argument is not <tt>null</tt> and is a <tt>Word</tt> object that represents the String * as this object.. */ public boolean equals(Object o) { if (o == null || !(o instanceof Word)) return false; if (o == this) return true; final int length = word.length; for (int i = 0; i < length; i++) if (word[i] != ((Word) o).word[i]) return false; return true; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -