Class LogicGate

java.lang.Object
  |
  +--LogicGate
Direct Known Subclasses:
LogicAnd, LogicInput, LogicNand, LogicNode, LogicNor, LogicNot, LogicOr, LogicXnor, LogicXor

public abstract class LogicGate
extends java.lang.Object


Field Summary
protected  boolean calculated
          True if the gate has been calculated since the last time it was reset
protected  GraphicGate equivGate
          reference to the equivalent graphics gate
protected  int gateType
          Stores the type of Gate.
protected  int id
          the id number of the gate.
protected  LogicGate inputOne
          reference to gates providing input
protected  LogicGate inputTwo
           
protected  boolean lastOutputValue
           
protected  java.util.Vector outputs
          vector of all the gates output to
protected  boolean outputValue
          holds the output of the gate
protected  boolean sequential
          If true the gate is sequential, that is that it is in a loop from its output to its input.
 
Constructor Summary
(package private) LogicGate()
          basic constructor will not be used
(package private) LogicGate(java.lang.Object linkGate)
          Constructor that will always be used, it takes a graphical gate as its only argument which it will use as its equivalent gate
 
Method Summary
 void addInput(LogicGate newIn)
          Add an input to the gate
 void addOutput(LogicGate newOut)
          add a reference to a gate to output to
 void calcOutputs()
          This is basically a helper function for the extended classes when they calculate.
(package private)  void calculate()
          defined in each extended class will calculate the gate's output value
(package private)  void determineSequential(LogicGate checkGate)
          This method determines whether the gate sent to it as checkGate is is part of an input output loop which would mean that it is a sequential gate.
(package private) abstract  void evaluate()
           
 boolean getOutputValue()
           
(package private)  void printInfo()
           
 void removeInput(LogicGate oldIn)
          removes oldIn from the gate
 void removeOutput(LogicGate oldOut)
          remove a gate from the outputs of a gate.
 void resetCalculated()
          resets the calculated variable to false
 boolean returnOutput(LogicGate callingGate)
          returns the last output the gate calculated.
 void unlinkGates()
          unlinkGate takes all the gates that link to the gate as an input or an output and removes those links
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected int id
the id number of the gate. It will correspond to the id of graphical gate that is the equivalent to this logical gate.

outputValue

protected boolean outputValue
holds the output of the gate

lastOutputValue

protected boolean lastOutputValue

equivGate

protected GraphicGate equivGate
reference to the equivalent graphics gate

outputs

protected java.util.Vector outputs
vector of all the gates output to

inputOne

protected LogicGate inputOne
reference to gates providing input

inputTwo

protected LogicGate inputTwo

calculated

protected boolean calculated
True if the gate has been calculated since the last time it was reset

gateType

protected int gateType
Stores the type of Gate. It uses the values given in the GraphicalGate class

sequential

protected boolean sequential
If true the gate is sequential, that is that it is in a loop from its output to its input.
Constructor Detail

LogicGate

LogicGate()
basic constructor will not be used

LogicGate

LogicGate(java.lang.Object linkGate)
Constructor that will always be used, it takes a graphical gate as its only argument which it will use as its equivalent gate
Method Detail

calculate

void calculate()
defined in each extended class will calculate the gate's output value

evaluate

abstract void evaluate()

addOutput

public void addOutput(LogicGate newOut)
add a reference to a gate to output to

removeOutput

public void removeOutput(LogicGate oldOut)
remove a gate from the outputs of a gate. This method does not ensure that the gate referenced by oldOut has had this gate removed from its inputs

addInput

public void addInput(LogicGate newIn)
Add an input to the gate

removeInput

public void removeInput(LogicGate oldIn)
removes oldIn from the gate

unlinkGates

public void unlinkGates()
unlinkGate takes all the gates that link to the gate as an input or an output and removes those links

returnOutput

public boolean returnOutput(LogicGate callingGate)
returns the last output the gate calculated. I made this before I knew about the getWhatever convention and it's a fair bit of code internally so I just left it and added the get one too

getOutputValue

public boolean getOutputValue()

resetCalculated

public void resetCalculated()
                     throws calculateException
resets the calculated variable to false

calcOutputs

public void calcOutputs()
This is basically a helper function for the extended classes when they calculate. It will call calculate on all of the gate's outputs so that I don't have to write that out individually for each gate.

determineSequential

void determineSequential(LogicGate checkGate)
This method determines whether the gate sent to it as checkGate is is part of an input output loop which would mean that it is a sequential gate. I know that it is really ugly to have a line that wraps in the code but I couldn't see a good way to deal with it.

printInfo

void printInfo()