Registering new XOR command

This commit is contained in:
Jesus M. Castagnetto 2013-02-01 22:42:01 -05:00
parent ebec459cfd
commit df450b20f7
2 changed files with 13 additions and 8 deletions

View File

@ -2,7 +2,7 @@
Implementing a naive XOR operation
Copyright 2013, Jesus M. Castagnetto
License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
*/
*/
package com.google.refine.expr.functions.booleans;
@ -19,8 +19,8 @@ public class Xor implements Function {
@Override
public Object call(Properties bindings, Object[] args) {
if (args.length == 2 &&
args[0] != null && args[0] instanceof Boolean &&
if (args.length == 2 &&
args[0] != null && args[0] instanceof Boolean &&
args[1] != null && args[0] instanceof Boolean) {
boolean o1 = ((Boolean) args[0]).booleanValue();
boolean o2 = ((Boolean) args[1]).booleanValue();
@ -28,15 +28,18 @@ public class Xor implements Function {
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 booleans");
}
@Override
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("description"); writer.value("XORs two boolean values");
writer.key("params"); writer.value("boolean a, boolean b");
writer.key("returns"); writer.value("boolean");
writer.key("description");
writer.value("XORs two boolean values");
writer.key("params");
writer.value("boolean a, boolean b");
writer.key("returns");
writer.value("boolean");
writer.endObject();
}
}

View File

@ -56,6 +56,7 @@ import com.google.refine.expr.functions.arrays.Uniques;
import com.google.refine.expr.functions.booleans.And;
import com.google.refine.expr.functions.booleans.Not;
import com.google.refine.expr.functions.booleans.Or;
import com.google.refine.expr.functions.booleans.Xor;
import com.google.refine.expr.functions.date.DatePart;
import com.google.refine.expr.functions.date.Inc;
import com.google.refine.expr.functions.date.Now;
@ -284,6 +285,7 @@ public class ControlFunctionRegistry {
registerFunction("and", new And());
registerFunction("or", new Or());
registerFunction("not", new Not());
registerFunction("xor", new Xor());
registerFunction("cross", new Cross());