You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/01/15 20:08:59 UTC
[avro] branch master updated: Minor non-functional changes.
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new dcf925e Minor non-functional changes.
dcf925e is described below
commit dcf925ec6c3f26ff7e5dfd7d48503b70259a2093
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Sat Jan 15 22:07:22 2022 +0200
Minor non-functional changes.
---
.../avro/src/main/java/org/apache/avro/Schema.java | 28 ++++++++++++----------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index fec08e1..c58a852 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -532,10 +532,10 @@ public abstract class Schema extends JsonProperties implements Serializable {
private final String name;
- private Order() {
+ Order() {
this.name = this.name().toLowerCase(Locale.ENGLISH);
}
- };
+ }
/**
* For Schema unions with a "null" type as the first entry, this can be used to
@@ -711,7 +711,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
this.name = validateName(name);
} else { // qualified name
space = name.substring(0, lastDot); // get space from name
- this.name = validateName(name.substring(lastDot + 1, name.length()));
+ this.name = validateName(name.substring(lastDot + 1));
}
if ("".equals(space))
space = null;
@@ -836,7 +836,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
}
public void aliasesToJson(JsonGenerator gen) throws IOException {
- if (aliases == null || aliases.size() == 0)
+ if (aliases == null || aliases.isEmpty())
return;
gen.writeFieldName("aliases");
gen.writeStartArray();
@@ -1660,19 +1660,23 @@ public abstract class Schema extends JsonProperties implements Serializable {
Name name = null;
String savedSpace = names.space();
String doc = null;
- if (type.equals("record") || type.equals("error") || type.equals("enum") || type.equals("fixed")) {
+ final boolean isTypeError = "error".equals(type);
+ final boolean isTypeRecord = "record".equals(type);
+ final boolean isTypeEnum = "enum".equals(type);
+ final boolean isTypeFixed = "fixed".equals(type);
+ if (isTypeRecord || isTypeError || isTypeEnum || isTypeFixed) {
String space = getOptionalText(schema, "namespace");
doc = getOptionalText(schema, "doc");
if (space == null)
- space = names.space();
+ space = savedSpace;
name = new Name(getRequiredText(schema, "name", "No name in schema"), space);
names.space(name.space); // set default namespace
}
if (PRIMITIVES.containsKey(type)) { // primitive
result = create(PRIMITIVES.get(type));
- } else if (type.equals("record") || type.equals("error")) { // record
+ } else if (isTypeRecord || isTypeError) { // record
List<Field> fields = new ArrayList<>();
- result = new RecordSchema(name, doc, type.equals("error"));
+ result = new RecordSchema(name, doc, isTypeError);
if (name != null)
names.add(result);
JsonNode fieldsNode = schema.get("fields");
@@ -1686,7 +1690,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
throw new SchemaParseException("No field type: " + field);
if (fieldTypeNode.isTextual() && names.get(fieldTypeNode.textValue()) == null)
throw new SchemaParseException(fieldTypeNode + " is not a defined name." + " The type of the \"" + fieldName
- + "\" field must be" + " a defined name or a {\"type\": ...} expression.");
+ + "\" field must be a defined name or a {\"type\": ...} expression.");
Schema fieldSchema = parse(fieldTypeNode, names);
Field.Order order = Field.Order.ASCENDING;
JsonNode orderNode = field.get("order");
@@ -1712,7 +1716,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
name, fieldName, getOptionalText(field, "logicalType"));
}
result.setFields(fields);
- } else if (type.equals("enum")) { // enum
+ } else if (isTypeEnum) { // enum
JsonNode symbolsNode = schema.get("symbols");
if (symbolsNode == null || !symbolsNode.isArray())
throw new SchemaParseException("Enum has no symbols: " + schema);
@@ -1736,7 +1740,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
if (valuesNode == null)
throw new SchemaParseException("Map has no values type: " + schema);
result = new MapSchema(parse(valuesNode, names));
- } else if (type.equals("fixed")) { // fixed
+ } else if (isTypeFixed) { // fixed
JsonNode sizeNode = schema.get("size");
if (sizeNode == null || !sizeNode.isInt())
throw new SchemaParseException("Invalid or no size: " + schema);
@@ -1753,7 +1757,7 @@ public abstract class Schema extends JsonProperties implements Serializable {
Iterator<String> i = schema.fieldNames();
Set reserved = SCHEMA_RESERVED;
- if (type.equals("enum")) {
+ if (isTypeEnum) {
reserved = ENUM_RESERVED;
}
while (i.hasNext()) { // add properties