Registering new XOR command
This commit is contained in:
parent
ebec459cfd
commit
df450b20f7
@ -2,7 +2,7 @@
|
|||||||
Implementing a naive XOR operation
|
Implementing a naive XOR operation
|
||||||
Copyright 2013, Jesus M. Castagnetto
|
Copyright 2013, Jesus M. Castagnetto
|
||||||
License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
|
License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.refine.expr.functions.booleans;
|
package com.google.refine.expr.functions.booleans;
|
||||||
|
|
||||||
@ -19,8 +19,8 @@ public class Xor implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length == 2 &&
|
if (args.length == 2 &&
|
||||||
args[0] != null && args[0] instanceof Boolean &&
|
args[0] != null && args[0] instanceof Boolean &&
|
||||||
args[1] != null && args[0] instanceof Boolean) {
|
args[1] != null && args[0] instanceof Boolean) {
|
||||||
boolean o1 = ((Boolean) args[0]).booleanValue();
|
boolean o1 = ((Boolean) args[0]).booleanValue();
|
||||||
boolean o2 = ((Boolean) args[1]).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");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 booleans");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("description"); writer.value("XORs two boolean values");
|
writer.key("description");
|
||||||
writer.key("params"); writer.value("boolean a, boolean b");
|
writer.value("XORs two boolean values");
|
||||||
writer.key("returns"); writer.value("boolean");
|
writer.key("params");
|
||||||
|
writer.value("boolean a, boolean b");
|
||||||
|
writer.key("returns");
|
||||||
|
writer.value("boolean");
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.And;
|
||||||
import com.google.refine.expr.functions.booleans.Not;
|
import com.google.refine.expr.functions.booleans.Not;
|
||||||
import com.google.refine.expr.functions.booleans.Or;
|
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.DatePart;
|
||||||
import com.google.refine.expr.functions.date.Inc;
|
import com.google.refine.expr.functions.date.Inc;
|
||||||
import com.google.refine.expr.functions.date.Now;
|
import com.google.refine.expr.functions.date.Now;
|
||||||
@ -284,6 +285,7 @@ public class ControlFunctionRegistry {
|
|||||||
registerFunction("and", new And());
|
registerFunction("and", new And());
|
||||||
registerFunction("or", new Or());
|
registerFunction("or", new Or());
|
||||||
registerFunction("not", new Not());
|
registerFunction("not", new Not());
|
||||||
|
registerFunction("xor", new Xor());
|
||||||
|
|
||||||
registerFunction("cross", new Cross());
|
registerFunction("cross", new Cross());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user