diff --git a/common/src/main/java/ctbrec/recorder/postprocessing/AbstractPlaceholderAwarePostProcessor.java b/common/src/main/java/ctbrec/recorder/postprocessing/AbstractPlaceholderAwarePostProcessor.java index 31ebd108..238f900f 100644 --- a/common/src/main/java/ctbrec/recorder/postprocessing/AbstractPlaceholderAwarePostProcessor.java +++ b/common/src/main/java/ctbrec/recorder/postprocessing/AbstractPlaceholderAwarePostProcessor.java @@ -1,22 +1,18 @@ package ctbrec.recorder.postprocessing; -import static ctbrec.StringUtil.*; -import static java.util.Optional.*; +import ctbrec.Config; +import ctbrec.Recording; +import ctbrec.StringUtil; +import ctbrec.variableexpansion.ModelVariableExpander; import java.time.Instant; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.function.Function; -import ctbrec.Config; -import ctbrec.Recording; -import ctbrec.variableexpansion.ModelVariableExpander; +import static java.util.Optional.ofNullable; public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPostProcessor { @@ -24,18 +20,14 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost Recording rec = ctx.getRecording(); Config config = ctx.getConfig(); - Map>> placeholderValueSuppliers = new HashMap<>(); ModelVariableExpander modelExpander = new ModelVariableExpander(rec.getModel(), config, ctx.getRecorder()); - placeholderValueSuppliers.putAll(modelExpander.getPlaceholderValueSuppliers()); - + Map>> placeholderValueSuppliers = new HashMap<>(modelExpander.getPlaceholderValueSuppliers()); placeholderValueSuppliers.put("recordingNotes", r -> getSanitizedRecordingNotes(rec)); - placeholderValueSuppliers.put("fileSuffix", r -> getFileSuffix(rec)); placeholderValueSuppliers.put("recordingsDir", r -> Optional.of(config.getSettings().recordingsDir)); placeholderValueSuppliers.put("absolutePath", r -> Optional.of(rec.getPostProcessedFile().getAbsolutePath())); placeholderValueSuppliers.put("absoluteParentPath", r -> Optional.of(rec.getPostProcessedFile().getParentFile().getAbsolutePath())); - placeholderValueSuppliers.put("epochSecond", r -> ofNullable(rec.getStartDate()).map(Instant::getEpochSecond).map(l -> Long.toString(l))); // NOSONAR placeholderValueSuppliers.put("utcDateTime", pattern -> replaceUtcDateTime(rec, pattern)); placeholderValueSuppliers.put("localDateTime", pattern -> replaceLocalDateTime(rec, pattern)); @@ -45,7 +37,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost } private String fillInPlaceHolders(String input, Map>> placeholderValueSuppliers) { - boolean somethingReplaced = false; + boolean somethingReplaced; do { somethingReplaced = false; int end = input.indexOf("}"); @@ -54,7 +46,7 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost if (start >= 0) { String placeholder = input.substring(start, end + 1); String placeholderName = placeholder.substring(2, placeholder.length() - 1); - String defaultValue = null; + String defaultValue; String expression = null; int questionMark = placeholder.indexOf('?'); if (questionMark > 0) { @@ -114,10 +106,6 @@ public abstract class AbstractPlaceholderAwarePostProcessor extends AbstractPost private Optional getSanitizedRecordingNotes(Recording rec) { Optional notes = ofNullable(rec.getNote()); - if (notes.isPresent()) { - return Optional.of(sanitize(notes.get())); - } else { - return Optional.empty(); - } + return notes.map(StringUtil::sanitize); } }