jcsp.plugNplay
Class Xor
java.lang.Object
|
+--jcsp.plugNplay.Xor
- All Implemented Interfaces:
- CSProcess
- public final class Xor
- extends Object
- implements CSProcess
Bitwise xors two Integer streams to one stream.
Process Diagram
in1 _______
-->--| | out
in2 | Xor |-->--
-->--|_______|
Description
The Xor class is a process which has an infinite loop that waits
a Object of type Number to be sent down each of the in1 and in2 Channels.
The process then calculates the bitwise XOR on the intValue() of the
two Numbers then write the result as a new Integer down the out 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. The
program generates a sequence of numbers and XORs them from
Integer.MAX_VALUE to give a decending sequence of numbers and prints
this on the screen.
import jcsp.lang.*;
import jcsp.util.*;
public final class XorExample {
public static void main (String[] argv) {
final Channel a = new One2OneChannel ();
final Channel b = new One2OneChannel ();
final Channel c = new One2OneChannel ();
new Parallel (
new CSProcess[] {
new Numbers (a),
new Xor (a, b, c),
new CSProcess () {
public void run () {
Integer xorVal = new Integer (Integer.MAX_VALUE);
while (true) {
b.write (xorVal);
}
}
}
new Printer (c),
}
).run ();
}
}
- Author:
- 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 |
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
run
public void run()
- The main body of this process.
- Specified by:
run
in interface CSProcess
Submit a bug or feature to jcsp-team@ukc.ac.uk
Version 1.0-rc4 of the JCSP API Specification (Copyright 1997-2000 P.D.Austin and P.H.Welch - All Rights Reserved)
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.