package jsetool.data; import java.io.Serializable; import java.util.Iterator; import java.util.Vector; /** * @author Mike Lawson * * @since Oct 20, 2004 * * The MachineState class represents a Machine State in the * CFSM. It is composed of a name and a set of transitions. * * */ public class MachineState implements Serializable { /** The name of the state */ protected String stateName; /** True if this state has already been explored.*/ protected boolean explored = false; // To make it easier in differentiating the two, I'm splitting up the transitions // based on type. /** SEND transitions */ protected Vector sendTransitions = new Vector(); /** RECEIVE transitions */ protected Vector receiveTransitions = new Vector(); /** * Returns true if state has been explored. * @return boolean */ public boolean isExplored() { return explored; } /** * Sets this object as having been explored */ public void setExplored() { explored = true; } /** * @return Returns the stateName. */ public String getStateName() { return stateName; } /** * Sets the name of this state. * @param stateName The stateName to set. */ public void setStateName(String stateName) { this.stateName = stateName; } /** * Returns an iterator over the send transitions. * @return Iterator */ public Iterator getSendTransitions() { return sendTransitions.iterator(); } /** * Returns an iterator over the receive transitions. * @return Iterator */ public Iterator getReceiveTransitions() { return receiveTransitions.iterator(); } /** * Adds the given transition to this machine state. * * @param transition The transition to add */ public void addTransition(Transition transition) { if (transition.getTransitionType() == Transition.SEND) { addSendTransition(transition); } else { addReceiveTransition(transition); } } /** * Returns a string-ified version of this object * @return String */ public String toString() { return stateName; } /** * Returns a hash code for this object. * @return int */ public int hashCode() { return stateName.hashCode(); } /** * Returns true if the other object equals this one. * Equality is based solely on state name * * @param other * * @return boolean */ public boolean equals(Object other) { if ( ! ( other instanceof MachineState)) { return false; } MachineState otherMS = (MachineState)other; return otherMS.getStateName().equals(getStateName()); } /** * Adds a send transition * @param t * */ protected void addSendTransition(Transition t) { sendTransitions.add(t); } /** * Adds a receive transition to this state. * @param t */ protected void addReceiveTransition(Transition t) { receiveTransitions.add(t); } }