Search in sources :

Example 1 with ReplaceAll

use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.

the class StringComplexFieldActions method replaceAll.

@AtlasFieldActionInfo(name = "ReplaceAll", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceAll(Action action, String input) {
    if (action == null || !(action instanceof ReplaceAll)) {
        throw new IllegalArgumentException("Action must be a ReplaceAll action");
    }
    ReplaceAll replaceAll = (ReplaceAll) action;
    String match = replaceAll.getMatch();
    if (match == null || match.length() == 0) {
        throw new IllegalArgumentException("ReplaceAll action must be specified with a non-empty old string");
    }
    String newString = replaceAll.getNewString();
    return input == null ? null : input.replaceAll(match, newString == null ? "" : newString);
}
Also used : SubString(io.atlasmap.v2.SubString) ReplaceAll(io.atlasmap.v2.ReplaceAll) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 2 with ReplaceAll

use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.

the class StringComplexFieldActionsTest method testReplaceAll.

@Test
public void testReplaceAll() {
    ReplaceAll replaceAll = new ReplaceAll();
    replaceAll.setMatch(" ");
    assertNull(StringComplexFieldActions.replaceAll(replaceAll, null));
    assertEquals("", StringComplexFieldActions.replaceAll(replaceAll, ""));
    assertEquals("test", StringComplexFieldActions.replaceAll(replaceAll, "test"));
    replaceAll.setMatch("e");
    assertEquals("tst", StringComplexFieldActions.replaceAll(replaceAll, "test"));
    replaceAll.setMatch("t");
    replaceAll.setNewString("h");
    assertEquals("hesh", StringComplexFieldActions.replaceAll(replaceAll, "test"));
    replaceAll.setMatch("is");
    replaceAll.setNewString("at");
    assertEquals("That at a test", StringComplexFieldActions.replaceAll(replaceAll, "This is a test"));
}
Also used : ReplaceAll(io.atlasmap.v2.ReplaceAll) Test(org.junit.Test)

Example 3 with ReplaceAll

use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.

the class StringComplexFieldActionsTest method testReplaceAllNullOldString.

@Test(expected = IllegalArgumentException.class)
public void testReplaceAllNullOldString() {
    ReplaceAll replaceAll = new ReplaceAll();
    StringComplexFieldActions.replaceAll(replaceAll, " ");
}
Also used : ReplaceAll(io.atlasmap.v2.ReplaceAll) Test(org.junit.Test)

Example 4 with ReplaceAll

use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.

the class StringComplexFieldActionsTest method testReplaceAllEmptyMatch.

@Test(expected = IllegalArgumentException.class)
public void testReplaceAllEmptyMatch() {
    ReplaceAll replaceAll = new ReplaceAll();
    replaceAll.setMatch("");
    StringComplexFieldActions.replaceAll(replaceAll, " ");
}
Also used : ReplaceAll(io.atlasmap.v2.ReplaceAll) Test(org.junit.Test)

Aggregations

ReplaceAll (io.atlasmap.v2.ReplaceAll)4 Test (org.junit.Test)3 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 SubString (io.atlasmap.v2.SubString)1