RandomSec/main/src/com/google/refine/expr/functions/booleans/Not.java
David Huynh 1de5e7c00e Renamed package gel to grel.
Replaced gel with grel in other places in the code base while maintaining backward compatibility.
Changed layout in expression preview dialog to accommodate long GREL name.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1442 7d457c2a-affb-35e4-300a-418c747d4874
2010-10-07 05:19:35 +00:00

36 lines
1.1 KiB
Java

package com.google.refine.expr.functions.booleans;
import java.util.Properties;
import org.json.JSONException;
import org.json.JSONWriter;
import com.google.refine.expr.EvalError;
import com.google.refine.grel.ControlFunctionRegistry;
import com.google.refine.grel.Function;
public class Not implements Function {
public Object call(Properties bindings, Object[] args) {
if (args.length == 1) {
return !objectToBoolean(args[0]);
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a boolean");
}
public static boolean objectToBoolean(Object o) {
return o == null ? false : (
(o instanceof Boolean) ? ((Boolean) o).booleanValue() : Boolean.parseBoolean(o.toString()));
}
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("description"); writer.value("Returns the opposite of b");
writer.key("params"); writer.value("boolean b");
writer.key("returns"); writer.value("boolean");
writer.endObject();
}
}