Skip to content

Commit 20d4363

Browse files
PARQUET-2406: Clean up valueOf calls where possible (#1229)
1 parent efd6dab commit 20d4363

14 files changed

Lines changed: 21 additions & 29 deletions

File tree

parquet-avro/src/main/java/org/apache/parquet/avro/AvroIndexedRecordConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private static Converter newConverter(Schema schema, Type type, GenericData mode
168168
case MAP:
169169
return new MapConverter(parent, type.asGroupType(), schema, model);
170170
case RECORD:
171-
return new AvroIndexedRecordConverter(parent, type.asGroupType(), schema, model);
171+
return new AvroIndexedRecordConverter<>(parent, type.asGroupType(), schema, model);
172172
case STRING:
173173
return new AvroConverters.FieldStringConverter(parent);
174174
case UNION:
@@ -260,7 +260,7 @@ static final class FieldFixedConverter extends PrimitiveConverter {
260260
private final ParentValueContainer parent;
261261
private final Schema avroSchema;
262262
private final Class<? extends GenericData.Fixed> fixedClass;
263-
private final Constructor fixedClassCtor;
263+
private final Constructor<? extends Object> fixedClassCtor;
264264

265265
public FieldFixedConverter(ParentValueContainer parent, Schema avroSchema, GenericData model) {
266266
this.parent = parent;

parquet-avro/src/main/java/org/apache/parquet/avro/AvroReadSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public RecordMaterializer<T> prepareForRead(
156156

157157
GenericData model = getDataModel(configuration, avroSchema);
158158
String compatEnabled = metadata.get(AvroReadSupport.AVRO_COMPATIBILITY);
159-
if (compatEnabled != null && Boolean.valueOf(compatEnabled)) {
159+
if (Boolean.parseBoolean(compatEnabled)) {
160160
return newCompatMaterializer(parquetSchema, avroSchema, model);
161161
}
162162
return new AvroRecordMaterializer<T>(parquetSchema, avroSchema, model);

parquet-cli/src/main/java/org/apache/parquet/cli/csv/AvroCSV.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static Schema inferSchemaInternal(
108108
Objects.requireNonNull(line, "No content to infer schema");
109109
header = new String[line.length];
110110
for (int i = 0; i < line.length; i += 1) {
111-
header[i] = "field_" + String.valueOf(i);
111+
header[i] = "field_" + i;
112112
}
113113
}
114114

parquet-cli/src/main/java/org/apache/parquet/cli/csv/CSVProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static class Builder {
6363
private String delimiter = DEFAULT_DELIMITER;
6464
private String quote = DEFAULT_QUOTE;
6565
private String escape = DEFAULT_ESCAPE;
66-
private boolean useHeader = Boolean.valueOf(DEFAULT_HAS_HEADER);
66+
private boolean useHeader = Boolean.parseBoolean(DEFAULT_HAS_HEADER);
6767
private int linesToSkip = DEFAULT_LINES_TO_SKIP;
6868
private String header = null;
6969

parquet-cli/src/main/java/org/apache/parquet/cli/json/AvroJson.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ private static Object convertField(GenericData model, JsonNode datum, Schema.Fie
212212
throw new RecordException(String.format("Cannot convert field %s", field.name()), e);
213213
} catch (AvroRuntimeException e) {
214214
throw new RecordException(
215-
String.format(
216-
"Field %s: cannot make %s value: '%s'",
217-
field.name(), field.schema(), String.valueOf(datum)),
218-
e);
215+
String.format("Field %s: cannot make %s value: '%s'", field.name(), field.schema(), datum), e);
219216
}
220217
}
221218

parquet-column/src/main/java/org/apache/parquet/column/values/dictionary/DictionaryValuesWriter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ public void resetDictionary() {
226226
public String memUsageString(String prefix) {
227227
return String.format(
228228
"%s DictionaryValuesWriter{\n" + "%s\n" + "%s\n" + "%s}\n",
229-
prefix,
230-
prefix + " dict:" + dictionaryByteSize,
231-
prefix + " values:" + String.valueOf(encodedValues.size() * 4),
232-
prefix);
229+
prefix, prefix + " dict:" + dictionaryByteSize, prefix + " values:" + encodedValues.size() * 4, prefix);
233230
}
234231

235232
public static class PlainBinaryDictionaryValuesWriter extends DictionaryValuesWriter {

parquet-column/src/main/java/org/apache/parquet/example/data/simple/Int96Value.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public void writeValue(RecordConsumer recordConsumer) {
4141

4242
@Override
4343
public String toString() {
44-
return "Int96Value{" + String.valueOf(value) + "}";
44+
return "Int96Value{" + value + "}";
4545
}
4646
}

parquet-common/src/main/java/org/apache/parquet/SemanticVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public static SemanticVersion parse(String version) throws SemanticVersionParseE
103103
final int patch;
104104

105105
try {
106-
major = Integer.valueOf(matcher.group(1));
107-
minor = Integer.valueOf(matcher.group(2));
108-
patch = Integer.valueOf(matcher.group(3));
106+
major = Integer.parseInt(matcher.group(1));
107+
minor = Integer.parseInt(matcher.group(2));
108+
patch = Integer.parseInt(matcher.group(3));
109109
} catch (NumberFormatException e) {
110110
throw new SemanticVersionParseException(e);
111111
}

parquet-hadoop/src/main/java/org/apache/parquet/ParquetReadOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public FileDecryptionProperties getDecryptionProperties() {
212212

213213
public boolean isEnabled(String property, boolean defaultValue) {
214214
Optional<String> propValue = Optional.ofNullable(properties.get(property));
215-
return propValue.isPresent() ? Boolean.valueOf(propValue.get()) : defaultValue;
215+
return propValue.map(Boolean::parseBoolean).orElse(defaultValue);
216216
}
217217

218218
public ParquetConfiguration getConfiguration() {

parquet-hadoop/src/main/java/org/apache/parquet/crypto/keytools/KeyMaterial.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static String createSerialized(
171171
keyMaterialMap.put(KeyMetadata.KEY_MATERIAL_INTERNAL_STORAGE_FIELD, Boolean.TRUE);
172172
}
173173
// 2. Write isFooterKey
174-
keyMaterialMap.put(IS_FOOTER_KEY_FIELD, Boolean.valueOf(isFooterKey));
174+
keyMaterialMap.put(IS_FOOTER_KEY_FIELD, isFooterKey);
175175
if (isFooterKey) {
176176
// 3. For footer key, write KMS Instance ID
177177
keyMaterialMap.put(KMS_INSTANCE_ID_FIELD, kmsInstanceID);
@@ -183,7 +183,7 @@ static String createSerialized(
183183
// 6. Write wrapped DEK
184184
keyMaterialMap.put(WRAPPED_DEK_FIELD, encodedWrappedDEK);
185185
// 7. Write isDoubleWrapped
186-
keyMaterialMap.put(DOUBLE_WRAPPING_FIELD, Boolean.valueOf(isDoubleWrapped));
186+
keyMaterialMap.put(DOUBLE_WRAPPING_FIELD, isDoubleWrapped);
187187
if (isDoubleWrapped) {
188188
// 8. In double wrapping mode, write KEK ID
189189
keyMaterialMap.put(KEK_ID_FIELD, kekID);

0 commit comments

Comments
 (0)