![JAR search and dependency download from the Maven repository](/logo.png)
io.wizzie.normalizer.funcs.impl.StringReplaceMapper Maven / Gradle / Ivy
package io.wizzie.normalizer.funcs.impl;
import io.wizzie.metrics.MetricsManager;
import io.wizzie.normalizer.funcs.MapperFunction;
import org.apache.kafka.streams.KeyValue;
import java.util.Map;
import static com.cookingfox.guava_preconditions.Preconditions.checkNotNull;
public class StringReplaceMapper extends MapperFunction {
String dimension;
String targetString;
String replacementString;
@Override
public void prepare(Map properties, MetricsManager metricsManager) {
dimension = (String) checkNotNull(properties.get("dimension"), "dimension cannot be null");
targetString = (String) checkNotNull(properties.get("target_string"), "target_string cannot be null");
replacementString = (String) checkNotNull(properties.get("replacement_string"), "replacement_string cannot be null");
}
@Override
public KeyValue> process(String key, Map value) {
if(value != null) {
String content = (String) value.get(dimension);
if(content != null) {
value.put(dimension, content.replaceAll(targetString, replacementString));
}
}
return new KeyValue<>(key, value);
}
@Override
public void stop() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy