See: Description
Interface | Description |
---|---|
FieldI |
Defines the methods which each field should implement - add, sub, mul, div, mod, pow, eq, ne, gt, ge, lt, le, and, or, not.
|
Class | Description |
---|---|
FieldCollection |
Groups a set of fields together.
|
FieldOperatorTable |
An operator table where the standard operators are evaluated using a set of
fields.
|
A type system for Jep allowing use of new datatype like matrices or rational numbers. See the Field Documentation.
New datatypes can be added to the Jep system by implementing the FieldI
interface.
This defines methods such as add(Object l, Object r)
which the field must implement.
Different fields can be mixed together using to produce a complex type system.
In general each method takes one or two Objects as input and returns an Object. The methods
should return null
if do not know how to handle a particular input. In rare circumstances they can also
throw an EvaluationException. A typical implementation for add would be
@Override public Object add(Object l, Object r) throws EvaluationException { if(l instanceof Double && r instanceof Double) { double ld = ((Double) l).doubleValue(); double rd = ((Double) r).doubleValue(); return Double.valueOf(ld+rd); } return null; }
The FieldOperatorTable
is a OperatorTable
which allow one or more fields to be used by Jep for evaluation.
The FieldCollection
can be given multiple field implementations and use each in turn to calculate the results.
If the first field returns non-null then that value will be used, otherwise
the next in the list will be tried.
A typical implementation would be
FieldColection fc = new FieldColection(); fc.addField(new DoubleField()); fc.addField(new StringField()); fc.addField(new BooleanField()); FieldOperatorTable fieldOperatorTable = new FieldOperatorTable(fc); Jep jep = new Jep(fieldOperatorTable);This allows double number, strings and boolean logical operations to be used together.
An implementation for String's would be
// just need to implement additive and comparative operations public class StringField implements FieldI { // If both arguments are string then concatenate the results // otherwise return null @Override public Object add(Object l, Object r) throws EvaluationException { if(l instanceof String && r instanceof String) return ((String) l)+((String)r); return null; } // Test equality of two strings, // returns true is equal, false if not equal or null if not strings @Override public Boolean eq(Object l, Object r) throws EvaluationException { if(l instanceof String && r instanceof String) { String ls = (String) l; String rs = (String) r; boolean res = ls.equals(rs); return res; } return null; } // Other comparison operations need to be implemented public Boolean ne(Object l, Object r) { .... } public Boolean gt(Object l, Object r) { .... } public Boolean ge(Object l, Object r) { .... } public Boolean lt(Object l, Object r) { .... } public Boolean le(Object l, Object r) { .... } // Null results for other operators public Object sub(Object l, Object r) { return null; } public Object neg(Object l) { return null; } public Object mul(Object l, Object r) { return null; } public Object div(Object l, Object r) { return null; } public Object mod(Object l, Object r) { return null; } public Object pow(Object l, Object r) { return null; } public Boolean and(Object l, Object r) { return null; } public Boolean or(Object l, Object r) { return null; } public Boolean not(Object l) { return null; } }
com.singularsys.extensions.field.implementations
com.singularsys.extensions.field.functions
Copyright © 2018 Singular Systems http://www.singularsys.com/jep