Replace if statements with Optional#ifPresent

This commit is contained in:
Sebastian Sieber
2023-07-13 13:31:07 +02:00
parent 6c968e1b00
commit d660e79af4
2 changed files with 8 additions and 19 deletions

View File

@@ -21,20 +21,12 @@
package org.mustangproject.ZUGFeRD;
import static org.mustangproject.ZUGFeRD.ZUGFeRDDateFormat.DATE;
import static org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants.CORRECTEDINVOICE;
import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATEGORY_CODES_WITH_EXEMPTION_REASON;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.mustangproject.*;
@@ -287,9 +279,7 @@ public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
copyWithoutRebateInfo.addNote(note);
}
}
if(exportableTransaction.getSubjectNote()!= null) {
copyWithoutRebateInfo.addNote(exportableTransaction.getSubjectNote());
}
Optional.ofNullable(exportableTransaction.getSubjectNote()).ifPresent(copyWithoutRebateInfo::addNote);
return super.buildNotes(copyWithoutRebateInfo);
}
}

View File

@@ -47,7 +47,6 @@ import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.mustangproject.FileAttachment;
import org.mustangproject.IncludedNote;
import org.mustangproject.SubjectCode;
import org.mustangproject.XMLTools;
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
@@ -757,12 +756,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
if (exportableTransaction.rebateAgreementExists()) {
includedNotes.add(IncludedNote.discountBonusNote("Es bestehen Rabatt- und Bonusvereinbarungen."));
}
if (exportableTransaction.getOwnOrganisationFullPlaintextInfo() != null) {
includedNotes.add(IncludedNote.regulatoryNote(exportableTransaction.getOwnOrganisationFullPlaintextInfo()));
}
if (exportableTransaction.getSubjectNote() != null) {
includedNotes.add(IncludedNote.unspecifiedNote(exportableTransaction.getSubjectNote()));
}
Optional.ofNullable(exportableTransaction.getOwnOrganisationFullPlaintextInfo())
.ifPresent(info -> includedNotes.add(IncludedNote.regulatoryNote(info)));
Optional.ofNullable(exportableTransaction.getSubjectNote())
.ifPresent(note -> includedNotes.add(IncludedNote.unspecifiedNote(note)));
return includedNotes.stream().map(IncludedNote::toCiiXml).collect(Collectors.joining(""));
}