org.jcsp.plugNplay
Class Plus
java.lang.Object
org.jcsp.plugNplay.Plus
- All Implemented Interfaces:
- CSProcess
public final class Plus
- extends Object
- implements CSProcess
Sums two Integer streams to one stream.
Process Diagram
in0 ______
-->--| | out
in1 | Plus |-->--
-->--|______|
Description
This is a process with an infinite loop that waits for
a Object of type Number to be sent down each of its input channels.
The loop body adds them together and writes the result as a new Integer
to its output channel.
Channel Protocols
Input Channels |
in1,in2 |
java.lang.Number |
Both Channels can accept data from any subclass of Number. It is
possible to send Floats down one channel and Integers down the
other. However all values will be converted to ints.
|
Output Channels |
out |
java.lang.Integer |
The output will always be of type Integer.
|
Example
The following example shows how the use of this process in a small program.
The program also uses some of the other building block processes.
It generates two sequences of numbers, adds them together and
prints them to the screen.
import org.jcsp.lang.*;
import org.jcsp.plugNplay.*;
public class PlusExample {
public static void main (String[] argv) {
final One2OneChannel a = Channel.one2one ();
final One2OneChannel b = Channel.one2one ();
final One2OneChannel c = Channel.one2one ();
new Parallel (
new CSProcess[] {
new Numbers (a.out ()),
new Numbers (b.out ()),
new Plus (a.in (), b.in (), c.out ()),
new Printer (c.in (), "--> ", "\n")
}
).run ();
}
}
- Author:
- P.H. Welch and P.D. Austin
Method Summary |
void |
run()
The main body of this process. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Plus
public Plus(ChannelInput in1,
ChannelInput in2,
ChannelOutput out)
- Construct a new Plus process with the input Channels in1 and in2 and the
output Channel out. The ordering of the Channels in1 and in2 make
no difference to the functionality of this process.
- Parameters:
in1
- The first input Channelin2
- The second input Channelout
- The output Channel
run
public void run()
- The main body of this process.
- Specified by:
run
in interface CSProcess
Copyright © 1996-2012. All Rights Reserved.