package sale;

import users.User;

/**
  * Convenience implementation of a Transition that simply changes to another gate. Additionally, some other
  * useful Transitions are provided.
  *
  * @see Transition
  * @see Gate
  *
  * @author Steffen Zschaler
  * @version 2.0 17/08/1999
  * @since v2.0
  */
public class GateChangeTransition extends Object implements Transition {

  /**
    * The target gate.
    *
    * @serial
    */
  protected Gate m_gTarget;

  /**
    * Create a new GateChangeTransition.
    *
    * @param gTarget the Gate to change to.
    */
  public GateChangeTransition (Gate gTarget) {
    super();

    m_gTarget = gTarget;
  }

  /**
    * Perform the Transition. I.e. go to the gate indicated on creation.
    *
    * @override Never
    */
  public final Gate perform (SaleProcess p, User u) {
    return m_gTarget;
  }

  // some convenience constants
  /**
    * Transition that will go to the calling process' {@link SaleProcess#getRollbackGate rollback gate}.
    */
  public static final Transition CHANGE_TO_ROLLBACK_GATE = new Transition() {
    public Gate perform (SaleProcess p, User u) {
      return p.getRollbackGate();
    }
  };

  /**
    * Transition that will go to the calling process' {@link SaleProcess#getCommitGate commit gate}.
    */
  public static final Transition CHANGE_TO_COMMIT_GATE = new Transition() {
    public Gate perform (SaleProcess p, User u) {
      return p.getCommitGate();
    }
  };

  /**
    * Transition that will go to the calling process' {@link SaleProcess#getQuitGate quit gate}.
    */
  public static final Transition CHANGE_TO_QUIT_GATE = new Transition() {
    public Gate perform (SaleProcess p, User u) {
      return p.getQuitGate();
    }
  };

  /**
    * Transition that will go to the calling process' {@link SaleProcess#getStopGate stop gate}.
    */
  public static final Transition CHANGE_TO_STOP_GATE = new Transition() {
    public Gate perform (SaleProcess p, User u) {
      return p.getStopGate();
    }
  };

  /**
    * Transition that will go to the calling process' {@link SaleProcess#getLogGate log gate}.
    */
  public static final Transition CHANGE_TO_LOG_GATE = new Transition() {
    public Gate perform (SaleProcess p, User u) {
      return p.getLogGate();
    }
  };
}