carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From man...@apache.org
Subject [carbondata] branch master updated: [CARBONDATA-3889] Cleanup code for carbondata-common module
Date Sun, 19 Jul 2020 11:52:03 GMT
This is an automated email from the ASF dual-hosted git repository.

manhua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git


The following commit(s) were added to refs/heads/master by this push:
     new 6def83f  [CARBONDATA-3889] Cleanup code for carbondata-common module
6def83f is described below

commit 6def83f85bef5890230376b75b02ef7d4d102aa0
Author: QiangCai <qiangcai@qq.com>
AuthorDate: Sat Jul 4 21:55:18 2020 +0800

    [CARBONDATA-3889] Cleanup code for carbondata-common module
    
    Why is this PR needed?
    1.Field can be 'final'
    2.Redundant 'if' statement
    3.Empty method
    4.Redundant 'throws' clause
    5.Anonymous type can be replaced with lambda
    6.Typo
    7.Redundant String operation
    
    What changes were proposed in this PR?
    1.change field to be 'final'
    2.change redundant 'if' statement
    3.remove Empty method
    4.remove redundant 'throws' clause
    5.change anonymous type to lambda
    6.fix typo
    7.remove redundant String operation
    
    Does this PR introduce any user interface change?
    No
    
    Is any new testcase added?
    No
    
    This closes #3825
---
 .../main/java/org/apache/carbondata/common/Maps.java  |  2 +-
 .../carbondata/common/constants/LoggerAction.java     |  2 +-
 .../sql/MalformedCarbonCommandException.java          |  2 +-
 .../apache/carbondata/common/logging/LogService.java  | 13 +++----------
 .../logging/impl/ExtendedRollingFileAppender.java     | 19 +++++--------------
 .../org/apache/carbondata/common/StringsSuite.java    |  2 +-
 .../common/logging/LogServiceFactoryTest_UT.java      | 10 +---------
 .../impl/AuditExtendedRollingFileAppenderTest_UT.java |  7 +------
 .../common/logging/impl/AuditLevelTest_UT.java        |  8 --------
 .../impl/ExtendedRollingFileAppenderTest_UT.java      |  6 +-----
 10 files changed, 15 insertions(+), 56 deletions(-)

diff --git a/common/src/main/java/org/apache/carbondata/common/Maps.java b/common/src/main/java/org/apache/carbondata/common/Maps.java
index 4e76192..2fefbad 100644
--- a/common/src/main/java/org/apache/carbondata/common/Maps.java
+++ b/common/src/main/java/org/apache/carbondata/common/Maps.java
@@ -25,7 +25,7 @@ import org.apache.carbondata.common.annotations.InterfaceAudience;
 public class Maps {
 
   /**
-   * Return value if key is contained in the map, else return defauleValue.
+   * Return value if key is contained in the map, else return defaultValue.
    * This is added to avoid JDK 8 dependency
    */
   public static <K, V> V getOrDefault(Map<K, V> map, K key, V defaultValue) {
diff --git a/common/src/main/java/org/apache/carbondata/common/constants/LoggerAction.java
b/common/src/main/java/org/apache/carbondata/common/constants/LoggerAction.java
index ca2e2e7..38a8143 100644
--- a/common/src/main/java/org/apache/carbondata/common/constants/LoggerAction.java
+++ b/common/src/main/java/org/apache/carbondata/common/constants/LoggerAction.java
@@ -26,7 +26,7 @@ public enum LoggerAction {
   REDIRECT("REDIRECT"), // no null conversion moved to bad record and written to raw csv
   IGNORE("IGNORE"), // no null conversion moved to bad record and not written to raw csv
   FAIL("FAIL");  //data loading will fail if a bad record is found
-  private String name;
+  private final String name;
 
   LoggerAction(String name) {
     this.name = name;
diff --git a/common/src/main/java/org/apache/carbondata/common/exceptions/sql/MalformedCarbonCommandException.java
b/common/src/main/java/org/apache/carbondata/common/exceptions/sql/MalformedCarbonCommandException.java
index 0394d29..6948d42 100644
--- a/common/src/main/java/org/apache/carbondata/common/exceptions/sql/MalformedCarbonCommandException.java
+++ b/common/src/main/java/org/apache/carbondata/common/exceptions/sql/MalformedCarbonCommandException.java
@@ -36,7 +36,7 @@ public class MalformedCarbonCommandException extends Exception {
   /**
    * The Error message.
    */
-  private String msg = "";
+  private final String msg;
 
   /**
    * Constructor
diff --git a/common/src/main/java/org/apache/carbondata/common/logging/LogService.java b/common/src/main/java/org/apache/carbondata/common/logging/LogService.java
index 55dade6..6102e94 100644
--- a/common/src/main/java/org/apache/carbondata/common/logging/LogService.java
+++ b/common/src/main/java/org/apache/carbondata/common/logging/LogService.java
@@ -35,7 +35,7 @@ public class LogService extends Logger {
   private static String hostName;
   private static String username;
 
-  {
+  static {
     try {
       hostName = InetAddress.getLocalHost().getHostName();
     } catch (UnknownHostException e) {
@@ -77,9 +77,9 @@ public class LogService extends Logger {
   }
 
   public void audit(String message) {
-    String threadid = Thread.currentThread().getId() + "";
+    String threadId = Thread.currentThread().getId() + "";
     super.log(AuditLevel.AUDIT,
-        "[" + hostName + "]" + "[" + username + "]" + "[Thread-" + threadid + "]" + message);
+        "[" + hostName + "]" + "[" + username + "]" + "[Thread-" + threadId + "]" + message);
   }
 
   /**
@@ -91,15 +91,8 @@ public class LogService extends Logger {
     super.log(StatisticLevel.STATISTIC, message);
   }
 
-  public boolean isDebugEnabled() {
-    return super.isDebugEnabled();
-  }
-
   public boolean isWarnEnabled() {
     return super.isEnabledFor(org.apache.log4j.Level.WARN);
   }
 
-  public boolean isInfoEnabled() {
-    return super.isInfoEnabled();
-  }
 }
diff --git a/common/src/main/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppender.java
b/common/src/main/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppender.java
index 089865b..484b228 100644
--- a/common/src/main/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppender.java
+++ b/common/src/main/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppender.java
@@ -18,7 +18,6 @@
 package org.apache.carbondata.common.logging.impl;
 
 import java.io.File;
-import java.io.FileFilter;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.text.DateFormat;
@@ -63,16 +62,8 @@ public class ExtendedRollingFileAppender extends RollingFileAppender {
     File file = new File(folderPath);
 
     if (file.exists()) {
-      File[] files = file.listFiles(new FileFilter() {
-
-        public boolean accept(File file) {
-          if (!file.isDirectory() && file.getName().toLowerCase(Locale.US)
-              .startsWith(fileStartName)) {
-            return true;
-          }
-          return false;
-        }
-      });
+      File[] files = file.listFiles(f ->
+          !f.isDirectory() && f.getName().toLowerCase(Locale.US).startsWith(fileStartName));
 
       if (null == files) {
         return;
@@ -85,7 +76,7 @@ public class ExtendedRollingFileAppender extends RollingFileAppender {
       }
 
       // Sort the file based on its name.
-      TreeMap<String, File> sortedMap = new TreeMap<String, File>();
+      TreeMap<String, File> sortedMap = new TreeMap<>();
       for (File file1 : files) {
         sortedMap.put(file1.getName(), file1);
       }
@@ -95,7 +86,7 @@ public class ExtendedRollingFileAppender extends RollingFileAppender {
       sortedMap.remove(sortedMap.firstKey());
 
       Iterator<Entry<String, File>> it = sortedMap.entrySet().iterator();
-      Entry<String, File> temp = null;
+      Entry<String, File> temp;
 
       // After clean up the files should be maxBackupIndex -1 number of
       // files. Because one more backup file
@@ -151,7 +142,7 @@ public class ExtendedRollingFileAppender extends RollingFileAppender {
       String extension = "";
       if (fileName.contains(".")) {
         extension = fileName.substring(fileName.lastIndexOf("."));
-        buffer.append(fileName.substring(0, fileName.lastIndexOf(".")));
+        buffer.append(fileName, 0, fileName.lastIndexOf("."));
       } else {
         buffer.append(fileName);
       }
diff --git a/common/src/test/java/org/apache/carbondata/common/StringsSuite.java b/common/src/test/java/org/apache/carbondata/common/StringsSuite.java
index ccabaf7..67160be 100644
--- a/common/src/test/java/org/apache/carbondata/common/StringsSuite.java
+++ b/common/src/test/java/org/apache/carbondata/common/StringsSuite.java
@@ -36,7 +36,7 @@ public class StringsSuite {
   public void testMkString() {
     String[] strings = new String[]{};
     String output = Strings.mkString(strings, ",");
-    Assert.assertTrue(output.length() == 0);
+    Assert.assertEquals(0, output.length());
 
     strings = new String[]{"abc"};
     output = Strings.mkString(strings, ",");
diff --git a/common/src/test/java/org/apache/carbondata/common/logging/LogServiceFactoryTest_UT.java
b/common/src/test/java/org/apache/carbondata/common/logging/LogServiceFactoryTest_UT.java
index d0e1c0c..f924262 100644
--- a/common/src/test/java/org/apache/carbondata/common/logging/LogServiceFactoryTest_UT.java
+++ b/common/src/test/java/org/apache/carbondata/common/logging/LogServiceFactoryTest_UT.java
@@ -19,21 +19,13 @@ package org.apache.carbondata.common.logging;
 
 import junit.framework.TestCase;
 import org.apache.log4j.Logger;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 public class LogServiceFactoryTest_UT extends TestCase {
 
-  @Before public void setUp() throws Exception {
-  }
-
-  @After public void tearDown() throws Exception {
-  }
-
   @Test public void testGetLogService() {
     Logger logger = LogServiceFactory.getLogService(this.getClass().getName());
-    assertTrue(logger instanceof Logger);
+    assertNotNull(logger);
   }
 
 }
diff --git a/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditExtendedRollingFileAppenderTest_UT.java
b/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditExtendedRollingFileAppenderTest_UT.java
index cfd0f02..2fa9259 100644
--- a/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditExtendedRollingFileAppenderTest_UT.java
+++ b/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditExtendedRollingFileAppenderTest_UT.java
@@ -21,7 +21,6 @@ import org.junit.Assert;
 import mockit.Deencapsulation;
 import org.apache.log4j.Logger;
 import org.apache.log4j.spi.LoggingEvent;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -29,7 +28,7 @@ public class AuditExtendedRollingFileAppenderTest_UT {
 
   private AuditExtendedRollingFileAppender rAppender = null;
 
-  @Before public void setUp() throws Exception {
+  @Before public void setUp() {
     rAppender = new AuditExtendedRollingFileAppender();
     Deencapsulation.setField(rAppender, "fileName", "audit.log");
     Deencapsulation.setField(rAppender, "maxBackupIndex", 1);
@@ -37,10 +36,6 @@ public class AuditExtendedRollingFileAppenderTest_UT {
 
   }
 
-  @After public void tearDown() throws Exception {
-
-  }
-
   @Test public void testRollOver() {
     rAppender.rollOver();
     rAppender.rollOver();
diff --git a/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditLevelTest_UT.java
b/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditLevelTest_UT.java
index 24cca23..45cca40 100644
--- a/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditLevelTest_UT.java
+++ b/common/src/test/java/org/apache/carbondata/common/logging/impl/AuditLevelTest_UT.java
@@ -19,18 +19,10 @@ package org.apache.carbondata.common.logging.impl;
 
 import junit.framework.TestCase;
 import org.apache.log4j.Level;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 
 public class AuditLevelTest_UT extends TestCase {
 
-  @Before public void setUp() throws Exception {
-  }
-
-  @After public void tearDown() throws Exception {
-  }
-
   @Test public void testAuditLevel() {
     assertEquals(AuditLevel.AUDIT.toInt(), 55000);
   }
diff --git a/common/src/test/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppenderTest_UT.java
b/common/src/test/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppenderTest_UT.java
index 1ae348f..769c5a2 100644
--- a/common/src/test/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppenderTest_UT.java
+++ b/common/src/test/java/org/apache/carbondata/common/logging/impl/ExtendedRollingFileAppenderTest_UT.java
@@ -21,7 +21,6 @@ import org.junit.Assert;
 import mockit.Deencapsulation;
 import org.apache.log4j.Logger;
 import org.apache.log4j.spi.LoggingEvent;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -29,16 +28,13 @@ public class ExtendedRollingFileAppenderTest_UT {
 
   private ExtendedRollingFileAppender rAppender = null;
 
-  @Before public void setUp() throws Exception {
+  @Before public void setUp() {
     rAppender = new ExtendedRollingFileAppender();
     Deencapsulation.setField(rAppender, "fileName", "dummy.log");
     Deencapsulation.setField(rAppender, "maxBackupIndex", 1);
     Deencapsulation.setField(rAppender, "maxFileSize", 1000L);
   }
 
-  @After public void tearDown() throws Exception {
-  }
-
   @Test public void testRollOver() {
     rAppender.rollOver();
     rAppender.rollOver();


Mime
View raw message