Provides more intuitive representation for arrays in GREL (#2488)
Added test for same closes #2040
This commit is contained in:
parent
d9fa25fa8d
commit
05b6a7b2ae
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user