use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testSplitCollapse.
@Test
public void testSplitCollapse() {
Split action = new Split();
action.setCollapseRepeatingDelimiters(true);
action.setDelimiter("\\");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1\\2\\\\3"));
action.setDelimiter("|");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1|2|||3"));
action.setDelimiter(".");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1..2...3"));
action.setDelimiter("$");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1$$$$2$$$$3"));
action.setDelimiter(" ");
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1 2 3"));
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testSplitNoDelimiter.
@Test
public void testSplitNoDelimiter() {
assertThrows(IllegalArgumentException.class, () -> {
Split action = new Split();
StringComplexFieldActions.split(action, "foobar");
});
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class StringComplexFieldActions method split.
/**
* Splits the String with the specified delimiter.
* @param split action model
* @param input source
* @return splitted
*/
@AtlasActionProcessor(sourceType = FieldType.ANY)
public static String[] split(Split split, String input) {
if (split == null || split.getDelimiter() == null) {
throw new IllegalArgumentException("Split must be specified with a delimiter");
}
String quotedDelimiter = Pattern.quote(split.getDelimiter());
boolean collapseRepeatingDelimiter = split.getCollapseRepeatingDelimiters() == null ? false : split.getCollapseRepeatingDelimiters();
if (collapseRepeatingDelimiter) {
quotedDelimiter = "(" + quotedDelimiter + ")+";
}
return input == null ? null : input.toString().split(quotedDelimiter);
}
Aggregations