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

Use the SlicerMap to compute the sum of odd and even numbers separately. More...

Static Public Member Functions

static void main (String[] args)
 

Detailed Description

Use the SlicerMap to compute the sum of odd and even numbers separately.

Graphically, this can be represented as:

Processor chain

The expected output of this program is:

{1=1.0}
{1=1.0, 6=1.0}
{1=1.0, 4=1.0, 6=1.0}
{1=1.0, 3=1.0, 4=1.0, 6=1.0}
{1=1.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0}
{1=2.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0}
{1=2.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0, 9=1.0}
…
Author
Sylvain Hallé
See also
SlicerSimple Easy

Definition at line 57 of file SlicerOddEven.java.

Member Function Documentation

◆ main()

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

We first setup a stream of numbers to be used as a source

Definition at line 59 of file SlicerOddEven.java.

60  {
61  /// We first setup a stream of numbers to be used as a source
62  QueueSource source = new QueueSource();
63  source.setEvents(1, 6, 4, 3, 2, 1, 9);
64 
65  /* The function we'll use to create slices is the identity.
66  * This will create one distinct subtrace per number .*/
67  Function slicing_fct = new IdentityFunction(1);
68 
69  /* The processor chain to apply to each subtrace is a simple
70  * counter of events. */
71  GroupProcessor counter = new GroupProcessor(1, 1);
72  {
73  TurnInto to_one = new TurnInto(new Constant(1));
74  Cumulate sum = new Cumulate(new CumulativeFunction<Number>(Numbers.addition));
75  Connector.connect(to_one, sum);
76  counter.addProcessors(to_one, sum);
77  counter.associateInput(INPUT, to_one, INPUT);
78  counter.associateOutput(OUTPUT, sum, OUTPUT);
79  }
80 
81  /* Create the slicer processor, by giving it the slicing function and
82  * the processor to apply on each slide. */
83  Slice slicer = new Slice(slicing_fct, counter);
84  Connector.connect(source, slicer);
85 
86  /* Let us now pull and print 10 events from the slicer. */
87  Pullable p = slicer.getPullableOutput();
88  for (int i = 0; i < 10; i++)
89  {
90  Object o = p.pull();
91  System.out.println(o);
92  }
93  ///
94  }

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