⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 word.java

📁 JAVA在编译原理上的应用。
💻 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&uuml;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 + -