Skip to content

Commit

Permalink
fix nits
Browse files Browse the repository at this point in the history
Signed-off-by: Kat Shen <[email protected]>
  • Loading branch information
shenkw1 committed Aug 25, 2023
1 parent c895037 commit b4f62f9
Showing 1 changed file with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces
super(pluginMetrics);
this.keyValueProcessorConfig = keyValueProcessorConfig;

if(keyValueProcessorConfig.getFieldDelimiterRegex() != null
if (keyValueProcessorConfig.getFieldDelimiterRegex() != null
&& !keyValueProcessorConfig.getFieldDelimiterRegex().isEmpty()) {
if(keyValueProcessorConfig.getFieldSplitCharacters() != null
if (keyValueProcessorConfig.getFieldSplitCharacters() != null
&& !keyValueProcessorConfig.getFieldSplitCharacters().isEmpty()) {
throw new IllegalArgumentException("field_delimiter_regex and field_split_characters cannot both be defined.");
} else if(!validateRegex(keyValueProcessorConfig.getFieldDelimiterRegex())) {
} else if (!validateRegex(keyValueProcessorConfig.getFieldDelimiterRegex())) {
throw new PatternSyntaxException("field_delimiter_regex is not a valid regex string", keyValueProcessorConfig.getFieldDelimiterRegex(), -1);
}

Expand All @@ -92,16 +92,15 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

fieldDelimiterPattern = Pattern.compile(regex);

if (keyValueProcessorConfig.getRecursive()) {
if (fieldDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set field split characters cannot contain brackets while you are trying to recurse.");
}
if (keyValueProcessorConfig.getRecursive()
&& fieldDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set field split characters cannot contain brackets while you are trying to recurse.");
}
}

if(keyValueProcessorConfig.getKeyValueDelimiterRegex() != null
if (keyValueProcessorConfig.getKeyValueDelimiterRegex() != null
&& !keyValueProcessorConfig.getKeyValueDelimiterRegex().isEmpty()) {
if(keyValueProcessorConfig.getValueSplitCharacters() != null
if (keyValueProcessorConfig.getValueSplitCharacters() != null
&& !keyValueProcessorConfig.getValueSplitCharacters().isEmpty()) {
throw new IllegalArgumentException("key_value_delimiter_regex and value_split_characters cannot both be defined.");
} else if (!validateRegex(keyValueProcessorConfig.getKeyValueDelimiterRegex())) {
Expand All @@ -110,10 +109,9 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

keyValueDelimiterPattern = Pattern.compile(keyValueProcessorConfig.getKeyValueDelimiterRegex());

if (keyValueProcessorConfig.getRecursive()) {
if (keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set key value delimiter regex cannot contain brackets while you are trying to recurse.");
}
if (keyValueProcessorConfig.getRecursive()
&& keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set key value delimiter regex cannot contain brackets while you are trying to recurse.");
}
} else {
String regex;
Expand All @@ -130,10 +128,9 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces

keyValueDelimiterPattern = Pattern.compile(regex);

if (keyValueProcessorConfig.getRecursive()) {
if (keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set value split characters cannot contain brackets while you are trying to recurse.");
}
if (keyValueProcessorConfig.getRecursive()
&& keyValueDelimiterPattern.matcher(delimiterBracketCheck).matches()) {
throw new IllegalArgumentException("While recursive is true, the set value split characters cannot contain brackets while you are trying to recurse.");
}
}

Expand Down Expand Up @@ -188,7 +185,7 @@ private String buildRegexFromCharacters(String s) {
char[] splitters = s.toCharArray();
StringBuilder regexedFieldSplitCharacters = new StringBuilder();
for(char c : splitters) {
if(Objects.equals(c, '\\')) {
if (Objects.equals(c, '\\')) {
regexedFieldSplitCharacters.append(c);
} else {
regexedFieldSplitCharacters.append(c).append('|');
Expand All @@ -202,7 +199,7 @@ private String buildRegexFromCharacters(String s) {

private boolean validateRegex(final String pattern)
{
if(pattern != null && !Objects.equals(pattern, "")) {
if (pattern != null && !Objects.equals(pattern, "")) {
try {
Pattern.compile(pattern);
} catch (PatternSyntaxException e) {
Expand Down Expand Up @@ -257,7 +254,7 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
return records;
}

private ObjectNode recurse(String input, ObjectMapper mapper) {
private ObjectNode recurse(final String input, final ObjectMapper mapper) {
Stack<Character> bracketStack = new Stack<Character>();
Map<Character, Character> bracketMap = initBracketMap();
int pairStart = 0;
Expand Down Expand Up @@ -400,12 +397,12 @@ private Map<String, Object> executeConfigs(Map<String, Object> map) {
continue;
}

if(keyValueProcessorConfig.getDeleteKeyRegex() != null && !Objects.equals(keyValueProcessorConfig.getDeleteKeyRegex(), "")) {
if (keyValueProcessorConfig.getDeleteKeyRegex() != null && !Objects.equals(keyValueProcessorConfig.getDeleteKeyRegex(), "")) {
key = key.replaceAll(keyValueProcessorConfig.getDeleteKeyRegex(), "");
}
key = keyValueProcessorConfig.getPrefix() + key;

if(value != null
if (value != null
&& value instanceof String
&& keyValueProcessorConfig.getDeleteValueRegex() != null
&& !Objects.equals(keyValueProcessorConfig.getDeleteValueRegex(), "")) {
Expand Down Expand Up @@ -470,7 +467,7 @@ private void addKeyValueToMap(final Map<String, Object> parsedMap, final String
}
}

if(!parsedMap.containsKey(key)) {
if (!parsedMap.containsKey(key)) {
parsedMap.put(key, processedValue);
return;
}
Expand Down

0 comments on commit b4f62f9

Please sign in to comment.