kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject [kafka] branch trunk updated: KAFKA-6926: Simplified some logic to eliminate some suppressions of NPath complexity checks (#5051)
Date Thu, 13 Sep 2018 04:21:52 GMT
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new f028249   KAFKA-6926: Simplified some logic to eliminate some suppressions of NPath
complexity checks (#5051)
f028249 is described below

commit f0282498e7a312a977acb127557520def338d45c
Author: Randall Hauch <rhauch@gmail.com>
AuthorDate: Wed Sep 12 23:21:46 2018 -0500

     KAFKA-6926: Simplified some logic to eliminate some suppressions of NPath complexity
checks (#5051)
    
    Modified several classes' `equals` methods and simplified a complex method to
    reduce the NPath complexity so they could be removed from the checkstyle
    suppressions that were required with the recent move to Java 8 and upgrade
    of Checkstyle: https://github.com/apache/kafka/pull/5046.
    
    Reviewers: Robert Yokota <rayokota@gmail.com>, Arjun Satish <arjun@confluent.io>,
Ismael Juma <ismael@juma.me.uk>
---
 checkstyle/suppressions.xml                        |  2 +-
 .../kafka/connect/connector/ConnectRecord.java     | 26 +++++++---------------
 .../apache/kafka/connect/data/ConnectSchema.java   | 15 ++++++++-----
 .../kafka/connect/runtime/AbstractStatus.java      | 13 ++++++-----
 4 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml
index 2fa499c..5046c76 100644
--- a/checkstyle/suppressions.xml
+++ b/checkstyle/suppressions.xml
@@ -114,7 +114,7 @@
               files="Values.java"/>
 
     <suppress checks="NPathComplexity"
-              files="(AbstractStatus|ConnectHeaders|ConnectRecord|ConnectSchema|DistributedHerder|FileStreamSourceTask|JsonConverter|KafkaConfigBackingStore).java"/>
+              files="(DistributedHerder|JsonConverter|KafkaConfigBackingStore|FileStreamSourceTask).java"/>
 
     <suppress checks="MethodLength"
               files="Values.java"/>
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/connector/ConnectRecord.java
b/connect/api/src/main/java/org/apache/kafka/connect/connector/ConnectRecord.java
index 2ad8a04..2c5f514 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/connector/ConnectRecord.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/connector/ConnectRecord.java
@@ -155,24 +155,14 @@ public abstract class ConnectRecord<R extends ConnectRecord<R>>
{
 
         ConnectRecord that = (ConnectRecord) o;
 
-        if (kafkaPartition != null ? !kafkaPartition.equals(that.kafkaPartition) : that.kafkaPartition
!= null)
-            return false;
-        if (topic != null ? !topic.equals(that.topic) : that.topic != null)
-            return false;
-        if (keySchema != null ? !keySchema.equals(that.keySchema) : that.keySchema != null)
-            return false;
-        if (key != null ? !key.equals(that.key) : that.key != null)
-            return false;
-        if (valueSchema != null ? !valueSchema.equals(that.valueSchema) : that.valueSchema
!= null)
-            return false;
-        if (value != null ? !value.equals(that.value) : that.value != null)
-            return false;
-        if (timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null)
-            return false;
-        if (!Objects.equals(headers, that.headers))
-            return false;
-
-        return true;
+        return Objects.equals(kafkaPartition, that.kafkaPartition)
+               && Objects.equals(topic, that.topic)
+               && Objects.equals(keySchema, that.keySchema)
+               && Objects.equals(key, that.key)
+               && Objects.equals(valueSchema, that.valueSchema)
+               && Objects.equals(value, that.value)
+               && Objects.equals(timestamp, that.timestamp)
+               && Objects.equals(headers, that.headers);
     }
 
     @Override
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
index f1a05bb..66630d1 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
@@ -218,14 +218,10 @@ public class ConnectSchema implements Schema {
             if (!schema.isOptional())
                 throw new DataException("Invalid value: null used for required field: \""
+ name
                         + "\", schema type: " + schema.type());
-            else
-                return;
+            return;
         }
 
-        List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name());
-
-        if (expectedClasses == null)
-                expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type());
+        List<Class> expectedClasses = expectedClassesFor(schema);
 
         if (expectedClasses == null)
             throw new DataException("Invalid Java object for schema type " + schema.type()
@@ -266,6 +262,13 @@ public class ConnectSchema implements Schema {
         }
     }
 
+    private static List<Class> expectedClassesFor(Schema schema) {
+        List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name());
+        if (expectedClasses == null)
+            expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type());
+        return expectedClasses;
+    }
+
     /**
      * Validate that the value can be used for this schema, i.e. that its type matches the
schema type and optional
      * requirements. Throws a DataException if the value is invalid.
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractStatus.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractStatus.java
index 00a050a..dd1b94a 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractStatus.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractStatus.java
@@ -16,6 +16,8 @@
  */
 package org.apache.kafka.connect.runtime;
 
+import java.util.Objects;
+
 public abstract class AbstractStatus<T> {
 
     public enum State {
@@ -81,12 +83,11 @@ public abstract class AbstractStatus<T> {
 
         AbstractStatus<?> that = (AbstractStatus<?>) o;
 
-        if (generation != that.generation) return false;
-        if (id != null ? !id.equals(that.id) : that.id != null) return false;
-        if (state != that.state) return false;
-        if (trace != null ? !trace.equals(that.trace) : that.trace != null) return false;
-        return workerId != null ? workerId.equals(that.workerId) : that.workerId == null;
-
+        return generation == that.generation
+                && Objects.equals(id, that.id)
+                && state == that.state
+                && Objects.equals(trace, that.trace)
+                && Objects.equals(workerId, that.workerId);
     }
 
     @Override


Mime
View raw message