package jsetool.data; import java.io.Serializable; import java.util.NoSuchElementException; import java.util.Vector; import jsetool.data.*; /** * This class contains information about a single machine, including * it's state and it's communication channel. * * @author Mike Lawson * */ public class ExplorationStateContainer implements Serializable { protected MachineState machineState; protected Vector communicationChannel = new Vector(); // contains the messages for m1 at this stage protected int channelMaxSize = 0; // The maximum size the communication channel ever obtained. /** * Default constructor * */ public ExplorationStateContainer() { } /** * Copy constructor * @param other */ public ExplorationStateContainer(ExplorationStateContainer other) { this.machineState = other.getMachineState(); this.communicationChannel = new Vector(other.getCommunicationChannel()); this.channelMaxSize = other.getChannelMaxSize(); } /** * @return Returns the machineState. */ public MachineState getMachineState() { return machineState; } /** * @param machineState The machineState to set. */ public void setMachineState(MachineState machineState) { this.machineState = machineState; } /** * @return Returns the communicationChannel. */ public Vector getCommunicationChannel() { return communicationChannel; } /** * Appends the given message to the channel. * * @param message */ public void appendMessage(String message) { communicationChannel.add(message); // Keep track of the maximum size of the channel. if (communicationChannel.size() > channelMaxSize) { channelMaxSize = communicationChannel.size(); } } /** * Takes a peek at the first message in the communications channel. * @return String */ public String peekFirstMessage() { try { return (String)communicationChannel.firstElement(); } catch (NoSuchElementException n) { return null; } } /** * Returns the maximum size of the communication channel. * @return int */ public int getChannelMaxSize() { return channelMaxSize; } /** * Returns true of the other object is equal to this one, based * on the state and the communication channel. * @param obj - the other object to compare * @return boolean */ public boolean equals(Object obj) { if (! (obj instanceof ExplorationStateContainer)) { return false; } ExplorationStateContainer other = (ExplorationStateContainer)obj; // equality is based on both machines being in the same state // and the values in the communication channels are exactly the same. if (! machineState.equals(other.getMachineState())) { return false; } if (communicationChannel.equals(other.getCommunicationChannel())) { return true; } else { return false; } } /** * Returns a hash for this object * @return int */ public int hashCode() { int cornedBeef = 37; cornedBeef ^= machineState.hashCode(); cornedBeef ^= 37 * communicationChannel.hashCode(); return cornedBeef; } }