use of io.atlasmap.v2.Concatenate in project atlasmap by atlasmap.
the class StringComplexFieldActions method concatenate.
@AtlasFieldActionInfo(name = "Concatenate", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.ALL, targetCollectionType = CollectionType.NONE)
public static String concatenate(Action action, Object input) {
if (action == null || !(action instanceof Concatenate)) {
throw new IllegalArgumentException("Action must be a Concatenate action");
}
if (input == null) {
return null;
}
Concatenate concat = (Concatenate) action;
String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
Collection<?> inputs = collection(input);
StringBuilder builder = new StringBuilder();
for (Object entry : inputs) {
if (builder.length() > 0) {
builder.append(delim);
}
if (entry != null) {
builder.append(entry.toString());
}
}
return builder.toString();
}
use of io.atlasmap.v2.Concatenate in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testConcatenate.
@Test
public void testConcatenate() {
Concatenate action = new Concatenate();
assertEquals(null, StringComplexFieldActions.concatenate(action, null));
assertEquals("1true2.0", StringComplexFieldActions.concatenate(action, new Object[] { 1, true, 2.0 }));
assertEquals("1true2.0", StringComplexFieldActions.concatenate(action, Arrays.asList(1, true, 2.0)));
Map<Object, Object> map = new LinkedHashMap<>();
map.put(1, 1);
map.put(true, true);
map.put(2.0, 2.0);
assertEquals("1true2.0", StringComplexFieldActions.concatenate(action, map));
action.setDelimiter("-");
assertEquals(null, StringComplexFieldActions.concatenate(action, null));
assertEquals("1-true-2.0", StringComplexFieldActions.concatenate(action, new Object[] { 1, true, 2.0 }));
assertEquals("1-true-2.0", StringComplexFieldActions.concatenate(action, Arrays.asList(1, true, 2.0)));
assertEquals("1-true-2.0", StringComplexFieldActions.concatenate(action, map));
}
Aggregations