/*
	15-111 Moose Sections
	Lab 6
	Name: bjmoose, extended for Lab 10 by mjs
  Date: 09.23.01
*/

public class ScrabbleWord implements Comparable
{
	private String normal, sorted;
	private int value;

	public ScrabbleWord(String s)
	{
		this(0,s);
	}

	public ScrabbleWord(int v, String s)
	{
		normal = s;
		sorted = sort();
		value = v;
	}

	private String sort()
	{
		StringBuffer buff = new StringBuffer(normal);

		for (int b = 0; b < buff.length() - 1; b++) {
   			for (int c = b+1; c < buff.length(); c++) {
				if (buff.charAt(c) < buff.charAt(b)) {
					char temp = buff.charAt(c);
   					buff.setCharAt(c,buff.charAt(b)) ;
   					buff.setCharAt(b,temp);
   				}
   			}
   		}

   		return new String(buff);
	}

	public int getValue()
	{
		return value;
	}

 	public String getWord()
 	{
 		return normal;
 	}

 	public String getSorted()
 	{
 		return sorted;
 	}

 	public boolean equals(String key)
 	{
 		return sorted.equals(key);
 	}

 	public boolean equals(ScrabbleWord key)
 	{
 		return sorted.equals(key.getSorted() );
 	}

 	public String toString()
 	{
	    return normal;
 	}

 	public int compareTo(Object o)
 	{
 		if (!(o instanceof ScrabbleWord))
 			throw new IllegalArgumentException("Object not a word");

 		ScrabbleWord w = (ScrabbleWord)o;
 		return sorted.compareTo(w.sorted);
 	}
 }
