CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay
Class And

java.lang.Object
  |
  +--jcsp.plugNplay.And
All Implemented Interfaces:
CSProcess

public final class And
extends Object
implements CSProcess

Bitwise ands two Integer streams to one stream.

Process Diagram

    in0  _______
   -->--|       | out
    in1 |  And  |-->--
   -->--|_______|
 

Description

The And class is a process which has an infinite loop that waits a Object of type Number to be sent down each of the in0 and in1 Channels. The process then calculates the bitwise AND on the intValue() of the two Numbers then write the result as a new Integer down the out Channel.

Channel Protocols

Input Channels
in0, in1 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 And process in a small program. The program also uses some of the other building block processes. The program generates a sequence of numbers and rounds each odd number down to the nearest even number and prints this on the screen.
 import jcsp.lang.*;
 import jcsp.util.*;
 
 public class AndExample {
   public static void main (String[] argv) {
 
     Channel a = new One2OneChannel ();
     Channel b = new One2OneChannel ();
     Channel c = new One2OneChannel ();
 
     new Parallel (
       new CSProcess[] {
         new Numbers (a),
         new And (a, b, c),
         new Printer (c),
         new CSProcess () {
           public void run () {
             Integer andVal = new Integer (Integer.MAX_VALUE - 1);
             while (true) {
               b.write (andVal);
             }
           }
         }
       }
     ).run ();
 
   }
 
 }
 

Author:
P.D.Austin

Constructor Summary
And(ChannelInput in0, ChannelInput in1, ChannelOutput out)
          Construct a new And process with the input Channels in0 and in1 and the output Channel out.
 
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
 

Constructor Detail

And

public And(ChannelInput in0,
           ChannelInput in1,
           ChannelOutput out)
Construct a new And process with the input Channels in0 and in1 and the output Channel out. The ordering of the Channels in0 and in1 make no difference to the functionality of this process.
Parameters:
in0 - the first input Channel
in1 - the second input Channel
out - the output Channel
Method Detail

run

public void run()
The main body of this process.
Specified by:
run in interface CSProcess

CSP for Java
(JCSP) 1.0-rc4

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.