0.11.4
ca.uqac.lif.cep.io.Print Class Reference

Detailed Description

Sends its input to a PrintStream (such as the standard output).

This processor takes whatever event it receives (i.e. any Java Object), calls its toString() method, and pushes the resulting output to a print stream. Graphically, it is represented as:

Print

The behaviour of this processor can be configured in a few ways. Methods setPrefix() and setSuffix() can specify the character string to be displayed before and after each event, and method setSeparator() defines the symbol that is inserted between each event. Further customization of the output can be achieved by passing to a fancier type of print stream, such as an ANSI-aware printer.

Author
Sylvain Hallé
Since
0.1

Definition at line 44 of file Print.java.

Classes

class  Println
 A special type of Print processor that prints a carriage return by default between tokens. More...

Public Member Functions

 Print ()
 Creates a new printer with an input arity of 1 and sending its output to the standard output.
 Print (int in_arity, PrintStream out)
 Creates a new print processor.
 Print (PrintStream out)
 Creates a new print processor with input arity 1.
void reset ()
 Resets the processor.
Print setPrefix (String prefix)
 Sets a prefix to display before each event.
Print setSuffix (String suffix)
 Sets a suffix to display before each event.
Print setSeparator (String separator)
 Sets a separator to display after each event.
PrintStream getPrintStream ()
 Gets a reference to the print stream to which the character strings will be sent.
Print setPrintStream (PrintStream printer)
 Sets the print stream to which the character string will be sent.
void stop ()
 Stops the processor.
void close ()
 Closes the underlying PrintStream.
Print duplicate (boolean with_state)
 Duplicates an object.
Public Member Functions inherited from ca.uqac.lif.cep.tmf.Sink
 Sink ()
 Sink (int in_arity)
final void pull ()
 Tells the sink to pull events from the pipeline.
final void pullHard ()
 Tells the sink to pull events from the pipeline.
Public Member Functions inherited from ca.uqac.lif.cep.SynchronousProcessor
 SynchronousProcessor (int in_arity, int out_arity)
 Initializes a processor.
Pushable getPushableInput (int index)
 Returns the Pushable corresponding to the processor's i-th input trace.
Pullable getPullableOutput (int index)
 Returns the Pullable corresponding to the processor's i-th output trace.
final SynchronousProcessor setEventTracker (EventTracker tracker)
 Associates an event tracker to this processor.
Public Member Functions inherited from ca.uqac.lif.cep.Processor
 Processor (int in_arity, int out_arity)
 Initializes a processor.
final Object getContext (String key)
 Retrieves an object from the processor's context.
Context getContext ()
 Gets the context associated to this object.
void setContext (String key, Object value)
 Adds an object to the object's context.
void setContext (Context context)
 Adds a complete context to this object.
final int hashCode ()
 Implementation of hashCode() specific to processors.
final boolean equals (Object o)
 Implementation of equals() specific to processors.
final int getId ()
 Fetches the processor instance's unique ID.
final Pushable getPushableInput ()
 Returns the Pushable corresponding to the processor's first input trace.
final Pullable getPullableOutput ()
 Returns the Pullable corresponding to the processor's first output trace.
void setPullableInput (int i, Pullable p)
 Assigns a Pullable to the processor's i-th input.
Pullable getPullableInput (int i)
 Returns the Pullable corresponding to the processor's i-th input.
void setPushableOutput (int i, Pushable p)
 Assigns a Pushable to the processor's i-th output.
Pushable getPushableOutput (int i)
 Retrieves the Pushable associated to the processor's i-th output.
final int getInputArity ()
 Returns the processor's input arity.
final int getOutputArity ()
 Returns the processor's output arity.
void duplicateInto (Processor p)
 Copies the contents and state of the current processor into another.
final Set< Class<?> > getInputType (int index)
 Gets the type of events the processor accepts for its i-th input trace.
void getInputTypesFor (Set< Class<?> > classes, int index)
 Populates the set of classes accepted by the processor for its i-th input.
Class<?> getOutputType (int index)
 Returns the type of the events produced by the processor for its i-th output.
void start ()
 Starts the processor.
final EventTracker getEventTracker ()
 Gets the instance of event tracker associated to this processor.
void associateToInput (int in_stream_index, int in_stream_pos, int out_stream_index, int out_stream_pos)
 Associates an input event to an output event.
void associateTo (NodeFunction f, int out_stream_index, int out_stream_pos)
 Associates a node function to a particular event of processor's output stream.
void associateToOutput (int in_stream_index, int in_stream_pos, int out_stream_index, int out_stream_pos)
 Associates an input event to an output event.
final int getInputCount ()
 Gets the number of event fronts received so far by this processor.
final int getOutputCount ()
 Gets the number of event fronts produced so far by this processor.
final Object print (ObjectPrinter<?> printer) throws ProcessorException
 Prints the contents of this processor into an object printer.
final Processor read (ObjectReader<?> reader, Object o) throws ProcessorException
 Reads the content of a processor from a serialized object.
final Processor duplicate ()
 Duplicates an object and sets it to its initial state.
void copyInputQueue (int index, Collection< Object > to)
 Copies the content of one of the processor's input queue to a collection.
void copyOutputQueue (int index, Collection< Object > to)
 Copies the content of one of the processor's output queue to a collection.
Processor or (Processor p)
 Connects the first output pipe of this processor to the first input pipe of another processor.
Processor or (CallAfterConnect c)
 Operates similar to or(Processor), but also calls a method after the connection has been established.
Processor or (SelectedInputPipe p)
 Connects the output at index 0 of the current processor to the input of another processor.
PipeSelector getAt (int index)
 Gets the PipeSelector object corresponding to the processor's input or output pipe for a given index.
Pushable rightShift (int index)
Pullable leftShift (int index)
Queue< Object > getInputQueue (int index)
 Gets the content of the processor's input queue at a given index.
Queue< Object > getOutputQueue (int index)
 Gets the content of the processor's output queue at a given index.

Protected Member Functions

boolean compute (Object[] inputs, Queue< Object[]> outputs)
 Computes one or more output events from its input events.
void beforeEvent (PrintStream ps)
 Method that is called before an event is to be printed.
void afterEvent (PrintStream ps)
 Method that is called after an event is be printed.
void beforeSeparator (PrintStream ps)
 Method that is called before an separator is to be printed.
void afterSeparator (PrintStream ps)
 Method that is called after a separator is be printed.
void prettyPrint (PrintStream ps, Object o)
 Prints an object in an eye-pleasing way.
void prettyPrint (Number n)
 Prints a number in an eye-pleasing way.
void prettyPrint (Object[] array)
 Prints an array in an eye-pleasing way.
void copyInto (Print print, boolean with_state)
 Copies the member fields of the current processor into that of another Print processor.
Protected Member Functions inherited from ca.uqac.lif.cep.Processor
boolean allNotifiedEndOfTrace ()
 Determines if all the upstream pushables have sent the end of trace notification.
final Context newContext ()
 Creates a new empty context map.
boolean onEndOfTrace (Queue< Object[]> outputs) throws ProcessorException
 Allows to describe a specific behavior when the trace of input fronts has reached its end.
Object printState ()
 Produces an object that represents the state of the current processor.
Processor readState (Object o)
 Reads the state of a processor and uses it to create a new instance.

Protected Attributes

transient PrintStream m_out
 The stream to print to.
String m_separator = ","
 The separator between each event.
String m_prefix = ""
 The prefix to display before each event.
String m_suffix = ""
 The suffix to display after each event.
boolean m_firstOut
 A flag determining if the printed token is the first.
Protected Attributes inherited from ca.uqac.lif.cep.SynchronousProcessor
final transient Queue< Object[]> m_tempQueue
 A queue object that will be passed to the compute(Object[], Queue) method.
final transient Pushable[] m_inputPushables
 An array of input pushables.
transient Pullable[] m_outputPullables
 An array of output pullables.
Protected Attributes inherited from ca.uqac.lif.cep.Processor
int m_inputArity
 The processor's input arity, i.e.
int m_outputArity
 The processor's output arity, i.e.
transient Queue< Object >[] m_inputQueues
 An array of input event queues.
transient EventTracker m_eventTracker = null
 An object that keeps track of the relationship between input and output events.
transient Queue< Object >[] m_outputQueues
 An array of output event queues.
transient Pullable[] m_inputPullables
 An array of Pullables, one for each input trace this processor receives.
transient Pushable[] m_outputPushables
 An array of Pushables, one for each output trace this processor produces.
int m_inputCount = 0
 A counter incremented upon each input front processed.
int m_outputCount = 0
 A counter incremented upon each output front processed.
Context m_context = null
 The context in which the processor is instantiated.
boolean[] m_hasBeenNotifiedOfEndOfTrace
 Indicates whether the processor has been notified of the end of trace or not.
boolean m_notifiedEndOfTraceDownstream
 Indicates whether the processor has notified the end of the trace to the downstream processors it is connected to.

Additional Inherited Members

Static Public Member Functions inherited from ca.uqac.lif.cep.Processor
static boolean allNull (Object[] v)
 Checks if all objects in the array are null.
static Queue< Object[]> getEmptyQueue ()
 Gets an instance of an empty event queue.
static void startAll (Processor ... procs)
 Starts all processors given as an argument.
static void stopAll (Processor ... procs)
 Stops all processors given as an argument.
static List< ProvenanceNode > getLeaves (ProvenanceNode root)
 Gets the leaves of a provenance tree.
Static Public Attributes inherited from ca.uqac.lif.cep.Processor
static final transient String s_versionString = "0.11.2"
 A string used to identify the program's version.
static final transient int MAX_PULL_RETRIES = 10000000
 Number of times the Pullable#hasNext() method tries to produce an output from the input before giving up.
Static Protected Member Functions inherited from ca.uqac.lif.cep.Processor
static void getLeaves (ProvenanceNode root, List< ProvenanceNode > leaves)
 Accumulates the leaves of a provenance tree in a list.

Constructor & Destructor Documentation

◆ Print() [1/3]

ca.uqac.lif.cep.io.Print.Print ( )

Creates a new printer with an input arity of 1 and sending its output to the standard output.

Definition at line 78 of file Print.java.

◆ Print() [2/3]

ca.uqac.lif.cep.io.Print.Print ( int in_arity,
PrintStream out )

Creates a new print processor.

Parameters
in_arityThe input arity
outThe print stream to use

Definition at line 91 of file Print.java.

◆ Print() [3/3]

ca.uqac.lif.cep.io.Print.Print ( PrintStream out)

Creates a new print processor with input arity 1.

Parameters
outThe print stream to use

Definition at line 104 of file Print.java.

Member Function Documentation

◆ afterEvent()

void ca.uqac.lif.cep.io.Print.afterEvent ( PrintStream ps)
protected

Method that is called after an event is be printed.

Descendants of this call can be used to make special calls to the underlying print stream, for example to change its display colors.

Parameters
psThe print stream

Reimplemented in ca.uqac.lif.cep.io.Print.Println.

Definition at line 234 of file Print.java.

◆ afterSeparator()

void ca.uqac.lif.cep.io.Print.afterSeparator ( PrintStream ps)
protected

Method that is called after a separator is be printed.

Descendants of this call can be used to make special calls to the underlying print stream, for example to change its display colors.

Parameters
psThe print stream

Definition at line 260 of file Print.java.

◆ beforeEvent()

void ca.uqac.lif.cep.io.Print.beforeEvent ( PrintStream ps)
protected

Method that is called before an event is to be printed.

Descendants of this call can be used to make special calls to the underlying print stream, for example to change its display colors.

Parameters
psThe print stream

Definition at line 221 of file Print.java.

◆ beforeSeparator()

void ca.uqac.lif.cep.io.Print.beforeSeparator ( PrintStream ps)
protected

Method that is called before an separator is to be printed.

Descendants of this call can be used to make special calls to the underlying print stream, for example to change its display colors.

Parameters
psThe print stream

Definition at line 247 of file Print.java.

◆ close()

void ca.uqac.lif.cep.io.Print.close ( )

Closes the underlying PrintStream.

Definition at line 337 of file Print.java.

◆ compute()

boolean ca.uqac.lif.cep.io.Print.compute ( Object[] inputs,
Queue< Object[]> outputs )
protected

Computes one or more output events from its input events.

Parameters
inputsAn array of input events; its length corresponds to the processor's input arity
outputsA queue of arrays of objects. The processor should push arrays into this queue for every output front it produces. The size of each array should be equal to the processor's output arity, although this is not enforced.
Returns
true if this processor may output other events in the future, false otherwise

Reimplemented from ca.uqac.lif.cep.SynchronousProcessor.

Definition at line 186 of file Print.java.

◆ copyInto()

void ca.uqac.lif.cep.io.Print.copyInto ( Print print,
boolean with_state )
protected

Copies the member fields of the current processor into that of another Print processor.

Parameters
printThe other print processor
with_statetrue to make a stateful copy, false otherwise

Definition at line 357 of file Print.java.

◆ duplicate()

Print ca.uqac.lif.cep.io.Print.duplicate ( boolean with_state)

Duplicates an object.

Optionally, set the object into the same state as the source object.

Parameters
with_stateSet to true to replicate the object's state, false to create a new copy in the initial state.
Returns
Another object

Reimplemented from ca.uqac.lif.cep.Processor.

Reimplemented in ca.uqac.lif.cep.io.Print.Println.

Definition at line 343 of file Print.java.

◆ getPrintStream()

PrintStream ca.uqac.lif.cep.io.Print.getPrintStream ( )

Gets a reference to the print stream to which the character strings will be sent.

Returns
The print stream

Definition at line 166 of file Print.java.

◆ prettyPrint() [1/3]

void ca.uqac.lif.cep.io.Print.prettyPrint ( Number n)
protected

Prints a number in an eye-pleasing way.

In this case, the printer trims the decimals from a number if it is an integer

Parameters
nThe number

Definition at line 295 of file Print.java.

◆ prettyPrint() [2/3]

void ca.uqac.lif.cep.io.Print.prettyPrint ( Object[] array)
protected

Prints an array in an eye-pleasing way.

In this case, the printer pretty-prints each element of the array.

Parameters
arrayThe array

Definition at line 314 of file Print.java.

◆ prettyPrint() [3/3]

void ca.uqac.lif.cep.io.Print.prettyPrint ( PrintStream ps,
Object o )
protected

Prints an object in an eye-pleasing way.

So far, this method only does something special for numbers.

Parameters
psThe print stream to print into
oThe object to print

Definition at line 272 of file Print.java.

◆ reset()

void ca.uqac.lif.cep.io.Print.reset ( )

Resets the processor.

This has for effect of flushing the contents of all input and output event queues. If the processor has an internal state, this should also reset this state to its "initial" settings (whatever that means in your context).

Reimplemented from ca.uqac.lif.cep.Processor.

Definition at line 110 of file Print.java.

◆ setPrefix()

Print ca.uqac.lif.cep.io.Print.setPrefix ( String prefix)

Sets a prefix to display before each event.

Parameters
prefixThe prefix; can be any string and include ANSI escape sequences
Returns
This print processor

Definition at line 123 of file Print.java.

◆ setPrintStream()

Print ca.uqac.lif.cep.io.Print.setPrintStream ( PrintStream printer)

Sets the print stream to which the character string will be sent.

Parameters
printerThe print stream
Returns
This Print processor

Definition at line 178 of file Print.java.

◆ setSeparator()

Print ca.uqac.lif.cep.io.Print.setSeparator ( String separator)

Sets a separator to display after each event.

This is not the same thing as the separator that can be set with setSeparator()

Parameters
separatorThe separator; can be any string and include ANSI escape sequences
Returns
This print processor

Definition at line 154 of file Print.java.

◆ setSuffix()

Print ca.uqac.lif.cep.io.Print.setSuffix ( String suffix)

Sets a suffix to display before each event.

This is not the same thing as the separator that can be set with setSeparator(). The suffix is appended immediately after each event, while the separator is appended only after the next event arrives.

Parameters
suffixThe suffix; can be any string and include ANSI escape sequences
Returns
This print processor

Definition at line 139 of file Print.java.

◆ stop()

void ca.uqac.lif.cep.io.Print.stop ( )

Stops the processor.

This has no effect, except for processors that use threads; in such a case, calling this method should stop the thread.

Reimplemented from ca.uqac.lif.cep.Processor.

Definition at line 329 of file Print.java.

Member Data Documentation

◆ m_firstOut

boolean ca.uqac.lif.cep.io.Print.m_firstOut
protected

A flag determining if the printed token is the first.

This flag is used to avoid printing a dangling separator token after the last printed token. The separator is printed only if another token comes after it.

Definition at line 71 of file Print.java.

◆ m_out

transient PrintStream ca.uqac.lif.cep.io.Print.m_out
protected

The stream to print to.

Definition at line 49 of file Print.java.

◆ m_prefix

String ca.uqac.lif.cep.io.Print.m_prefix = ""
protected

The prefix to display before each event.

Definition at line 59 of file Print.java.

◆ m_separator

String ca.uqac.lif.cep.io.Print.m_separator = ","
protected

The separator between each event.

Definition at line 54 of file Print.java.

◆ m_suffix

String ca.uqac.lif.cep.io.Print.m_suffix = ""
protected

The suffix to display after each event.

Definition at line 64 of file Print.java.


The documentation for this class was generated from the following file:
  • /home/sylvain/Workspaces/beepbeep/core/src/ca/uqac/lif/cep/io/Print.java