There is a new version of BRules, a collection of Talend Routines, available on the Talend Exchange. Version 1.2 includes new routines pad(), pad(size), and trimLeadingZeros().
pad()
pad() and pad(size) will add left padding to a string. pad() without a size argument will pad to 10 characters. Here are the test cases these routines support.
@Test
public void pad() {
String[] a = {
null,
"",
"a",
"abc",
"12345678901"
};
assertEquals(" ", BRules.pad(a[0]));
assertEquals(" ", BRules.pad(a[1]));
assertEquals(" a", BRules.pad(a[2]));
assertEquals(" abc", BRules.pad(a[3]));
assertEquals("12345678901", BRules.pad(a[4]));
}
@Test
public void padToSize() {
String[] a = {
null,
"",
"a",
"abc",
"12345678901"
};
assertEquals(" ", BRules.pad(a[0], 7));
assertEquals(" ", BRules.pad(a[1], 7));
assertEquals(" a", BRules.pad(a[2], 7));
assertEquals(" abc", BRules.pad(a[3], 7));
assertEquals("12345678901", BRules.pad(a[4], 7));
}
trimLeadingZeros()
trimLeadingZeros() removes the left leading zeros on a numeric string. The function accepts and returns java.lang.String data.
Here is the test case that trimLeadingZeros() supports.
@Test
public void trimLeadingZeros() {
String[] a = {
null,
"",
"00101",
"0",
"999",
"abc"
};
assertEquals("", BRules.trimLeadingZeros(a[0]));
assertEquals("", BRules.trimLeadingZeros(a[1]));
assertEquals("101", BRules.trimLeadingZeros(a[2]));
assertEquals("0", BRules.trimLeadingZeros(a[3]));
assertEquals("999", BRules.trimLeadingZeros(a[4]));
assertEquals("abc", BRules.trimLeadingZeros(a[5]));
}
No comments:
Post a Comment