From df450b20f7a4af847b74aee8110cf92df3e0bda9 Mon Sep 17 00:00:00 2001 From: "Jesus M. Castagnetto" Date: Fri, 1 Feb 2013 22:42:01 -0500 Subject: [PATCH] Registering new XOR command --- .../refine/expr/functions/booleans/Xor.java | 19 +++++++++++-------- .../refine/grel/ControlFunctionRegistry.java | 2 ++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/main/src/com/google/refine/expr/functions/booleans/Xor.java b/main/src/com/google/refine/expr/functions/booleans/Xor.java index 27e9ffc4e..84ed87bd3 100644 --- a/main/src/com/google/refine/expr/functions/booleans/Xor.java +++ b/main/src/com/google/refine/expr/functions/booleans/Xor.java @@ -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(); } } diff --git a/main/src/com/google/refine/grel/ControlFunctionRegistry.java b/main/src/com/google/refine/grel/ControlFunctionRegistry.java index 4e615a3a8..6dad3c2dd 100644 --- a/main/src/com/google/refine/grel/ControlFunctionRegistry.java +++ b/main/src/com/google/refine/grel/ControlFunctionRegistry.java @@ -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());