Provides more intuitive representation for arrays in GREL (#2488)

Added test for same
closes #2040
This commit is contained in:
Ekta Mishra 2020-04-01 14:29:25 +05:30 committed by GitHub
parent d9fa25fa8d
commit 05b6a7b2ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -27,6 +27,7 @@
package com.google.refine.util; package com.google.refine.util;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.Arrays;
public class StringUtils { public class StringUtils {
/** /**
@ -41,6 +42,8 @@ public class StringUtils {
return ParsingUtilities.dateToString((OffsetDateTime) odt); return ParsingUtilities.dateToString((OffsetDateTime) odt);
} else if (o == null) { } else if (o == null) {
return ""; return "";
} else if(o instanceof Object[]){
return Arrays.deepToString((Object[]) o);
} else { } else {
return o.toString(); return o.toString();
} }

View File

@ -0,0 +1,25 @@
package com.google.refine.util;
import com.google.refine.RefineTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.time.OffsetDateTime;
import com.google.refine.util.StringUtils;
public class StringUtilsTests extends RefineTest {
@Test
public void objectToString() {
Object nullObject = null;
Object[] emptyArray = {};
Object[] objArray = {4, "hello", true, 0.01};
Object[][] multiArray = {{"OpenRefine", 12}, {13, 4.6}, {"data", "mining"}};
OffsetDateTime time = OffsetDateTime.parse("2017-01-02T01:02:03Z");
Assert.assertEquals("", StringUtils.toString(nullObject));
Assert.assertEquals("[]", StringUtils.toString(emptyArray));
Assert.assertEquals("[4, hello, true, 0.01]", StringUtils.toString(objArray));
Assert.assertEquals("[[OpenRefine, 12], [13, 4.6], [data, mining]]", StringUtils.toString(multiArray));
Assert.assertEquals("2017-01-02T01:02:03Z", StringUtils.toString(time));
}
}