Comments (7)
There is this method:
/**
* Returns all variables or constants that are used i the expression, excluding the standard
* constants like e.g. <code>PI</code> or <code>TRUE</code> and <code>FALSE</code>.
*
* @return All used variables and constants less the standard constants.
* @throws ParseException If there were problems while parsing the expression.
*/
public Set<String> getUsedVariables() throws ParseException;
from evalex.
There is this method:
/** * Returns all variables or constants that are used i the expression, excluding the standard * constants like e.g. <code>PI</code> or <code>TRUE</code> and <code>FALSE</code>. * * @return All used variables and constants less the standard constants. * @throws ParseException If there were problems while parsing the expression. */ public Set<String> getUsedVariables() throws ParseException;
In version 2.x, getUsedVariables
and getDeclaredVariables
are different. Used variables are variables inside the expression string. Declared variables are variables that we input with with
or and
. They may or may not be equal.
from evalex.
https://github.com/ezylang/EvalEx/blob/2.x/src/main/java/com/udojava/evalex/Expression.java
/**
* Exposing declared variables in the expression.
*
* @return All declared variables.
*/
public Set<String> getDeclaredVariables() {
return Collections.unmodifiableSet(variables.keySet());
}
/**
* Returns a list of the variables in the expression.
*
* @return A list of the variable names in this expression.
*/
public List<String> getUsedVariables() {
List<String> result = new ArrayList<String>();
Tokenizer tokenizer = new Tokenizer(expressionString);
while (tokenizer.hasNext()) {
Token nextToken = tokenizer.next();
String token = nextToken.toString();
if (nextToken.type != TokenType.VARIABLE || DEFAULT_CONSTANTS.containsKey(token)) {
continue;
}
result.add(token);
}
return result;
}
from evalex.
There are two possibilities.
One is to write an own data accessor that allows you to also control the declared variables.
Or you could code it like this, checking the data accessor for each used variable:
void checkVariables() throws ParseException {
Expression expression = new Expression("a+B*b-A/PI*(1/2)*pi+e-E+a").with("a", 12);
DataAccessorIfc dataAccessor = expression.getConfiguration().getDataAccessorSupplier().get();
for (String variable : expression.getUsedVariables()) {
if (dataAccessor.getData(variable) == null) {
System.out.println("Variable not declared: " + variable);
}
}
}
from evalex.
Will it not be possible for a straightforward method anymore like in 2.x?
from evalex.
Sure is this possible, but why not a method that directly returns the undeclared variables? e.g. public Set<String> getUndeclaredVariables()
?
from evalex.
Yeah that would work too! Or maybe a method that checks if the expression can be evaluated or not (because some variables needed were not declared)
from evalex.
Related Issues (20)
- OutOfMemoryError: for wrong expression with 2 dots HOT 1
- Support arrays as function parameters HOT 7
- Equality depends on input type in 3.1.0
- problem with placeholder HOT 1
- Add module-info (or at least Automatic-Module-Name) HOT 2
- SQRT function doesn't work HOT 3
- With introduction of null, it's better to allow short circuiting (lazy evaluation) for those boolean operators HOT 4
- Equals/NotEquals operator is now sometimes showing inconsistent behavior HOT 1
- Broken boolean expression evaluation in version 3.1.0
- Allow Java arrays as input parameters
- Restore compatibility with Java 8 HOT 2
- Determine evaluation result type without evaluating HOT 2
- Java exception generated when trying to calculate expressions (it worked before with the original EvalEX library in the previous GitHub) HOT 2
- Can arrayJson filtering be supported? HOT 6
- Add a configurable locale to the configuration
- New Player Guidebook Naming rules HOT 1
- Incorrect behavior of ‘==’ operator in IF() expression for Array typed variable
- Management of the exception IndexOutOfBoundsException for Array variables
- Definition domain of the ACOS function
- does not evaluate if expression operand has a period, hyphen seperater HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evalex.