All blog posts, code samples and downloads licensed under Apache License 2.0.
Close

Handling a "boolean" value from session.evaluate (Java)

Oliver Busse on 08/27/2014 11:29:51 PM CEDT, filed under Java 

Today I faced a strange behavior evaluating a @Formula from a session object. I created the following code and got stuck when I wasn't able to cast the result as a boolean value but as a Double!

public static boolean eval(String formula, Document doc) {
		boolean result = false;

		try {
			Double b = (Double) ExtLibUtil.getCurrentSession().evaluate(formula, doc).elementAt(0);
			result = b == 1 ? true : false;
		} catch (Exception e) {

		}
		return result;
	}

This helper method comes in handy when you are trying to evaluate a @Formula that normally results in a boolean value (@True or @False).


Tagged with java formula