fr.expression4j.factory
Class ExpressionFactory

java.lang.Object
  extended by fr.expression4j.factory.ExpressionFactory

public final class ExpressionFactory
extends java.lang.Object

 Factory used to create 
                - Expression
                - Catalog
                - Parameters
 
 and to get the default Catalog.
 
 Default catalog is catalog who store all functions created by factory.
 
 

Author:
SGINER

Constructor Summary
ExpressionFactory()
           
 
Method Summary
static Catalog createCatalog(java.lang.String catalogName)
          Create an empty catalog.
static Expression createExpression(java.lang.String expression)
          Create an expression.
static Expression createExpression(java.lang.String expression, Catalog catalog)
          Create an expression with the given catalog.
static Expression createExpression(java.lang.String expression, Catalog catalog, ExpressionModel model)
          Create an expression with the given catalog and the given expression model.
static Parameters createParameters()
          Create an empty parameters
static Catalog getCatalog()
          get the default catalog with all expression created by the factory.
static Catalog getCatalog(java.lang.String catalogName)
          get the specified catalog.
static java.util.List getCatalogList()
          get catalog list.
static Expression optimizeExpression(Expression expression)
          Optimize expression Sample: f(x)=2+5-4*x+3*2 => f2(x)=13-4*x
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionFactory

public ExpressionFactory()
Method Detail

createExpression

public static Expression createExpression(java.lang.String expression)
                                   throws ParsingException
Create an expression. Expression must be conform to the BNF define in ExpressionImpl like - f(x)=2*x - g()=2*50.4e-2

Parameters:
expression - String of the expression.
Returns:
the expression.
Throws:
ParsingException - when expression is not valid.

createExpression

public static Expression createExpression(java.lang.String expression,
                                          Catalog catalog)
                                   throws ParsingException
Create an expression with the given catalog. Expression must be conform to the BNF define in ExpressionImpl like - f(x)=2*x - g()=2*50.4e-2

Parameters:
expression - String of the expression.
catalog - catalog to use to create function.
Returns:
the expression.
Throws:
ParsingException - when expression is not valid.

createExpression

public static Expression createExpression(java.lang.String expression,
                                          Catalog catalog,
                                          ExpressionModel model)
                                   throws ParsingException
Create an expression with the given catalog and the given expression model. Expression must be conform to the BNF define in ExpressionImpl like - f(x)=2*x - g()=2*50.4e-2

Parameters:
expression - String of the expression.
catalog - catalog to use to create function.
model - model tu use to parse expression.
Returns:
the expression.
Throws:
ParsingException - when expression is not valid.

createCatalog

public static Catalog createCatalog(java.lang.String catalogName)
Create an empty catalog.

Parameters:
catalogName - name of the catalog. This name is unique. Crate a new catalog with the same name return the same catalog.
Returns:
an empty catalog (with no expression).

createParameters

public static Parameters createParameters()
Create an empty parameters

Returns:
empty parameters

getCatalog

public static Catalog getCatalog()
get the default catalog with all expression created by the factory.

Returns:
default catalog.

getCatalog

public static Catalog getCatalog(java.lang.String catalogName)
get the specified catalog.

Parameters:
catalogName - requested catalog name.
Returns:
the catalog if found, null if not.

getCatalogList

public static java.util.List getCatalogList()
get catalog list.

Returns:
catalog as list of String name.

optimizeExpression

public static Expression optimizeExpression(Expression expression)
Optimize expression Sample: f(x)=2+5-4*x+3*2 => f2(x)=13-4*x

Parameters:
expression - expression to optimize
Returns:
the optimized expression if possible or the given expression otherwise.