Package api

Class Pin


  • public class Pin
    extends java.lang.Object
    A Pin represents a connection point in a digital circuit. Each Pin has a value of 0 or 1, and may be valid or invalid. An Pin may be connected to zero or more other Pins, in which case setting its value will also set the values of connected Pins.
    • Constructor Summary

      Constructors 
      Constructor Description
      Pin​(IComponent parent)
      Constructs a Pin with the given parent component.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(IPinListener listener)
      Adds the given listener to this Pin's list of listeners.
      void connectTo​(Pin destination)
      Add a connection from this Pin to the given destination.
      java.util.ArrayList<Pin> getConnections()
      Returns the list of Pins connected to this one.
      IComponent getParent()
      Returns a reference to the component to which this Pin belongs
      int getValue()
      Returns the value stored in this pin.
      void invalidate()
      Sets this Pin to the invalid state.
      boolean isValid()
      Returns whether this Pin is currently valid.
      void set​(int givenValue)
      Sets this Pin to have the given value (0 or 1) and changes the state to valid.
      java.lang.String toString()
      Returns a String representation of this Pin's value as either "0" or "1", or "-" if the state is invalid.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Pin

        public Pin​(IComponent parent)
        Constructs a Pin with the given parent component. Initially the state is invalid and the value is zero.
        Parameters:
        parent - the component to which this pin belonds
    • Method Detail

      • getParent

        public IComponent getParent()
        Returns a reference to the component to which this Pin belongs
        Returns:
        reference to the parent component
      • connectTo

        public void connectTo​(Pin destination)
        Add a connection from this Pin to the given destination.
        Parameters:
        destination - the Pin that is to be connected to this one
      • getConnections

        public java.util.ArrayList<Pin> getConnections()
        Returns the list of Pins connected to this one.
        Returns:
        list of Pins connected to this one
      • getValue

        public int getValue()
        Returns the value stored in this pin.
        Returns:
        value stored in this pin
      • invalidate

        public void invalidate()
        Sets this Pin to the invalid state. Note that this method does not modify connected Pins.
      • isValid

        public boolean isValid()
        Returns whether this Pin is currently valid.
        Returns:
        whether this Pin is valid
      • set

        public void set​(int givenValue)
        Sets this Pin to have the given value (0 or 1) and changes the state to valid. All connected Pins are also set with the same value.
        Parameters:
        givenValue - value to be set
      • toString

        public java.lang.String toString()
        Returns a String representation of this Pin's value as either "0" or "1", or "-" if the state is invalid.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the value
      • addListener

        public void addListener​(IPinListener listener)
        Adds the given listener to this Pin's list of listeners.
        Parameters:
        listener - the listener to be added