asfgit closed pull request #6: cleanup sonar edgent complaints
URL: https://github.com/apache/incubator-plc4x/pull/6
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
index eedfc794..bc4eaefe 100644
--- 
a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
+++ 
b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
@@ -108,28 +108,38 @@ public Address parseAddress(String addressString) throws 
PlcException {
 
     <T> Supplier<T> newSupplier(Class<T> datatype, String addressStr) {
         PlcConnectionAdapter.checkDatatype(datatype);
-        return new Supplier<T>() {
-            private static final long serialVersionUID = 1L;
+        // satisfy sonar's "Reduce number of anonymous class lines" code smell
+        return new MySupplier<T>(datatype, addressStr);
+    }
+    
+    private class MySupplier<T> implements Supplier<T> {
+        private static final long serialVersionUID = 1L;
+        private Class<T> datatype;
+        private String addressStr;
+      
+        MySupplier(Class<T> datatype, String addressStr) {
+            this.datatype = datatype;
+            this.addressStr = addressStr;
+        }
 
-            @Override
-            public T get() {
-                PlcConnection connection = null;
-                Address address = null;
-                try {
-                    connection = getConnection();
-                    address = connection.parseAddress(addressStr);
-                    PlcReader reader = connection.getReader()
-                        .orElseThrow(() -> new NullPointerException("No reader 
available"));
-                    TypeSafePlcReadRequest<T> readRequest = 
PlcConnectionAdapter.newPlcReadRequest(datatype, address);
-                    return reader.read(readRequest).get().getResponseItem()
-                        .orElseThrow(() -> new IllegalStateException("No 
response available"))
-                        .getValues().get(0);
-                } catch (Exception e) {
-                    logger.error("reading from plc device {} {} failed", 
connection, address, e);
-                    return null;
-                }
+        @Override
+        public T get() {
+            PlcConnection connection = null;
+            Address address = null;
+            try {
+                connection = getConnection();
+                address = connection.parseAddress(addressStr);
+                PlcReader reader = connection.getReader()
+                  .orElseThrow(() -> new NullPointerException("No reader 
available"));
+                TypeSafePlcReadRequest<T> readRequest = 
PlcConnectionAdapter.newPlcReadRequest(datatype, address);
+                return reader.read(readRequest).get().getResponseItem()
+                  .orElseThrow(() -> new IllegalStateException("No response 
available"))
+                  .getValues().get(0);
+            } catch (Exception e) {
+                logger.error("reading from plc device {} {} failed", 
connection, address, e);
+                return null;
             }
-        };
+        }
     }
 
     Supplier<PlcReadResponse> newSupplier(PlcReadRequest readRequest) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to