QScript  2.1.2
Expression and algorithm evaluator
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | List of all members
org.qscript.Solver Class Reference

Inherits Callable< Result >.

Public Member Functions

Result call () throws SyntaxException, EvaluationException
 
boolean isValid ()
 
boolean cancel ()
 
boolean isDone ()
 
boolean isCancelled ()
 
Result get ()
 
Result get_ () throws SyntaxException, EvaluationException
 

Static Public Member Functions

static void shutDown ()
 
static Solver evaluate (String line)
 
static Solver evaluate (String[] lines)
 
static Solver evaluate (List< String > lines)
 
static Solver evaluate (Script script)
 
static Result evaluate (String line)
 
static Result evaluate (List< String > lines)
 
static Result evaluate (String[] lines)
 
static Result evaluate (Script script)
 
static Result evaluate_ (String line) throws SyntaxException, EvaluationException
 
static Result evaluate_ (String[] lines) throws SyntaxException, EvaluationException
 
static Result evaluate_ (List< String > lines) throws SyntaxException, EvaluationException
 

Detailed Description

This class is similar to Solver in that it has static evaluate() methods to evaluate an expression or script, but now done in its own thread. These methods are suitable for very complex expressions and algorithms that may block the main process thread.
Since the script is being evaluated in their own thread the result will not be known until some future time. It is only when the user attempts to retrieve the evaluation result that any errors have to be dealt with.

All the evaluate methods return a Solve$ object. This object can be used to retrieve the evaluation result using either the get() or get_() methods. Calling either of these two methods will block the calling thread until the task has completed, either because the evaluation ended normally, was cancelled or a syntax / evaluation error occurred. The Solve$ object can also be used (in a non-blocking way) to cancel the task, see if task is done or has been cancelled.

If the get() method is used to retrieve the result any errors are simply outputted to the Java console (BASIC mode). If the get_() method is used (EXPERT mode) then the user much catch any SyntaxException or EvaluationException thrown.

the script has completed The methods fall into two categories depending on how exceptions (initialization and runtime errors) are handled -

Author
Peter Lager

This class has static methods to provide a simple API for users to evaluate an expression or script in the main process thread. They should only be used when the expected evaluation time is to be very short. A long evaluation time can make the application unresponsive.

The methods fall into two categories depending on how exceptions (parsing and runtime errors) are handled -

  1. BASIC - Any error created during the parsing or evaluation of the q-script will cause a message on the default console output device. All basic methods return a Result object, but this is only valid if no errors occur.
  2. EXPERT - Parsing of the q-script can throw a SyntaxException error. After a successful parse the script will be evaluated and an EvaluationException error maybe thrown. In this mode the user much catch these exceptions in their code. Expert methods will return a Result object only if the evaluation was successful i.e. no exceptions thrown.
Author
Peter Lager

Member Function Documentation

Result org.qscript.Solver.call ( ) throws SyntaxException, EvaluationException

Call by the

boolean org.qscript.Solver.cancel ( )

/** Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run.

After this method returns, subsequent calls to isDone will always return true. Subsequent calls to isCancelled will always return true if this method returned true.

Returns
false if the task could not be cancelled, typically because it has already completed normally; true otherwise
static Result org.qscript.Solver.evaluate ( String  line)
static

Basic Mode:
Evaluate a single line of q-script.

Parameters
linea single line of q-script
Returns
the result of the evaluation
static Solver org.qscript.Solver.evaluate ( String  line)
static

Basic Mode:
Evaluate a single line of q-script.

Parameters
linea single line of q-script
Returns
the Solver object
static Result org.qscript.Solver.evaluate ( List< String >  lines)
static

Basic Mode:
Evaluate multiple lines of q-script.

Parameters
linesa list of lines of q-script
Returns
the result of the evaluation
static Solver org.qscript.Solver.evaluate ( String[]  lines)
static

Basic Mode:
Evaluate multiple lines of q-script.

Parameters
linesan array of lines of q-script
Returns
the Solver object
static Result org.qscript.Solver.evaluate ( String[]  lines)
static

Basic Mode:
Evaluate multiple lines of q-script.

Parameters
linesan array of lines of q-script
Returns
the result of the evaluation
static Solver org.qscript.Solver.evaluate ( List< String >  lines)
static

Basic Mode:
Evaluate multiple lines of q-script.

Parameters
linesa list of lines of q-script
Returns
the Solver object
static Result org.qscript.Solver.evaluate ( Script  script)
static

Basic Mode:
Evaluate a q-script.

Parameters
scripta q-script
Returns
the result of the evaluation
static Solver org.qscript.Solver.evaluate ( Script  script)
static

Basic Mode:
Evaluate a q-script.

Parameters
scriptthe q-script
Returns
the Solver object
static Result org.qscript.Solver.evaluate_ ( String  line) throws SyntaxException, EvaluationException
static

Expert Mode:
If you use this method then you are responsible to catch any exceptions thrown.

Parameters
linea single line of q-script
Returns
the result of the evaluation
Exceptions
SyntaxException
EvaluationException
static Result org.qscript.Solver.evaluate_ ( String[]  lines) throws SyntaxException, EvaluationException
static

Expert Mode:
If you use this method then you are responsible to catch any exceptions thrown.
Evaluate multiple lines of q-script.

Parameters
linesan array of lines of q-script
Returns
the result of the evaluation
Exceptions
SyntaxException
EvaluationException
static Result org.qscript.Solver.evaluate_ ( List< String >  lines) throws SyntaxException, EvaluationException
static

Expert Mode:
If you use this method then you are responsible to catch any exceptions thrown.
Evaluate multiple lines of q-script.

Parameters
linesa list of lines of q-script
Returns
the result of the evaluation
Exceptions
SyntaxException
EvaluationException
Result org.qscript.Solver.get ( )

Get the result of the evaluation if it is not ready yet then it will block the calling thread until the evaluation is complete.

Returns
the result of the evaluation.
Result org.qscript.Solver.get_ ( ) throws SyntaxException, EvaluationException

Get the result of the evaluation if it is not ready yet then it will block the calling thread until the evaluation is complete.

Returns
the result of the evaluation.
Exceptions
SyntaxException
EvaluationException
boolean org.qscript.Solver.isCancelled ( )

Returns true if this task was cancelled before it completed normally.

boolean org.qscript.Solver.isDone ( )

Returns true if this task has completed (for any reason)

boolean org.qscript.Solver.isValid ( )

Returns true if this is a valid Solver$ object i.e. has a script

static void org.qscript.Solver.shutDown ( )
static

Need to call this to release resources


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