From b8f2b1ad2532e1dccff7cf9dabd6e9b26a924918 Mon Sep 17 00:00:00 2001 From: Manuel Bl Date: Sat, 1 Jun 2024 12:40:43 +0200 Subject: [PATCH] Mark unstructured address as deprecated --- .../net/codecrete/qrbill/canvas/PNGCanvas.java | 13 +++++++++---- .../net/codecrete/qrbill/generator/Address.java | 16 ++++++++++++++++ .../qrbill/generator/BillTextFormatter.java | 2 ++ .../codecrete/qrbill/generator/QRCodeText.java | 2 ++ .../qrbill/generator/SwicoS1Decoder.java | 2 +- .../codecrete/qrbill/generator/Validator.java | 5 +++++ .../codecrete/qrbill/generator/AddressTest.java | 10 ++++++++++ .../qrbill/generator/AlternativeSchemeTest.java | 1 + .../qrbill/generator/BillFormatTest.java | 1 + .../qrbill/generator/CreditorValidationTest.java | 1 + .../qrbill/generator/SampleQrCodeText.java | 2 ++ .../generator/SwicoBillInformationTest.java | 1 + .../codecrete/qrbill/testhelper/SampleData.java | 3 +++ 13 files changed, 54 insertions(+), 5 deletions(-) diff --git a/generator/src/main/java/net/codecrete/qrbill/canvas/PNGCanvas.java b/generator/src/main/java/net/codecrete/qrbill/canvas/PNGCanvas.java index 203a582..19ab8fa 100644 --- a/generator/src/main/java/net/codecrete/qrbill/canvas/PNGCanvas.java +++ b/generator/src/main/java/net/codecrete/qrbill/canvas/PNGCanvas.java @@ -175,6 +175,14 @@ private static void addDpiMetadata(IIOMetadata metadata, int dpi) throws IIOInva root.appendChild(physNode); metadata.mergeTree(metadata.getNativeMetadataFormatName(), root); + IIOMetadataNode dimension = createDimensionNode(dpi); + + root = new IIOMetadataNode(PNG_STANDARD_METADATA_FORMAT); + root.appendChild(dimension); + metadata.mergeTree(PNG_STANDARD_METADATA_FORMAT, root); + } + + private static IIOMetadataNode createDimensionNode(int dpi) { // standard metadata format double pixelsPerMM = dpi / 25.4; String pixelsPerMMString = Double.toString(pixelsPerMM); @@ -188,10 +196,7 @@ private static void addDpiMetadata(IIOMetadata metadata, int dpi) throws IIOInva IIOMetadataNode dimension = new IIOMetadataNode("Dimension"); dimension.appendChild(horizontalPixelSize); dimension.appendChild(verticalPixelSize); - - root = new IIOMetadataNode(PNG_STANDARD_METADATA_FORMAT); - root.appendChild(dimension); - metadata.mergeTree(PNG_STANDARD_METADATA_FORMAT, root); + return dimension; } private static void addTextMetadata(IIOMetadata metadata) throws IIOInvalidTreeException { diff --git a/generator/src/main/java/net/codecrete/qrbill/generator/Address.java b/generator/src/main/java/net/codecrete/qrbill/generator/Address.java index 302379f..c6bbe74 100644 --- a/generator/src/main/java/net/codecrete/qrbill/generator/Address.java +++ b/generator/src/main/java/net/codecrete/qrbill/generator/Address.java @@ -144,8 +144,12 @@ public void setName(String name) { * Starting November 25, 2025, banks will no longer accept payments using combined address elements. *

* + * @deprecated Use a structured address instead. Will be removed in release 4. + * * @return address line 1 */ + @Deprecated + @SuppressWarnings({"DeprecatedIsStillUsed", "java:S1133"}) public String getAddressLine1() { return addressLine1; } @@ -164,8 +168,12 @@ public String getAddressLine1() { * Starting November 25, 2025, banks will no longer accept payments using combined address elements. *

* + * @deprecated Use a structured address instead. Will be removed in release 4. + * * @param addressLine1 address line 1 */ + @Deprecated + @SuppressWarnings({"DeprecatedIsStillUsed", "java:S1133"}) public void setAddressLine1(String addressLine1) { this.addressLine1 = addressLine1; changeType(Type.COMBINED_ELEMENTS); @@ -181,8 +189,12 @@ public void setAddressLine1(String addressLine1) { * Starting November 25, 2025, banks will no longer accept payments using combined address elements. *

* + * @deprecated Use a structured address instead. Will be removed in release 4. + * * @return address line 2 */ + @Deprecated + @SuppressWarnings({"DeprecatedIsStillUsed", "java:S1133"}) public String getAddressLine2() { return addressLine2; } @@ -201,8 +213,12 @@ public String getAddressLine2() { * Starting November 25, 2025, banks will no longer accept payments using combined address elements. *

* + * @deprecated Use a structured address instead. Will be removed in release 4. + * * @param addressLine2 address line 2 */ + @Deprecated + @SuppressWarnings({"DeprecatedIsStillUsed", "java:S1133"}) public void setAddressLine2(String addressLine2) { this.addressLine2 = addressLine2; changeType(Type.COMBINED_ELEMENTS); diff --git a/generator/src/main/java/net/codecrete/qrbill/generator/BillTextFormatter.java b/generator/src/main/java/net/codecrete/qrbill/generator/BillTextFormatter.java index 593735d..946295f 100644 --- a/generator/src/main/java/net/codecrete/qrbill/generator/BillTextFormatter.java +++ b/generator/src/main/java/net/codecrete/qrbill/generator/BillTextFormatter.java @@ -162,6 +162,7 @@ private static String formatAmountForDisplay(BigDecimal amount) { return createAmountFormatter().format(amount); } + @SuppressWarnings("deprecation") private static String formatAddressForDisplay(Address address, boolean withCountryCode) { StringBuilder sb = new StringBuilder(); sb.append(address.getName()); @@ -228,6 +229,7 @@ private static boolean isForeignAddress(Address address, BillFormat format) { return address != null && !format.getLocalCountryCode().equals(address.getCountryCode()); } + @SuppressWarnings("deprecation") private Address createReducedAddress(Address address) { // Address without street / house number Address reducedAddress = new Address(); diff --git a/generator/src/main/java/net/codecrete/qrbill/generator/QRCodeText.java b/generator/src/main/java/net/codecrete/qrbill/generator/QRCodeText.java index 8a011ae..51f722e 100644 --- a/generator/src/main/java/net/codecrete/qrbill/generator/QRCodeText.java +++ b/generator/src/main/java/net/codecrete/qrbill/generator/QRCodeText.java @@ -80,6 +80,7 @@ private String createText() { return textBuilder.toString(); } + @SuppressWarnings("deprecation") private void appendPerson(Address address) { if (address != null) { appendDataField(address.getType() == Address.Type.STRUCTURED ? "S" : "K"); // AdrTp @@ -217,6 +218,7 @@ private static void decodeAlternativeSchemes(String[] lines, Bill bill) { * @param isOptional indicates if address is optional * @return decoded address or {@code null} if address is optional and empty */ + @SuppressWarnings("deprecation") private static Address decodeAddress(String[] lines, int startLine, boolean isOptional) { boolean isEmpty = lines[startLine].isEmpty() && lines[startLine + 1].isEmpty() diff --git a/generator/src/main/java/net/codecrete/qrbill/generator/SwicoS1Decoder.java b/generator/src/main/java/net/codecrete/qrbill/generator/SwicoS1Decoder.java index 8f8ec3b..56f9dfa 100644 --- a/generator/src/main/java/net/codecrete/qrbill/generator/SwicoS1Decoder.java +++ b/generator/src/main/java/net/codecrete/qrbill/generator/SwicoS1Decoder.java @@ -97,7 +97,7 @@ private SwicoBillInformation decodeIt(String billInfoText) { } private void decodeElement(SwicoBillInformation billInformation, int tag, String value) { - if (value.length() == 0) + if (value.isEmpty()) return; switch (tag) { diff --git a/generator/src/main/java/net/codecrete/qrbill/generator/Validator.java b/generator/src/main/java/net/codecrete/qrbill/generator/Validator.java index 8f33157..8408a2c 100644 --- a/generator/src/main/java/net/codecrete/qrbill/generator/Validator.java +++ b/generator/src/main/java/net/codecrete/qrbill/generator/Validator.java @@ -276,6 +276,7 @@ private void validateEmptyAddress(String fieldRoot, boolean mandatory) { } } + @SuppressWarnings("deprecation") private void emitErrorsForConflictingType(Address addressOut, String fieldRoot) { if (addressOut.getAddressLine1() != null) validationResult.addMessage(Type.ERROR, fieldRoot + ValidationConstants.SUBFIELD_ADDRESS_LINE_1, ValidationConstants.KEY_ADDRESS_TYPE_CONFLICT); @@ -291,6 +292,7 @@ private void emitErrorsForConflictingType(Address addressOut, String fieldRoot) validationResult.addMessage(Type.ERROR, fieldRoot + ValidationConstants.SUBFIELD_TOWN, ValidationConstants.KEY_ADDRESS_TYPE_CONFLICT); } + @SuppressWarnings("deprecation") private void checkMandatoryAddressFields(Address addressOut, String fieldRoot) { validateMandatory(addressOut.getName(), fieldRoot, ValidationConstants.SUBFIELD_NAME); if (addressOut.getType() == Address.Type.STRUCTURED || addressOut.getType() == Address.Type.UNDETERMINED) { @@ -303,6 +305,7 @@ private void checkMandatoryAddressFields(Address addressOut, String fieldRoot) { validateMandatory(addressOut.getCountryCode(), fieldRoot, ValidationConstants.SUBFIELD_COUNTRY_CODE); } + @SuppressWarnings("deprecation") private void cleanAddressFields(Address addressOut, String fieldRoot) { addressOut.setName(clippedValue(addressOut.getName(), 70, fieldRoot, ValidationConstants.SUBFIELD_NAME)); if (addressOut.getType() == Address.Type.STRUCTURED) { @@ -327,6 +330,7 @@ private boolean validateIBAN(String iban) { return true; } + @SuppressWarnings("deprecation") private Address cleanedPerson(Address addressIn, String fieldRoot) { if (addressIn == null) return null; @@ -383,6 +387,7 @@ private boolean validateLength(String value, int maxLength, String field) { } } + @SuppressWarnings("SameParameterValue") private String clippedValue(String value, int maxLength, String field) { if (value != null && value.length() > maxLength) { validationResult.addMessage(Type.WARNING, field, ValidationConstants.KEY_FIELD_VALUE_CLIPPED, diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/AddressTest.java b/generator/src/test/java/net/codecrete/qrbill/generator/AddressTest.java index c52f0aa..3088123 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/AddressTest.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/AddressTest.java @@ -32,6 +32,7 @@ void setName() { } @Test + @SuppressWarnings("deprecation") void setAddressLine1() { Address address = new Address(); address.setAddressLine1("TYUI"); @@ -40,6 +41,7 @@ void setAddressLine1() { } @Test + @SuppressWarnings("deprecation") void setAddressLine2() { Address address = new Address(); address.setAddressLine2("vbnm"); @@ -87,6 +89,7 @@ void setCountryCode() { } @Test + @SuppressWarnings("deprecation") void conflictTest1() { Address address = new Address(); address.setStreet("XY"); @@ -95,6 +98,7 @@ void conflictTest1() { } @Test + @SuppressWarnings("deprecation") void conflictTest2() { Address address = new Address(); address.setHouseNo("XY"); @@ -103,6 +107,7 @@ void conflictTest2() { } @Test + @SuppressWarnings("deprecation") void conflictTest3() { Address address = new Address(); address.setPostalCode("XY"); @@ -111,6 +116,7 @@ void conflictTest3() { } @Test + @SuppressWarnings("deprecation") void conflictTest4() { Address address = new Address(); address.setTown("XY"); @@ -147,6 +153,7 @@ void hashObjectCombined() { } @Test + @SuppressWarnings("deprecation") void clearTestStructured() { Address address1 = createStructuredAddress(); address1.clear(); @@ -162,6 +169,7 @@ void clearTestStructured() { } @Test + @SuppressWarnings("deprecation") void clearTestCombined() { Address address1 = createCombinedElementAddress(); address1.clear(); @@ -184,6 +192,7 @@ void toStringTest() { } @Test + @SuppressWarnings({"EqualsWithItself", "AssertBetweenInconvertibleTypes"}) void testEqualsTrivial() { Address address = createCombinedElementAddress(); assertEquals(address, address); @@ -213,6 +222,7 @@ private Address createStructuredAddress() { return address; } + @SuppressWarnings("deprecation") private Address createCombinedElementAddress() { Address address = new Address(); address.setName("Cornelia Singer"); diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/AlternativeSchemeTest.java b/generator/src/test/java/net/codecrete/qrbill/generator/AlternativeSchemeTest.java index 019cd3a..4bdd74b 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/AlternativeSchemeTest.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/AlternativeSchemeTest.java @@ -34,6 +34,7 @@ void toStringTest() { assertEquals("AlternativeScheme{name='Paymit', instruction='PM,12341234,1241234'}", text); } + @SuppressWarnings({"AssertBetweenInconvertibleTypes", "EqualsWithItself"}) @Test void testEqualsTrivial() { AlternativeScheme scheme = new AlternativeScheme("Paymit", "PM,12341234,1241234"); diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/BillFormatTest.java b/generator/src/test/java/net/codecrete/qrbill/generator/BillFormatTest.java index 2bc8911..a1fb1bd 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/BillFormatTest.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/BillFormatTest.java @@ -34,6 +34,7 @@ void toStringTest() { assertEquals("BillFormat{outputSize=QR_BILL_ONLY, language=EN, separatorType=DASHED_LINE_WITH_SCISSORS, fontFamily='Helvetica,Arial,\"Liberation Sans\"', graphicsFormat=SVG, resolution=144, marginLeft=5.0, marginRight=5.0, localCountryCode='CH'}", text); } + @SuppressWarnings({"EqualsWithItself", "AssertBetweenInconvertibleTypes"}) @Test void testEqualsTrivial() { BillFormat format = new BillFormat(); diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/CreditorValidationTest.java b/generator/src/test/java/net/codecrete/qrbill/generator/CreditorValidationTest.java index 87a274a..f285057 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/CreditorValidationTest.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/CreditorValidationTest.java @@ -131,6 +131,7 @@ void creditorWithInvalidCountryCode(String countryCode, String messageKey) { } @Test + @SuppressWarnings("deprecation") void creditorWithConflictingAddress() { bill = SampleData.getExample1(); bill.getCreditor().setAddressLine1("Conflict"); diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/SampleQrCodeText.java b/generator/src/test/java/net/codecrete/qrbill/generator/SampleQrCodeText.java index c0dca82..ec803dd 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/SampleQrCodeText.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/SampleQrCodeText.java @@ -223,6 +223,7 @@ static Bill getBillData3() { "EPD" }; + @SuppressWarnings("deprecation") static Bill getBillData4() { Bill bill = new Bill(); bill.getFormat().setLanguage(Language.EN); @@ -281,6 +282,7 @@ static Bill getBillData4() { "EPD" }; + @SuppressWarnings("deprecation") static Bill getBillData5() { Bill bill = new Bill(); bill.getFormat().setLanguage(Language.EN); diff --git a/generator/src/test/java/net/codecrete/qrbill/generator/SwicoBillInformationTest.java b/generator/src/test/java/net/codecrete/qrbill/generator/SwicoBillInformationTest.java index fb02954..7969cf6 100644 --- a/generator/src/test/java/net/codecrete/qrbill/generator/SwicoBillInformationTest.java +++ b/generator/src/test/java/net/codecrete/qrbill/generator/SwicoBillInformationTest.java @@ -211,6 +211,7 @@ void dueDate_isNull() { assertNull(billInformation.getDueDate()); } + @SuppressWarnings({"EqualsWithItself", "AssertBetweenInconvertibleTypes"}) @Test void testEqualsTrivial() { SwicoBillInformation info = new SwicoBillInformation(); diff --git a/generator/src/test/java/net/codecrete/qrbill/testhelper/SampleData.java b/generator/src/test/java/net/codecrete/qrbill/testhelper/SampleData.java index def77e4..04c50a8 100644 --- a/generator/src/test/java/net/codecrete/qrbill/testhelper/SampleData.java +++ b/generator/src/test/java/net/codecrete/qrbill/testhelper/SampleData.java @@ -115,6 +115,7 @@ public static Bill getExample4() { return bill; } + @SuppressWarnings("deprecation") public static Bill getExample5() { Bill bill = new Bill(); bill.getFormat().setLanguage(Language.RM); @@ -139,6 +140,7 @@ public static Bill getExample5() { return bill; } + @SuppressWarnings("deprecation") public static Bill getExample6() { Bill bill = new Bill(); bill.getFormat().setLanguage(Language.EN); @@ -156,6 +158,7 @@ public static Bill getExample6() { return bill; } + @SuppressWarnings("deprecation") public static Bill getExample7() { Bill bill = new Bill(); bill.getFormat().setLanguage(Language.DE);