2

I have been trying to validate a sample string which I read from a file. I want to check if the condition in the given string evaluates to true or false.

String Test = "( ((10>20) & (10>5)) & (7>9) ) | (123>45)";

How can I do that using Java. I have been trying to split the brackets and operators. Is there any easy way to solve this kind of textual expressions?

I have tried JSR.JAR but I'm getting

java.lang.NoClassDefFoundError: Failed resolution of: Lsun/misc/Service; at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:108)at javax.script.ScriptEngineManager.access$000(ScriptEngineManager.java:55)at javax.script.ScriptEngineManager$1.run(ScriptEngineManager.java:98)at java.security.AccessController.doPrivileged(AccessController.java:45)at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:96)at javax.script.ScriptEngineManager.(ScriptEngineManager.java:69)

DimaSan
  • 12,264
  • 11
  • 65
  • 75
Sreyas
  • 744
  • 1
  • 7
  • 25
  • Possible duplicate: http://stackoverflow.com/questions/19383953/is-it-possible-to-evaluate-a-boolean-expression-for-string-comparions – JDC Dec 14 '16 at 09:06
  • I have tried using ScriptEngine But Im getting the above exception. – Sreyas Dec 14 '16 at 09:07
  • Ah, I see, sorry. Maybe you can use a third party library on android like this: https://github.com/ericwlange/AndroidJSCore or this built on top of googles V8 engine: http://eclipsesource.com/blogs/getting-started-with-j2v8/ – JDC Dec 14 '16 at 09:10

1 Answers1

0

It seems that android does not provide the java scripting engine.

Possibly you could use a third party library instead:

JDC
  • 4,247
  • 5
  • 31
  • 74