diff --git a/main/src/com/google/refine/expr/ExpressionUtils.java b/main/src/com/google/refine/expr/ExpressionUtils.java index 398eb78a7..2bd2b9c1d 100644 --- a/main/src/com/google/refine/expr/ExpressionUtils.java +++ b/main/src/com/google/refine/expr/ExpressionUtils.java @@ -125,11 +125,9 @@ public class ExpressionUtils { static public boolean sameValue(Object v1, Object v2) { if (v1 == null) { - return (v2 == null) - || (v2 instanceof String && ((String) v2).length() == 0); + return (v2 == null) ; } else if (v2 == null) { - return (v1 == null) - || (v1 instanceof String && ((String) v1).length() == 0); + return (v1 == null); } else { return v1.equals(v2); } diff --git a/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java new file mode 100644 index 000000000..9f371cb12 --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java @@ -0,0 +1,77 @@ +/* + +Copyright 2017, Owen Stephens +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +package com.google.refine.tests.expr.functions; + + +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.refine.expr.ExpressionUtils; +import com.google.refine.tests.RefineTest; + + +public class ExpressionUtilsTests extends RefineTest { + + + @Override + @BeforeTest + public void init() { + logger = LoggerFactory.getLogger(this.getClass()); + } + + + // -----------------tests------------ + + @Test + public void testSameValueTrue() { + Assert.assertTrue(ExpressionUtils.sameValue(null,null)); + Assert.assertTrue(ExpressionUtils.sameValue("","")); + Assert.assertTrue(ExpressionUtils.sameValue("one","one")); + Assert.assertTrue(ExpressionUtils.sameValue(1,1)); + Assert.assertTrue(ExpressionUtils.sameValue(1.0,1.00)); + Assert.assertTrue(ExpressionUtils.sameValue(true,true)); + } + + @Test + public void testSameValueFalse() { + Assert.assertFalse(ExpressionUtils.sameValue("",null)); + Assert.assertFalse(ExpressionUtils.sameValue(null,"")); + Assert.assertFalse(ExpressionUtils.sameValue("one","two")); + Assert.assertFalse(ExpressionUtils.sameValue(1,2)); + Assert.assertFalse(ExpressionUtils.sameValue(1,1.0)); + Assert.assertFalse(ExpressionUtils.sameValue(true,false)); + } +} diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index c2b43aa1a..aff50f5bb 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -614,7 +614,8 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells", + "blank-out": "To null", + "blank-out-empty": "To empty string", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-es.json b/main/webapp/modules/core/langs/translation-es.json index 86cdf73aa..612dc05bf 100644 --- a/main/webapp/modules/core/langs/translation-es.json +++ b/main/webapp/modules/core/langs/translation-es.json @@ -576,7 +576,7 @@ "to-number": "A número", "to-date": "A fecha", "to-text": "A texto", - "blank-out": "Vaciar Celdas", + "blank-out": "Establecer celdas en nulo", "fill-down": "Llenar hacia abajo", "blank-down": "Vaciar hacia abajo", "split-cells": "Dividir celdas multi-valuadas", diff --git a/main/webapp/modules/core/langs/translation-fil.json b/main/webapp/modules/core/langs/translation-fil.json index 8d1804aaf..66b56f3e5 100644 --- a/main/webapp/modules/core/langs/translation-fil.json +++ b/main/webapp/modules/core/langs/translation-fil.json @@ -475,7 +475,7 @@ "re-trans": "Muling ibahin ang hanggang sa", "warning-no-length": "Hindi tinukoy ang haba ng patlang.", "discard-judg": "Itapon ang mga hatol sa pagkakasundo", - "blank-out": "Mga blankong cell", + "blank-out": "Itakda ang mga cell sa null", "best-cand-type-match": "tumutugma sa mga uri ng pinakamahusay na kandidato?", "sort-by-col": "ayusin ayon sa hanay na ito lamang", "enter-col-name": "Magpasok ng bagong pangalan ng haligi", diff --git a/main/webapp/modules/core/langs/translation-fr.json b/main/webapp/modules/core/langs/translation-fr.json index bc5665725..aa2088e61 100644 --- a/main/webapp/modules/core/langs/translation-fr.json +++ b/main/webapp/modules/core/langs/translation-fr.json @@ -476,7 +476,7 @@ "remove-matching": "Supprimer les lignes correspondantes", "warning-no-length": "Aucune longueur de champ n’a été indiquée.", "discard-judg": "Rejeter les avis de réconciliation", - "blank-out": "Vider les cellules", + "blank-out": "Définir les cellules sur null", "best-cand-type-match": "Meilleure correspondance de type des candidats ?", "sort-by-col": "trier selon cette seule colonne", "enter-col-name": "Indiquer le nom de la nouvelle colonne", diff --git a/main/webapp/modules/core/langs/translation-he.json b/main/webapp/modules/core/langs/translation-he.json index 589dbc8b9..4c6674c87 100644 --- a/main/webapp/modules/core/langs/translation-he.json +++ b/main/webapp/modules/core/langs/translation-he.json @@ -578,7 +578,9 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells", + "blank-out": "To null", + "blank-out-empty": "To empty string", + "empty-cells": "Set cells to empty string", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-it.json b/main/webapp/modules/core/langs/translation-it.json index 0db4b8819..66d3dfc65 100644 --- a/main/webapp/modules/core/langs/translation-it.json +++ b/main/webapp/modules/core/langs/translation-it.json @@ -474,7 +474,7 @@ "re-trans": "Ritrasforma fino a", "warning-no-length": "Nessuna lunghezza dei campi specificata.", "discard-judg": "Annulla i match dei candidati", - "blank-out": "Cancella tutte le celle", + "blank-out": "Imposta le celle su null", "best-cand-type-match": "miglior match del tipo del candidato?", "sort-by-col": "ordina per questa colonna", "enter-col-name": "Inserisci il nome della nuova colonna", diff --git a/main/webapp/modules/core/langs/translation-pt_BR.json b/main/webapp/modules/core/langs/translation-pt_BR.json index 63c501534..45b87c1a6 100644 --- a/main/webapp/modules/core/langs/translation-pt_BR.json +++ b/main/webapp/modules/core/langs/translation-pt_BR.json @@ -467,7 +467,7 @@ "uppercase": "Para maiúsculo", "best-type": "Best candidate's types", "discard-judg": "Descartar a análise de reconciliação", - "blank-out": "Limpar células", + "blank-out": "Definir células para nulo", "best-cand-type-match": "best candidate's types match?", "sort-by-col": "ordenar somente esta coluna", "enter-col-name": "Digite um nome para a nova coluna", diff --git a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js index ec0343e67..8298bdc2e 100644 --- a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js +++ b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js @@ -268,6 +268,11 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { id: "core/to-blank", label: $.i18n._('core-views')["blank-out"], click: function() { doTextTransform("null", "keep-original", false, ""); } + }, + { + id: "core/to-empty", + label: $.i18n._('core-views')["blank-out-empty"], + click: function() { doTextTransform("\"\"", "keep-original", false, ""); } } ] },