/*
* Scrabaid
*
* Revisions:
*
* 18/05/2001 lc - v1.0 release
*
* ----------------------------------------------------------------------------
*
* Scrabaid version 1.0, Copyright 2001 Linus Chang
* Scrabaid comes with ABSOLUTELY NO WARRANTY; for details, view the LICENCE
* file included with this distribution. This is free software, and you are
* welcome to redistribute it under certain conditions; view the LICENCE
* file for details.
*/


class Pattern {
	static long [] characters;
	static final int MAX_HASH = 246011;
	static {	// FIX ME UP LATER
		characters = new long[128];
		for (char c = 'a'; c <= 'z'; c++)
			characters[c] = c - 'a';
	}

	private String m_pattern;
	public Pattern(String s) {
		m_pattern = s;
	}
	public String getString() {
		return m_pattern;
	}
	public String toString() {
		return m_pattern;
	}
	public int hashCode() {
		return m_pattern.hashCode();
	}
	public int getCustomHash() {
		long hash = 0L;
		for (int c = 0; c < m_pattern.length(); c++) {
			if (m_pattern.charAt(c) == ' ')
				hash += 26 + c % 5;
			else
				hash += characters[m_pattern.charAt(c)];
			if (c < m_pattern.length() - 1)
				hash *= 31;
		}
		return Math.abs((int) (hash % MAX_HASH));
	}
	public boolean doesWordMatch(Word w) {
		String sWord = w.getString();
		if (sWord.length() != m_pattern.length())
			return false;
		for (int c = 0; c < m_pattern.length(); c++)
			if (m_pattern.charAt(c) != ' ')
				if (m_pattern.charAt(c) != sWord.charAt(c))
					return false;
		return true;
	}
	public int length() {
		return m_pattern.length();
	}
	public boolean isBlank() {
		for (int c = 0; c < m_pattern.length(); c++)
			if (m_pattern.charAt(c) != ' ')
				return false;
		return true;
	}
	public static void main(String []args) throws ScrabaidException {
		Pattern p = new Pattern("l  anotations");

		System.out.println(p.getCustomHash());
/*		WordList wl = WordList.getInstance();
		Word[] words= wl.getWords()[13];
		System.out.println( words[3919]);
*/	}
}

