asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: remove dead code and curly braces in switches
Date Fri, 02 Dec 2016 17:04:39 GMT
Till Westmann has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1370

Change subject: remove dead code and curly braces in switches
......................................................................

remove dead code and curly braces in switches

Change-Id: I9b23c3e8acd38e3a3ffce5da797f57c064b667c4
---
M asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
M asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
M asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
3 files changed, 50 insertions(+), 116 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/70/1370/1

diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
index 4953ac8..9fc72be 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
@@ -45,31 +45,15 @@
                 if (line == null) {
                     break;
                 }
-                if (line.length() == 0) {
-                    continue;
-                } else {
+                if (line.length() != 0) {
                     list.add(line);
                 }
             }
             result.close();
-        } catch (FileNotFoundException e) {
         } catch (IOException e) {
+            System.err.println("ignoring " + e.getMessage());
         }
         return list;
-    }
-
-    public static void readFileToString(File file, StringBuilder buf) throws Exception {
-        BufferedReader result = new BufferedReader(new FileReader(file));
-        while (true) {
-            String s = result.readLine();
-            if (s == null) {
-                break;
-            } else {
-                buf.append(s);
-                buf.append('\n');
-            }
-        }
-        result.close();
     }
 
     public static void deleteRec(File path) {
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
index eb81d3f..8fe11c8 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
@@ -61,9 +61,7 @@
 public class ADMDataParser extends AbstractDataParser implements IStreamDataParser, IRecordDataParser<char[]>
{
     private AdmLexer admLexer;
     private final ARecordType recordType;
-    private boolean isStreamParser = true;
 
-    private int nullableFieldId = 0;
     private final ArrayBackedValueStorage castBuffer = new ArrayBackedValueStorage();
 
     private final IObjectPool<IARecordBuilder, ATypeTag> recordBuilderPool = new ListObjectPool<IARecordBuilder,
ATypeTag>(
@@ -72,8 +70,6 @@
             new ListBuilderFactory());
     private final IObjectPool<IMutableValueStorage, ATypeTag> abvsBuilderPool = new
ListObjectPool<IMutableValueStorage, ATypeTag>(
             new AbvsBuilderFactory());
-
-    protected final AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
 
     private final String mismatchErrorMessage = "Mismatch Type, expecting a value of type
";
     private final String mismatchErrorMessage2 = " got a value of type ";
@@ -131,8 +127,7 @@
     public ADMDataParser(String filename, ARecordType recordType, boolean isStream) {
         this.filename = filename;
         this.recordType = recordType;
-        this.isStreamParser = isStream;
-        if (!isStreamParser) {
+        if (!isStream) {
             this.admLexer = new AdmLexer();
         }
     }
@@ -182,89 +177,72 @@
     private void admFromLexerStream(int token, IAType objectType, DataOutput out) throws
IOException {
 
         switch (token) {
-            case AdmLexer.TOKEN_NULL_LITERAL: {
+            case AdmLexer.TOKEN_NULL_LITERAL:
                 if (checkType(ATypeTag.NULL, objectType)) {
                     nullSerde.serialize(ANull.NULL, out);
                 } else {
                     throw new ParseException("This field can not be null");
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_TRUE_LITERAL: {
+            case AdmLexer.TOKEN_TRUE_LITERAL:
                 if (checkType(ATypeTag.BOOLEAN, objectType)) {
                     booleanSerde.serialize(ABoolean.TRUE, out);
                 } else {
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_BOOLEAN_CONS: {
+            case AdmLexer.TOKEN_BOOLEAN_CONS:
                 parseConstructor(ATypeTag.BOOLEAN, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_FALSE_LITERAL: {
+            case AdmLexer.TOKEN_FALSE_LITERAL:
                 if (checkType(ATypeTag.BOOLEAN, objectType)) {
                     booleanSerde.serialize(ABoolean.FALSE, out);
                 } else {
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_DOUBLE_LITERAL: {
+            case AdmLexer.TOKEN_DOUBLE_LITERAL:
                 parseToNumericTarget(ATypeTag.DOUBLE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_DOUBLE_CONS: {
+            case AdmLexer.TOKEN_DOUBLE_CONS:
                 parseConstructor(ATypeTag.DOUBLE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_FLOAT_LITERAL: {
+            case AdmLexer.TOKEN_FLOAT_LITERAL:
                 parseToNumericTarget(ATypeTag.FLOAT, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_FLOAT_CONS: {
+            case AdmLexer.TOKEN_FLOAT_CONS:
                 parseConstructor(ATypeTag.FLOAT, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT8_LITERAL: {
+            case AdmLexer.TOKEN_INT8_LITERAL:
                 parseAndCastNumeric(ATypeTag.INT8, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT8_CONS: {
+            case AdmLexer.TOKEN_INT8_CONS:
                 parseConstructor(ATypeTag.INT8, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT16_LITERAL: {
+            case AdmLexer.TOKEN_INT16_LITERAL:
                 parseAndCastNumeric(ATypeTag.INT16, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT16_CONS: {
+            case AdmLexer.TOKEN_INT16_CONS:
                 parseConstructor(ATypeTag.INT16, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT_LITERAL: {
+            case AdmLexer.TOKEN_INT_LITERAL:
                 // For an INT value without any suffix, we return it as INT64 type value
since it is
                 // the default integer type.
                 parseAndCastNumeric(ATypeTag.INT64, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT32_LITERAL: {
+            case AdmLexer.TOKEN_INT32_LITERAL:
                 parseAndCastNumeric(ATypeTag.INT32, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT32_CONS: {
+            case AdmLexer.TOKEN_INT32_CONS:
                 parseConstructor(ATypeTag.INT32, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT64_LITERAL: {
+            case AdmLexer.TOKEN_INT64_LITERAL:
                 parseAndCastNumeric(ATypeTag.INT64, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INT64_CONS: {
+            case AdmLexer.TOKEN_INT64_CONS:
                 parseConstructor(ATypeTag.INT64, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_STRING_LITERAL: {
+            case AdmLexer.TOKEN_STRING_LITERAL:
                 if (checkType(ATypeTag.STRING, objectType)) {
                     String tokenImage = admLexer.getLastTokenImage().substring(1,
                             admLexer.getLastTokenImage().length() - 1);
@@ -280,13 +258,11 @@
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_STRING_CONS: {
+            case AdmLexer.TOKEN_STRING_CONS:
                 parseConstructor(ATypeTag.STRING, objectType, out);
                 break;
-            }
             case AdmLexer.TOKEN_HEX_CONS:
-            case AdmLexer.TOKEN_BASE64_CONS: {
+            case AdmLexer.TOKEN_BASE64_CONS:
                 if (checkType(ATypeTag.BINARY, objectType)) {
                     if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
                         if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
@@ -298,20 +274,16 @@
                     }
                 }
                 throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
-            }
-            case AdmLexer.TOKEN_DATE_CONS: {
+            case AdmLexer.TOKEN_DATE_CONS:
                 parseConstructor(ATypeTag.DATE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_TIME_CONS: {
+            case AdmLexer.TOKEN_TIME_CONS:
                 parseConstructor(ATypeTag.TIME, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_DATETIME_CONS: {
+            case AdmLexer.TOKEN_DATETIME_CONS:
                 parseConstructor(ATypeTag.DATETIME, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_INTERVAL_CONS: {
+            case AdmLexer.TOKEN_INTERVAL_CONS:
                 if (checkType(ATypeTag.INTERVAL, objectType)) {
                     objectType = getComplexType(objectType, ATypeTag.INTERVAL);
                     parseInterval(ATypeTag.INTERVAL, objectType, out);
@@ -319,44 +291,34 @@
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_DURATION_CONS: {
+            case AdmLexer.TOKEN_DURATION_CONS:
                 parseConstructor(ATypeTag.DURATION, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_YEAR_MONTH_DURATION_CONS: {
+            case AdmLexer.TOKEN_YEAR_MONTH_DURATION_CONS:
                 parseConstructor(ATypeTag.YEARMONTHDURATION, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_DAY_TIME_DURATION_CONS: {
+            case AdmLexer.TOKEN_DAY_TIME_DURATION_CONS:
                 parseConstructor(ATypeTag.DAYTIMEDURATION, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_POINT_CONS: {
+            case AdmLexer.TOKEN_POINT_CONS:
                 parseConstructor(ATypeTag.POINT, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_POINT3D_CONS: {
+            case AdmLexer.TOKEN_POINT3D_CONS:
                 parseConstructor(ATypeTag.POINT3D, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_CIRCLE_CONS: {
+            case AdmLexer.TOKEN_CIRCLE_CONS:
                 parseConstructor(ATypeTag.CIRCLE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_RECTANGLE_CONS: {
+            case AdmLexer.TOKEN_RECTANGLE_CONS:
                 parseConstructor(ATypeTag.RECTANGLE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_LINE_CONS: {
+            case AdmLexer.TOKEN_LINE_CONS:
                 parseConstructor(ATypeTag.LINE, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_POLYGON_CONS: {
+            case AdmLexer.TOKEN_POLYGON_CONS:
                 parseConstructor(ATypeTag.POLYGON, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_START_UNORDERED_LIST: {
+            case AdmLexer.TOKEN_START_UNORDERED_LIST:
                 if (checkType(ATypeTag.UNORDEREDLIST, objectType)) {
                     objectType = getComplexType(objectType, ATypeTag.UNORDEREDLIST);
                     parseUnorderedList((AUnorderedListType) objectType, out);
@@ -364,8 +326,7 @@
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_START_ORDERED_LIST: {
+            case AdmLexer.TOKEN_START_ORDERED_LIST:
                 if (checkType(ATypeTag.ORDEREDLIST, objectType)) {
                     objectType = getComplexType(objectType, ATypeTag.ORDEREDLIST);
                     parseOrderedList((AOrderedListType) objectType, out);
@@ -373,8 +334,7 @@
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_START_RECORD: {
+            case AdmLexer.TOKEN_START_RECORD:
                 if (checkType(ATypeTag.RECORD, objectType)) {
                     objectType = getComplexType(objectType, ATypeTag.RECORD);
                     parseRecord((ARecordType) objectType, out);
@@ -382,17 +342,13 @@
                     throw new ParseException(mismatchErrorMessage + objectType.getTypeName());
                 }
                 break;
-            }
-            case AdmLexer.TOKEN_UUID_CONS: {
+            case AdmLexer.TOKEN_UUID_CONS:
                 parseConstructor(ATypeTag.UUID, objectType, out);
                 break;
-            }
-            case AdmLexer.TOKEN_EOF: {
+            case AdmLexer.TOKEN_EOF:
                 break;
-            }
-            default: {
+            default:
                 throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+ ".");
-            }
         }
 
     }
@@ -527,14 +483,13 @@
         do {
             token = admLexer.next();
             switch (token) {
-                case AdmLexer.TOKEN_END_RECORD: {
+                case AdmLexer.TOKEN_END_RECORD:
                     if (expectingRecordField) {
                         throw new ParseException("Found END_RECORD while expecting a record
field.");
                     }
                     inRecord = false;
                     break;
-                }
-                case AdmLexer.TOKEN_STRING_LITERAL: {
+                case AdmLexer.TOKEN_STRING_LITERAL:
                     // we've read the name of the field
                     // now read the content
                     fieldNameBuffer.reset();
@@ -583,8 +538,7 @@
                     }
 
                     break;
-                }
-                case AdmLexer.TOKEN_COMMA: {
+                case AdmLexer.TOKEN_COMMA:
                     if (first) {
                         throw new ParseException("Found COMMA before any record field.");
                     }
@@ -593,17 +547,15 @@
                     }
                     expectingRecordField = true;
                     break;
-                }
-                default: {
+                default:
                     throw new ParseException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
                             + " while parsing record fields.");
-                }
             }
             first = false;
         } while (inRecord);
 
         if (recType != null) {
-            nullableFieldId = checkOptionalConstraints(recType, nulls);
+            final int nullableFieldId = checkOptionalConstraints(recType, nulls);
             if (nullableFieldId != -1) {
                 throw new ParseException("Field: " + recType.getFieldNames()[nullableFieldId]
+ " can not be null");
             }
@@ -832,14 +784,12 @@
     private void parseToBinaryTarget(int lexerToken, String tokenImage, DataOutput out)
             throws ParseException, HyracksDataException {
         switch (lexerToken) {
-            case AdmLexer.TOKEN_HEX_CONS: {
+            case AdmLexer.TOKEN_HEX_CONS:
                 parseHexBinaryString(tokenImage.toCharArray(), 1, tokenImage.length() - 2,
out);
                 break;
-            }
-            case AdmLexer.TOKEN_BASE64_CONS: {
+            case AdmLexer.TOKEN_BASE64_CONS:
                 parseBase64BinaryString(tokenImage.toCharArray(), 1, tokenImage.length()
- 2, out);
                 break;
-            }
         }
     }
 
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
index d6593b5..1cbe364 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
@@ -106,7 +106,7 @@
     protected AMutablePoint aPoint2 = new AMutablePoint(0, 0);
     protected AMutableLine aLine = new AMutableLine(null, null);
     protected AMutableDate aDate = new AMutableDate(0);
-    protected final AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
+    protected AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
 
     // Serializers
     @SuppressWarnings("unchecked")

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1370
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9b23c3e8acd38e3a3ffce5da797f57c064b667c4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>

Mime
View raw message