All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.util.buildingblocks.And

java.lang.Object
   |
   +----jcsp.util.buildingblocks.And

public final class And
extends Object
implements CSProcess

Process Diagram

    in1  _______
   -->--|       | out
    in2 |  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 in1 and in2 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
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 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 Nos(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 Index

 o And(ChannelInput, ChannelInput, ChannelOutput)
Construct a new And process with the input Channels in1 and in2 and the output Channel out.

Method Index

 o run()
The main body of this process.

Constructors

 o And
 public And(ChannelInput in1,
            ChannelInput in2,
            ChannelOutput out)
Construct a new And 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 Channel
in2 - The second input Channel
out - The output Channel

Methods

 o run
 public void run()
The main body of this process.


All Packages  Class Hierarchy  This Package  Previous  Next  Index