Code Examples
A repository of 155 code examples for BeepBeep
basic.SumTwo Class Reference

Use the Trim and Fork processors to compute the sum of two successive events. More...

Static Public Member Functions

static void main (String[] args)
 

Detailed Description

Use the Trim and Fork processors to compute the sum of two successive events.

The chain of processors in this example can be represented graphically as:

Processor graph
Author
Sylvain Hallé Easy

Definition at line 38 of file SumTwo.java.

Member Function Documentation

◆ main()

static void basic.SumTwo.main ( String []  args)
static

Create a source of arbitrary numbers

Definition at line 40 of file SumTwo.java.

41  {
42  /// Create a source of arbitrary numbers
43  QueueSource source = new QueueSource().setEvents(1, 2, 3, 4, 5, 6);
44 
45  // Fork the stream in two and connect it to the source
46  Fork fork = new Fork(2);
47  Connector.connect(source, fork);
48 
49  // Create an addition processor. Connect its first input to the
50  // first output of the fork.
51  ApplyFunction add = new ApplyFunction(Numbers.addition);
52  Connector.connect(fork, 0, add, 0);
53 
54  /* Create an instance of the Trim processor. This processor is
55  * instructed to discard the first 1 events it receives. Then
56  * connect this to the second output of the fork, and to the
57  * second input of add. */
58  Trim trim = new Trim(1);
59  Connector.connect(fork, 1, trim, 0);
60  Connector.connect(trim, 0, add, 1);
61 
62  /* Let us now print what we receive by pulling on the output of
63  * add. */
64  Pullable p = add.getPullableOutput();
65  for (int i = 0; i < 6; i++)
66  {
67  float x = (Float) p.pull();
68  System.out.println("The event is: " + x);
69  }
70  ///
71  }

The documentation for this class was generated from the following file: