Skip to content

Commit

Permalink
Refactor: move big case block into method
Browse files Browse the repository at this point in the history
  • Loading branch information
henning-gerhardt committed Nov 30, 2023
1 parent d24ce9b commit 34af646
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,7 @@ private String determineReplacementForMetadata(Matcher variableFinder) {

switch (metadataLevel) {
case ALL:
List<LogicalDivision> allChildren = workpiece.getLogicalStructure().getChildren();
String allFirstchildValue = null;
if (!allChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5));
if (Objects.isNull(allFirstchildValue)) {
allFirstchildValue = determineReplacementForTopstruct(variableFinder, dollarSignIfToKeep);
}
if (Objects.isNull(allFirstchildValue) || StringUtils.isEmpty(allFirstchildValue)) {
List<LogicalDivision> firstChildChildren = allChildren.get(0).getChildren();
if (!firstChildChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(firstChildChildren.get(0), variableFinder.group(5));
}
}
}
String allFirstchildValue = determinateReplacementForAll(variableFinder, dollarSignIfToKeep);

if (Objects.nonNull(allFirstchildValue)) {
return allFirstchildValue;
Expand All @@ -423,6 +410,24 @@ private String determineReplacementForMetadata(Matcher variableFinder) {
}
}

private String determinateReplacementForAll(Matcher variableFinder, String dollarSignIfToKeep) {
List<LogicalDivision> allChildren = workpiece.getLogicalStructure().getChildren();
String allFirstchildValue = null;
if (!allChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(allChildren.get(0), variableFinder.group(5));
if (Objects.isNull(allFirstchildValue)) {
allFirstchildValue = determineReplacementForTopstruct(variableFinder, dollarSignIfToKeep);
}
if (StringUtils.isEmpty(allFirstchildValue)) {
List<LogicalDivision> firstChildChildren = allChildren.get(0).getChildren();
if (!firstChildChildren.isEmpty()) {
allFirstchildValue = MetadataEditor.getMetadataValue(firstChildChildren.get(0), variableFinder.group(5));
}
}
}
return allFirstchildValue;
}

private String determineReplacementForTopstruct(Matcher variableFinder, String failureResult) {
String value = MetadataEditor.getMetadataValue(workpiece.getLogicalStructure(), variableFinder.group(5));
if (Objects.isNull(value)) {
Expand Down

0 comments on commit 34af646

Please sign in to comment.