// Path: src/com/android/wordzap/WordCache.java
// public interface WordCache {
// 
// 	// Returns true if word is valid, false otherwise
// 	boolean isWordValid(String word);
// 	
// 	//Returns list of all cached valid words
// 	List< String > getValidWords();
// 
// 	//Returns a random cached word
// 	String getRandomWord();
// 	
// 	//Returns a random cached word not in the list : wordList
// 	String getRandomWord(final List<String> wordList);
// 	
// }
// 
// Path: src/com/android/wordzap/exceptions/InvalidGridSizeException.java
// public class InvalidGridSizeException extends Exception {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -2800989629849259629L;
// 	private int numRows;
// 	private int numCols;
// 
// 	public InvalidGridSizeException(int numRows, int numCols) {
// 		this.numRows = numRows;
// 		this.numCols = numCols;
// 	}
// 
// 	public String toString() {
// 		String message = "";
// 		if (numRows < 0 || numCols < 0) {
// 			message = "Letter grid size cannot have negative dimensions";
// 			if (numRows < 0) {
// 				message += "\nNumber of rows : " + numRows
// 						+ " should have a positive value";
// 			}
// 			if (numCols < 0) {
// 				message += "\nNumber of columns : " + numCols
// 						+ " should have a positive value";
// 			}
// 		}
// 		return message;
// 	}
// 
// }
// 
// Path: src/com/android/wordzap/exceptions/InvalidStackOperationException.java
// public class InvalidStackOperationException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -1155556169006873406L;
// 
// 	public InvalidStackOperationException(String msg) {
// 		super(msg);
// 	}
// 
// }
// 
// Path: src/com/android/wordzap/exceptions/WordStackOverflowException.java
// public class WordStackOverflowException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 6708159980557380686L;
// 	private char letter;
// 	private int wordLimit;
// 
// 	public WordStackOverflowException(char letter, int wordLimit) {
// 		this.letter = letter;
// 		this.wordLimit = wordLimit;
// 	}
// 
// 	public String toString() {
// 		return "Stack exceeded limit : " + wordLimit
// 				+ " during addition of letter : " + letter;
// 	}
// 
// }


import java.util.Stack;
import java.util.Vector;
import com.android.wordzap.WordCache;
import com.android.wordzap.exceptions.InvalidGridSizeException;
import com.android.wordzap.exceptions.InvalidStackOperationException;
import com.android.wordzap.exceptions.WordStackOverflowException;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 
 * The MIT License : http://www.opensource.org/licenses/mit-license.php

 * Copyright (c) 2010 Kowshik Prakasam

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

package com.android.wordzap.datamodel;



/* 
 * Core class that abstracts the data model for the visual grid that the
 * human player sees on screen Offers an efficient interface to
 * manipulate the grid of letters
 * 
 */

public class LetterGrid {
	private int numRows;
	private int numCols;
	private Stack<WordStack> stackOfWords;
	private WordCache aWordCache;
	public static final String ROW_KEY = "row";
	public static final String COL_KEY = "col";
	public static final String LETTER_KEY = "letter";
	
	/*
	 * Negative numRows and numCols cause constructor to throw appropriate
	 * exceptions.
	 */
	public LetterGrid(int numRows, int numCols) throws InvalidGridSizeException {
		if (numRows > 0 && numCols > 0) {
			this.numRows = numRows;
			this.numCols = numCols;
			stackOfWords = new Stack<WordStack>();
		} else {
			throw new InvalidGridSizeException(numRows, numCols);
		}
		this.aWordCache = null;
	}

	/*
	 * Negative numRows and numCols cause constructor to throw appropriate
	 * exceptions.
	 */
	public LetterGrid(int numRows, int numCols, final WordCache aWordCache)
			throws InvalidGridSizeException {
		this(numRows, numCols);
		if (aWordCache == null) {
			throw new NullPointerException(
					"The cache object passed cant be null");
		}
		this.aWordCache = aWordCache;

	}

	// Getter for WordCache attribute
// Path: src/com/android/wordzap/WordCache.java
// public interface WordCache {
// 
// 	// Returns true if word is valid, false otherwise
// 	boolean isWordValid(String word);
// 	
// 	//Returns list of all cached valid words
// 	List< String > getValidWords();
// 
// 	//Returns a random cached word
// 	String getRandomWord();
// 	
// 	//Returns a random cached word not in the list : wordList
// 	String getRandomWord(final List<String> wordList);
// 	
// }
// 
// Path: src/com/android/wordzap/exceptions/InvalidGridSizeException.java
// public class InvalidGridSizeException extends Exception {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -2800989629849259629L;
// 	private int numRows;
// 	private int numCols;
// 
// 	public InvalidGridSizeException(int numRows, int numCols) {
// 		this.numRows = numRows;
// 		this.numCols = numCols;
// 	}
// 
// 	public String toString() {
// 		String message = "";
// 		if (numRows < 0 || numCols < 0) {
// 			message = "Letter grid size cannot have negative dimensions";
// 			if (numRows < 0) {
// 				message += "\nNumber of rows : " + numRows
// 						+ " should have a positive value";
// 			}
// 			if (numCols < 0) {
// 				message += "\nNumber of columns : " + numCols
// 						+ " should have a positive value";
// 			}
// 		}
// 		return message;
// 	}
// 
// }
// 
// Path: src/com/android/wordzap/exceptions/InvalidStackOperationException.java
// public class InvalidStackOperationException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -1155556169006873406L;
// 
// 	public InvalidStackOperationException(String msg) {
// 		super(msg);
// 	}
// 
// }
// 
// Path: src/com/android/wordzap/exceptions/WordStackOverflowException.java
// public class WordStackOverflowException extends Exception {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 6708159980557380686L;
// 	private char letter;
// 	private int wordLimit;
// 
// 	public WordStackOverflowException(char letter, int wordLimit) {
// 		this.letter = letter;
// 		this.wordLimit = wordLimit;
// 	}
// 
// 	public String toString() {
// 		return "Stack exceeded limit : " + wordLimit
// 				+ " during addition of letter : " + letter;
// 	}
// 
// }


// Path: src/com/android/wordzap/datamodel/LetterGrid.java
import java.util.Stack;
import java.util.Vector;
import com.android.wordzap.WordCache;
import com.android.wordzap.exceptions.InvalidGridSizeException;
import com.android.wordzap.exceptions.InvalidStackOperationException;
import com.android.wordzap.exceptions.WordStackOverflowException;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * The MIT License : http://www.opensource.org/licenses/mit-license.php

 * Copyright (c) 2010 Kowshik Prakasam

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

package com.android.wordzap.datamodel;



/* 
 * Core class that abstracts the data model for the visual grid that the
 * human player sees on screen Offers an efficient interface to
 * manipulate the grid of letters
 * 
 */

public class LetterGrid {
	private int numRows;
	private int numCols;
	private Stack<WordStack> stackOfWords;
	private WordCache aWordCache;
	public static final String ROW_KEY = "row";
	public static final String COL_KEY = "col";
	public static final String LETTER_KEY = "letter";
	
	/*
	 * Negative numRows and numCols cause constructor to throw appropriate
	 * exceptions.
	 */
	public LetterGrid(int numRows, int numCols) throws InvalidGridSizeException {
		if (numRows > 0 && numCols > 0) {
			this.numRows = numRows;
			this.numCols = numCols;
			stackOfWords = new Stack<WordStack>();
		} else {
			throw new InvalidGridSizeException(numRows, numCols);
		}
		this.aWordCache = null;
	}

	/*
	 * Negative numRows and numCols cause constructor to throw appropriate
	 * exceptions.
	 */
	public LetterGrid(int numRows, int numCols, final WordCache aWordCache)
			throws InvalidGridSizeException {
		this(numRows, numCols);
		if (aWordCache == null) {
			throw new NullPointerException(
					"The cache object passed cant be null");
		}
		this.aWordCache = aWordCache;

	}

	// Getter for WordCache attribute
	public WordCache getWordCache() {