
// WordNode.java
// Andrew Davison, ad@coe.psu.ac.th, Dec. 2022

/* Used by Doublets.java. Each word has a score, and a link
   back to the parent word that was modified to create this
   word.

   The score is used in a priority queue in Doublets.java
   to decide which word to modify. The highest scoring word
   is chosen.
*/


public class WordNode implements Comparable<WordNode>
{
  private String word;
  private int score;
  private WordNode parent;

  public WordNode(String s, int sc, WordNode p)
  {
    word = s;
    score = sc;
    parent = p;
  }

  public String getWord()
  {  return word;  }

  public int getScore()
  {  return score;  }

  public WordNode getParent()
  {  return parent;  }


  public String toString()
  {  return word + "; " + score;  }

  public int compareTo(WordNode wn)
  // score ordering is in descending order
  {
    if (score < wn.score)
      return 1;    // this object is ordered after wn
    else if (score > wn.score)
      return -1;  // this object is ordered before wn
    return 0;
  } /* compare */

}  // end of WordNode class
