You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2021/10/08 13:01:04 UTC
[plc4x] branch feature/mspec-ng updated: fix(plc4j/spi): change
string type representation to optional
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
new 58eeb0c fix(plc4j/spi): change string type representation to optional
58eeb0c is described below
commit 58eeb0cfb029a92993da01c3dadf9047115e6412
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Oct 8 15:00:53 2021 +0200
fix(plc4j/spi): change string type representation to optional
---
.../org/apache/plc4x/java/spi/generation/BufferCommons.java | 11 ++++++-----
.../plc4x/java/spi/generation/WriteBufferJsonBased.java | 7 ++++---
.../apache/plc4x/java/spi/generation/WriteBufferXmlBased.java | 7 ++++---
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/BufferCommons.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/BufferCommons.java
index c3fec86..7a0fea8 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/BufferCommons.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/BufferCommons.java
@@ -18,6 +18,7 @@
*/
package org.apache.plc4x.java.spi.generation;
+import java.util.Optional;
import java.util.stream.Stream;
public interface BufferCommons {
@@ -57,20 +58,20 @@ public interface BufferCommons {
return false;
}
- default String extractAdditionalStringRepresentation(WithReaderArgs... readerArgs) {
+ default Optional<String> extractAdditionalStringRepresentation(WithReaderArgs... readerArgs) {
return extractAdditionalStringRepresentation(Stream.of(readerArgs).map(WithReaderWriterArgs.class::cast).toArray(WithReaderWriterArgs[]::new));
}
- default String extractAdditionalStringRepresentation(WithWriterArgs... writerArgs) {
+ default Optional<String> extractAdditionalStringRepresentation(WithWriterArgs... writerArgs) {
return extractAdditionalStringRepresentation(Stream.of(writerArgs).map(WithReaderWriterArgs.class::cast).toArray(WithReaderWriterArgs[]::new));
}
- default String extractAdditionalStringRepresentation(WithReaderWriterArgs... readerWriterArgs) {
+ default Optional<String> extractAdditionalStringRepresentation(WithReaderWriterArgs... readerWriterArgs) {
for (WithReaderWriterArgs arg : readerWriterArgs) {
if (arg instanceof withAdditionalStringRepresentation) {
- return ((withAdditionalStringRepresentation) arg).stringRepresentation();
+ return Optional.of(((withAdditionalStringRepresentation) arg).stringRepresentation());
}
}
- return null;
+ return Optional.empty();
}
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferJsonBased.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferJsonBased.java
index 4db800e..3b9a620 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferJsonBased.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferJsonBased.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
+import java.util.Optional;
public class WriteBufferJsonBased implements WriteBuffer, BufferCommons, AutoCloseable {
@@ -311,9 +312,9 @@ public class WriteBufferJsonBased implements WriteBuffer, BufferCommons, AutoClo
}
generator.writeStringField(String.format(PLC4X_ATTRIBUTE_FORMAT, logicalName, rwDataTypeKey), dataType);
generator.writeNumberField(String.format(PLC4X_ATTRIBUTE_FORMAT, logicalName, rwBitLengthKey), bitLength);
- String stringRepresentation = extractAdditionalStringRepresentation(writerArgs);
- if (stringRepresentation != null) {
- generator.writeStringField(String.format(PLC4X_ATTRIBUTE_FORMAT, logicalName, rwStringRepresentationKey), stringRepresentation);
+ Optional<String> stringRepresentation = extractAdditionalStringRepresentation(writerArgs);
+ if (stringRepresentation.isPresent()) {
+ generator.writeStringField(String.format(PLC4X_ATTRIBUTE_FORMAT, logicalName, rwStringRepresentationKey), stringRepresentation.get());
}
}
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferXmlBased.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferXmlBased.java
index d09858f..b156b89 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferXmlBased.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferXmlBased.java
@@ -35,6 +35,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Deque;
+import java.util.Optional;
public class WriteBufferXmlBased implements WriteBuffer, BufferCommons {
@@ -257,9 +258,9 @@ public class WriteBufferXmlBased implements WriteBuffer, BufferCommons {
xmlEventWriter.add(dataTypeAttribute);
Attribute bitLengthAttribute = xmlEventFactory.createAttribute(rwBitLengthKey, String.valueOf(bitLength));
xmlEventWriter.add(bitLengthAttribute);
- String additionalStringRepresentation = extractAdditionalStringRepresentation(writerArgs);
- if (additionalStringRepresentation != null) {
- Attribute additionalStringRepresentationAttribute = xmlEventFactory.createAttribute(rwStringRepresentationKey, additionalStringRepresentation);
+ Optional<String> additionalStringRepresentation = extractAdditionalStringRepresentation(writerArgs);
+ if (additionalStringRepresentation.isPresent()) {
+ Attribute additionalStringRepresentationAttribute = xmlEventFactory.createAttribute(rwStringRepresentationKey, additionalStringRepresentation.get());
xmlEventWriter.add(additionalStringRepresentationAttribute);
}
if (encoding != null) {