/**
 * Implements words with multiple representations
 */
public class Word implements Comparable
{
	private String word;
	private String sortWord;
	

	public Word(String fw)
	{
		word = fw;
		sortWord = sort();
	}
	

	private String sort()
	{
		StringBuffer sbuf = new StringBuffer(word);
  	
		for (int i = 0; i < sbuf.length() - 1; i++)
		{
			for (int j = i + 1; j < sbuf.length(); j++)
			{
				if (sbuf.charAt(j) < sbuf.charAt(i))
				{
					char temp = sbuf.charAt(j);
					sbuf.setCharAt(j,sbuf.charAt(i));
					sbuf.setCharAt(i,temp);
				}
			}
 		}
   	
		return new String(sbuf);
	}
	

 	public String getWord()
 	{
 		return word;
 	}
 	

 	public String getSorted()
 	{
 		return sortWord;
 	}
 	

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

 	public boolean equals(Object o)
 	{
 		return sortWord.equals(((Word)o).getSorted());
 	}
 	
 	public int hashCode()
 	{
 		//return 4;
 		return sortWord.hashCode();
 	}
 	
 
 	public int compareTo(Object other)
 	{
 		Word w = (Word)other;
 		return sortWord.compareTo(w.sortWord);
 	}
 	

 	public String toString()
 	{
 		return word + " " + sortWord;
 	}
 	
 	public static void main(String[] args)
 	{
 		Word w = new Word("hoser");
 		Word w2 = new Word("fred");
 		System.out.println(w.compareTo(w2));
 	}
 }
 