Repository: asterixdb Updated Branches: refs/heads/master c692e6a37 -> dc0cf73a5
remove dead code and curly braces in switches Change-Id: I9b23c3e8acd38e3a3ffce5da797f57c064b667c4 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1370 Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Ian Maxon <ima...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/dc0cf73a Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/dc0cf73a Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/dc0cf73a Branch: refs/heads/master Commit: dc0cf73a501d3d69fa97d4409ba13a37695ce48f Parents: c692e6a Author: Till Westmann <ti...@apache.org> Authored: Fri Dec 2 09:03:46 2016 -0800 Committer: Till Westmann <ti...@apache.org> Committed: Tue Dec 6 13:26:39 2016 -0800 ---------------------------------------------------------------------- .../asterix/test/base/AsterixTestHelper.java | 20 +-- .../asterix/external/parser/ADMDataParser.java | 144 ++++++------------- .../external/parser/AbstractDataParser.java | 2 +- 3 files changed, 50 insertions(+), 116 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/dc0cf73a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java ---------------------------------------------------------------------- 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,33 +45,17 @@ public class AsterixTestHelper { 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) { if (path.isDirectory()) { for (File f : path.listFiles()) { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/dc0cf73a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java ---------------------------------------------------------------------- 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 @@ import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; 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>( @@ -73,8 +71,6 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars } } 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars } break; - } - case AdmLexer.TOKEN_COMMA: { + case AdmLexer.TOKEN_COMMA: if (first) { throw new ParseException("Found COMMA before any record field."); } @@ -593,17 +547,15 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars } 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 @@ public class ADMDataParser extends AbstractDataParser implements IStreamDataPars 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; - } } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/dc0cf73a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java ---------------------------------------------------------------------- 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 @@ public abstract class AbstractDataParser implements IDataParser { 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")