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 2019/12/18 22:45:15 UTC

[plc4x] branch next-gen-core updated: use new unwrap convenient method

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch next-gen-core
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/next-gen-core by this push:
     new 62ca452  use new unwrap convenient method
62ca452 is described below

commit 62ca4527837006ae4e312c9ba05f5c954323ebf6
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Dec 18 23:44:52 2019 +0100

    use new unwrap convenient method
---
 .../s7/readwrite/protocol/Plc4xS7Protocol.java     | 74 +++-------------------
 1 file changed, 10 insertions(+), 64 deletions(-)

diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
index b3ca35c..31211a9 100644
--- a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
@@ -28,46 +28,8 @@ import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.apache.plc4x.java.api.messages.PlcResponse;
 import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
-import org.apache.plc4x.java.s7.readwrite.COTPPacket;
-import org.apache.plc4x.java.s7.readwrite.COTPPacketConnectionRequest;
-import org.apache.plc4x.java.s7.readwrite.COTPPacketConnectionResponse;
-import org.apache.plc4x.java.s7.readwrite.COTPPacketData;
-import org.apache.plc4x.java.s7.readwrite.COTPParameter;
-import org.apache.plc4x.java.s7.readwrite.COTPParameterCalledTsap;
-import org.apache.plc4x.java.s7.readwrite.COTPParameterCallingTsap;
-import org.apache.plc4x.java.s7.readwrite.COTPParameterTpduSize;
-import org.apache.plc4x.java.s7.readwrite.S7Address;
-import org.apache.plc4x.java.s7.readwrite.S7AddressAny;
-import org.apache.plc4x.java.s7.readwrite.S7Message;
-import org.apache.plc4x.java.s7.readwrite.S7MessageRequest;
-import org.apache.plc4x.java.s7.readwrite.S7MessageResponse;
-import org.apache.plc4x.java.s7.readwrite.S7MessageUserData;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterReadVarRequest;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterReadVarResponse;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterSetupCommunication;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterUserData;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterUserDataItem;
-import org.apache.plc4x.java.s7.readwrite.S7ParameterUserDataItemCPUFunctions;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadReadVarRequest;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadReadVarResponse;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadSetupCommunication;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadUserData;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItem;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCpuFunctionReadSzlRequest;
-import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCpuFunctionReadSzlResponse;
-import org.apache.plc4x.java.s7.readwrite.S7VarPayloadDataItem;
-import org.apache.plc4x.java.s7.readwrite.S7VarRequestParameterItem;
-import org.apache.plc4x.java.s7.readwrite.S7VarRequestParameterItemAddress;
-import org.apache.plc4x.java.s7.readwrite.SzlDataTreeItem;
-import org.apache.plc4x.java.s7.readwrite.SzlId;
-import org.apache.plc4x.java.s7.readwrite.TPKTPacket;
-import org.apache.plc4x.java.s7.readwrite.types.COTPProtocolClass;
-import org.apache.plc4x.java.s7.readwrite.types.COTPTpduSize;
-import org.apache.plc4x.java.s7.readwrite.types.DataTransportErrorCode;
-import org.apache.plc4x.java.s7.readwrite.types.DataTransportSize;
-import org.apache.plc4x.java.s7.readwrite.types.S7ControllerType;
-import org.apache.plc4x.java.s7.readwrite.types.SzlModuleTypeClass;
-import org.apache.plc4x.java.s7.readwrite.types.SzlSublist;
+import org.apache.plc4x.java.s7.readwrite.*;
+import org.apache.plc4x.java.s7.readwrite.types.*;
 import org.apache.plc4x.java.s7.readwrite.utils.S7Field;
 import org.apache.plc4x.java.spi.ConversationContext;
 import org.apache.plc4x.java.spi.Plc4xProtocolBase;
@@ -75,19 +37,7 @@ import org.apache.plc4x.java.spi.messages.DefaultPlcReadRequest;
 import org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse;
 import org.apache.plc4x.java.spi.messages.InternalPlcReadRequest;
 import org.apache.plc4x.java.spi.messages.PlcRequestContainer;
-import org.apache.plc4x.java.spi.messages.items.BaseDefaultFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultBigIntegerFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultBooleanFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultByteFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultDoubleFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultFloatFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultIntegerFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultLocalDateFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultLocalDateTimeFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultLocalTimeFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultLongFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultShortFieldItem;
-import org.apache.plc4x.java.spi.messages.items.DefaultStringFieldItem;
+import org.apache.plc4x.java.spi.messages.items.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -99,11 +49,7 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -153,12 +99,12 @@ public class Plc4xS7Protocol extends Plc4xProtocolBase<TPKTPacket> {
                     .expectResponse(TPKTPacket.class, Duration.ofMillis(100))
                     .onTimeout(e -> {
                     })
-                    .check(p -> p.getPayload() instanceof COTPPacketData)
-                    .unwrap(p -> ((COTPPacketData) p.getPayload()))
-                    .check(p -> p.getPayload() instanceof S7MessageResponse)
-                    .unwrap(p -> ((S7MessageResponse) p.getPayload()))
-                    .check(p -> p.getParameter() instanceof S7ParameterSetupCommunication)
-                    .unwrap(p -> ((S7ParameterSetupCommunication) p.getParameter()))
+                    .unwrap(TPKTPacket::getPayload)
+                    .only(COTPPacketData.class)
+                    .unwrap(COTPPacket::getPayload)
+                    .only(S7MessageResponse.class)
+                    .unwrap(S7Message::getParameter)
+                    .only(S7ParameterSetupCommunication.class)
                     .handle(setupCommunication -> {
                         // Save some data from the response.
                         maxAmqCaller = setupCommunication.getMaxAmqCaller();