edu.nrao.sss.electronics
Class SignalSwitch

java.lang.Object
  extended by edu.nrao.sss.electronics.SignalSwitch
All Implemented Interfaces:
SignalProcessor, SignalSource

public class SignalSwitch
extends Object
implements SignalProcessor, SignalSource

A device that can connect one of its inputs to one of its outputs and pass signals through that connection. Only one input may be connected to an output, and only one output may be connected to an input. The remaining inputs and outputs (collectively, "poles") are not connected to any outputs or inputs, respectively.

For simultaneously connecting a single input to many outputs see the SignalManifold class. See also the SignalTransferSwitch for a variation of a switch that connects N inputs to N outputs simultaneously, with each pole connected to exactly one other, complementary, pole.

Signals pass through switches without being altered.

The following examples were all taken from the EVLA Antenna Block Diagram:

4 inputs, 1 output 2 inputs, 1 output
(assuming left-to-right flow)
1 input, 4 outputs 1 input, 2 outputs
(assuming left-to-right flow)

Note that indexing for input and output poles follows the java convention of starting with zero, which is different than what is displayed in the diagrams above. In addition to referencing poles by index, clients may name the input and output poles and then select them by name. If a client names two poles of the same kind (input or output) identically, the pole returned by the select-by-name methods is indeterminate.

Version Info:

$Revision: 1198 $
$Date: 2008-04-02 18:59:31 -0600 (Wed, 02 Apr 2008) $
$Author: dharland $ (last person to modify)

Since:
2007-10-24
Author:
David M. Harland

Method Summary
 void execute()
          Executes the currently selected output pipe of this device.
 void executeFromStartOfChainUpTo(SignalProcessor firstUnexecutedDevice)
          Retreats upstream from this processor to the source of the stream and executes that device(s), telling it to stop execution at firstUnexecutedDevice.
 void executeUpTo(SignalProcessor firstUnexecutedDevice)
          Executes this device and all downstream devices up to, but not including, the firstUnexecutedDevice.
 int getIndexOfSelectedInput()
          Returns the index of the currently selected input pole.
 int getIndexOfSelectedOutput()
          Returns the index of the currently selected output pole.
 SignalPipe getInputPipe(int index)
          Returns the indexth input pipe of this device.
 String getName()
          Returns the name of this switch.
 String getNameOfSelectedInput()
          Returns the name of the currently selected input pole.
 String getNameOfSelectedOutput()
          Returns the name of the currently selected output pole.
 List<String> getNamesOfInputPoles()
          Returns the names of the input poles of this switch.
 List<String> getNamesOfOutputPoles()
          Returns the names of the output poles of this switch.
 int getNumberOfInputPoles()
          Returns the number of input poles on this switch.
 int getNumberOfOutputPoles()
          Returns the number of output poles on this switch.
 SignalPipe getOutputPipe(int index)
          Returns the indexth output pipe of this device.
 SignalPipe getSelectedInput()
          Returns the currently selected input pole.
 SignalPipe getSelectedOutput()
          Returns the currently selected output pole.
 Signal getSignal()
          Returns the signal provided by the currently selected input pipe of this device.
 Signal getSignal(SignalPipe outputPipe)
           
 boolean hasInputNamed(String poleName)
          Returns true if this switch has an input with the given name.
 boolean hasOutputNamed(String poleName)
          Returns true if this switch has an output with the given name.
static SignalSwitch makeMultiInputSwitch(String deviceName, int numberOfInputPoles)
          Creates and returns a new switch with a single output pole and the given number of input poles.
static SignalSwitch makeMultiOutputSwitch(String deviceName, int numberOfOutputPoles)
          Creates and returns a new switch with a single input pole and the given number of output poles.
 void nameInputs(String... poleNames)
          Assigns names to the input poles of this switch.
 void nameOutputs(String... poleNames)
          Assigns names to the output poles of this switch.
 SignalPipe selectInput(int inputPole)
          Sets this switch so that it uses the input pole at the given index.
 SignalPipe selectInput(String poleName)
          Sets this switch so that it uses the input pole with the given name.
 SignalPipe selectOutput(int outputPole)
          Sets this switch so that it uses the output pole at the given index.
 SignalPipe selectOutput(String poleName)
          Sets this switch so that it uses the output pole with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeMultiInputSwitch

public static SignalSwitch makeMultiInputSwitch(String deviceName,
                                                int numberOfInputPoles)
Creates and returns a new switch with a single output pole and the given number of input poles.

Up to numberOfInputPoles sources may be hooked to this switch, but exactly one of them may be selected at any one time. Initially, the 0th input is the selected input.

Parameters:
deviceName - an optional name for this switch. If this value is null a default name will be used in its place.
numberOfInputPoles - the number of connections available for signal sources.
Returns:
a new switch with a single output and the given number of inputs.

makeMultiOutputSwitch

public static SignalSwitch makeMultiOutputSwitch(String deviceName,
                                                 int numberOfOutputPoles)
Creates and returns a new switch with a single input pole and the given number of output poles.

Up to numberOfOutputPoles signal processors may be hooked to this switch, but exactly one of them may be selected at any one time. Initially, the 0th output is the selected output.

Parameters:
deviceName - an optional name for this switch. If this value is null a default name will be used in its place.
numberOfOutputPoles - the number of connections available for signal processors.
Returns:
a new switch with a single input and the given number of outputs.

getName

public String getName()
Returns the name of this switch.

Returns:
the name of this switch.

getNumberOfInputPoles

public int getNumberOfInputPoles()
Returns the number of input poles on this switch.

Returns:
the number of input poles on this switch.

getNumberOfOutputPoles

public int getNumberOfOutputPoles()
Returns the number of output poles on this switch.

Returns:
the number of output poles on this switch.

hasInputNamed

public boolean hasInputNamed(String poleName)
Returns true if this switch has an input with the given name.

Parameters:
poleName - the potential name of an input pole of this switch.
Returns:
true if this switch has an input with the given name.

hasOutputNamed

public boolean hasOutputNamed(String poleName)
Returns true if this switch has an output with the given name.

Parameters:
poleName - the potential name of an output pole of this switch.
Returns:
true if this switch has an output with the given name.

nameInputs

public void nameInputs(String... poleNames)
Assigns names to the input poles of this switch. The names are assigned in the order presented, beginning with the pole at index zero.

Note: this method does not check the number of names submitted against the number of input poles.

Parameters:
poleNames - new names for the input poles of this switch.

nameOutputs

public void nameOutputs(String... poleNames)
Assigns names to the output poles of this switch. The names are assigned in the order presented, beginning with the pole at index zero.

Note: this method does not check the number of names submitted against the number of output poles.

Parameters:
poleNames - new names for the output poles of this switch.

getNamesOfInputPoles

public List<String> getNamesOfInputPoles()
Returns the names of the input poles of this switch.

The names are ordered according to the numerical order of the poles that they represent. For example, if the returned list is "Inky", "Blinky", "Pinky", and "Clyde", then the pole at index zero for this switch is named "Inky" and the pole at index three is "Clyde".

Returns:
the names of the input poles of this switch.

getNamesOfOutputPoles

public List<String> getNamesOfOutputPoles()
Returns the names of the output poles of this switch.

The names are ordered according to the numerical order of the poles that they represent. For example, if the returned list is "Larry", "Curly", "Moe", "Shemp", and "Curly Joe", then the pole at index one for this switch is named "Curly" and the pole at index two is "Moe".

Returns:
the names of the output poles of this switch.

selectInput

public SignalPipe selectInput(String poleName)
Sets this switch so that it uses the input pole with the given name. The selected input pole is returned.

Parameters:
poleName - the potential name of an input pole of this switch.
Returns:
the selected input.
Throws:
IllegalArgumentException - if this switch has no input pole with the given name.

selectInput

public SignalPipe selectInput(int inputPole)
Sets this switch so that it uses the input pole at the given index. Indexing begins with zero. The selected input pole is returned.

Parameters:
inputPole - the index of the input pole to be connected to this switch's selected output.
Returns:
the selected input.
Throws:
IndexOutOfBoundsException - if inputPole is < 0 or >= the number of input poles.

selectOutput

public SignalPipe selectOutput(String poleName)
Sets this switch so that it uses the output pole with the given name. The selected output pole is returned.

Parameters:
poleName - the potential name of an output pole of this switch.
Returns:
the selected output.
Throws:
IllegalArgumentException - if this switch has no output pole with the given name.

selectOutput

public SignalPipe selectOutput(int outputPole)
Sets this switch so that it uses the output pole at the given index. Indexing begins with zero. The selected output pole is returned.

Parameters:
outputPole - the index of the output pole to be connected to this switch's selected input.
Returns:
the selected output.
Throws:
IndexOutOfBoundsException - if outputPole is < 0 or >= the number of output poles.

getSelectedInput

public SignalPipe getSelectedInput()
Returns the currently selected input pole.

Returns:
the currently selected input pole.

getSelectedOutput

public SignalPipe getSelectedOutput()
Returns the currently selected output pole.

Returns:
the currently selected output pole.

getInputPipe

public SignalPipe getInputPipe(int index)
Returns the indexth input pipe of this device. A typical usage pattern for this method is:
 myFilter.getInputPipe(p).connectInputTo(mySource);

Indexing begins at zero.

Returns:
the indexth input pipe of this device.

getOutputPipe

public SignalPipe getOutputPipe(int index)
Returns the indexth output pipe of this device. A typical usage pattern for this method is:
 myFilter.getOutputPipe(p).connectOutputTo(myProcessor);

Indexing begins at zero.

Returns:
the indexth output pipe of this device.

getIndexOfSelectedInput

public int getIndexOfSelectedInput()
Returns the index of the currently selected input pole. Indexing begins at zero.

Returns:
the index of the currently selected input pole.

getIndexOfSelectedOutput

public int getIndexOfSelectedOutput()
Returns the index of the currently selected output pole. Indexing begins at zero.

Returns:
the index of the currently selected output pole.

getNameOfSelectedInput

public String getNameOfSelectedInput()
Returns the name of the currently selected input pole.

Returns:
the name of the currently selected input pole.

getNameOfSelectedOutput

public String getNameOfSelectedOutput()
Returns the name of the currently selected output pole.

Returns:
the name of the currently selected output pole.

getSignal

public Signal getSignal()
Returns the signal provided by the currently selected input pipe of this device. If nothing is connected to that input pipe, or if the connected source has a null signal, null will be returned.

Specified by:
getSignal in interface SignalSource
Returns:
the signal provided by this device.

getSignal

public Signal getSignal(SignalPipe outputPipe)

execute

public void execute()
Executes the currently selected output pipe of this device.

Specified by:
execute in interface SignalProcessor

executeUpTo

public void executeUpTo(SignalProcessor firstUnexecutedDevice)
Description copied from interface: SignalProcessor
Executes this device and all downstream devices up to, but not including, the firstUnexecutedDevice. See SignalProcessor.execute() for more information about the linking of processors.

Specified by:
executeUpTo in interface SignalProcessor
Parameters:
firstUnexecutedDevice - the first device downstream that is not to be executed. If all downstream devices should be executed you may use a null value here or call SignalProcessor.execute().

executeFromStartOfChainUpTo

public void executeFromStartOfChainUpTo(SignalProcessor firstUnexecutedDevice)
Description copied from interface: SignalProcessor
Retreats upstream from this processor to the source of the stream and executes that device(s), telling it to stop execution at firstUnexecutedDevice.

Specified by:
executeFromStartOfChainUpTo in interface SignalProcessor
Parameters:
firstUnexecutedDevice - the first device in a chain of processors that is not to be executed. If all devices should be executed you may use a null value here. The first unexecuted device should be downstream of this device.


Copyright © 2009. All Rights Reserved.