Package org.jcsp.plugNplay
Class Xor
- java.lang.Object
-
- org.jcsp.plugNplay.Xor
-
- All Implemented Interfaces:
CSProcess
public final class Xor extends java.lang.Object implements CSProcess
Bitwise xors two Integer streams to one stream.Process Diagram
in0 _____ -->--| | out in1 | Xor |-->-- -->--|_____|
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 then calculates the bitwise XOR on the values of the two Numbers 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 to use the Xor process in a small program. The program also uses some of the other building block processes. It generates a sequence of numbers, XORs them with Integer.MAX_VALUE to give a decending sequence of numbers (from Integer.MAX_VALUE) and prints this on the screen.import org.jcsp.lang.*; import org.jcsp.plugNplay.*; public class XorExample { public static void main (String[] argv) { One2OneChannel a = Channel.one2one (); One2OneChannel b = Channel.one2one (); One2OneChannel c = Channel.one2one (); new Parallel ( new CSProcess[] { new Numbers (a.out ()), new Generate (b.out (), Integer.MAX_VALUE), new Xor (a.in (), b.in (), c.out ()), new Printer (c.in (), "--> ", "\n") } ).run (); } }
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelInput
in1
The first input Channelprivate ChannelInput
in2
The second input Channelprivate ChannelOutput
out
The output Channel
-
Constructor Summary
Constructors Constructor Description Xor(ChannelInput in1, ChannelInput in2, ChannelOutput out)
Construct a new Xor process with the input Channels in1 and in2 and the output Channel out.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
run()
The main body of this process.
-
-
-
Field Detail
-
in1
private final ChannelInput in1
The first input Channel
-
in2
private final ChannelInput in2
The second input Channel
-
out
private final ChannelOutput out
The output Channel
-
-
Constructor Detail
-
Xor
public Xor(ChannelInput in1, ChannelInput in2, ChannelOutput out)
Construct a new Xor 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
-
-