use of io.atlasmap.v2.ReplaceFirst in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceFirst.
@AtlasFieldActionInfo(name = "ReplaceFirst", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceFirst(Action action, String input) {
if (action == null || !(action instanceof ReplaceFirst)) {
throw new IllegalArgumentException("Action must be a ReplaceFirst action");
}
ReplaceFirst replaceFirst = (ReplaceFirst) action;
String match = replaceFirst.getMatch();
if (match == null || match.length() == 0) {
throw new IllegalArgumentException("ReplaceFirst action must be specified with a non-empty old string");
}
String newString = replaceFirst.getNewString();
return input == null ? null : input.replaceFirst(match, newString == null ? "" : newString);
}
use of io.atlasmap.v2.ReplaceFirst in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceFirstEmptyMatch.
@Test(expected = IllegalArgumentException.class)
public void testReplaceFirstEmptyMatch() {
ReplaceFirst replaceFirst = new ReplaceFirst();
replaceFirst.setMatch("");
StringComplexFieldActions.replaceFirst(replaceFirst, " ");
}
use of io.atlasmap.v2.ReplaceFirst in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceFirstNullMatch.
@Test(expected = IllegalArgumentException.class)
public void testReplaceFirstNullMatch() {
ReplaceFirst replaceFirst = new ReplaceFirst();
StringComplexFieldActions.replaceFirst(replaceFirst, " ");
}
use of io.atlasmap.v2.ReplaceFirst in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceFirst.
@Test
public void testReplaceFirst() {
ReplaceFirst replaceFirst = new ReplaceFirst();
replaceFirst.setMatch(" ");
assertNull(StringComplexFieldActions.replaceFirst(replaceFirst, null));
assertEquals("", StringComplexFieldActions.replaceFirst(replaceFirst, ""));
assertEquals("test", StringComplexFieldActions.replaceFirst(replaceFirst, "test"));
replaceFirst.setMatch("e");
assertEquals("tst", StringComplexFieldActions.replaceFirst(replaceFirst, "test"));
replaceFirst.setMatch("t");
replaceFirst.setNewString("h");
assertEquals("hest", StringComplexFieldActions.replaceFirst(replaceFirst, "test"));
replaceFirst.setMatch("is");
replaceFirst.setNewString("at");
assertEquals("That is a test", StringComplexFieldActions.replaceFirst(replaceFirst, "This is a test"));
}
Aggregations