package labs.undobox;

/***
 * Class that represents a value that can be undone.
 */
public class UndoBox {
  private String item;
  private String prev;

  /**
   * Constructor
   * @param value Initial value
   */
  public UndoBox(String value) {
    this.item = value;
    this.prev = value;
  }

  /**
   * Get the current value
   * @return Current value
   */
  public String getItem() {
    return item;
  }

  /**
   * Set the current value
   * @param value New value
   */
  public void setItem(String value) {
    this.prev = this.item; // Store previous value
    this.item = value;
  }

  /**
   * Undo the last change
   */
  public void undo() {
    this.item = this.prev; // Restore previous value
  }
}
