Skip to content

Commit 2353cd4

Browse files
committed
Replace all uses of SchemaHolder with ValueHolder<SchemaTree>
1 parent 48a74de commit 2353cd4

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

src/main/java/com/github/fge/avro/Avro2JsonSchemaProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import com.github.fge.avro.translators.AvroTranslators;
55
import com.github.fge.jsonschema.exceptions.ProcessingException;
66
import com.github.fge.jsonschema.processing.Processor;
7-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
87
import com.github.fge.jsonschema.report.ProcessingReport;
98
import com.github.fge.jsonschema.tree.CanonicalSchemaTree;
109
import com.github.fge.jsonschema.tree.JsonTree;
10+
import com.github.fge.jsonschema.tree.SchemaTree;
1111
import com.github.fge.jsonschema.util.ValueHolder;
1212
import org.apache.avro.AvroRuntimeException;
1313
import org.apache.avro.Schema;
1414

1515
public final class Avro2JsonSchemaProcessor
16-
implements Processor<ValueHolder<JsonTree>, SchemaHolder>
16+
implements Processor<ValueHolder<JsonTree>, ValueHolder<SchemaTree>>
1717
{
1818
@Override
19-
public SchemaHolder process(final ProcessingReport report,
19+
public ValueHolder<SchemaTree> process(final ProcessingReport report,
2020
final ValueHolder<JsonTree> input)
2121
throws ProcessingException
2222
{
@@ -43,6 +43,8 @@ public SchemaHolder process(final ProcessingReport report,
4343
AvroTranslators.getTranslator(avroType)
4444
.translate(avroSchema, tree, report);
4545

46-
return new SchemaHolder(new CanonicalSchemaTree(tree.getBaseNode()));
46+
final SchemaTree schemaTree
47+
= new CanonicalSchemaTree(tree.getBaseNode());
48+
return ValueHolder.hold("schema", schemaTree);
4749
}
4850
}

src/main/java/com/github/fge/jsonschema2avro/AvroWriterProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.github.fge.jsonschema.exceptions.ProcessingException;
44
import com.github.fge.jsonschema.processing.Processor;
55
import com.github.fge.jsonschema.processing.ProcessorSelector;
6-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
76
import com.github.fge.jsonschema.report.ProcessingReport;
7+
import com.github.fge.jsonschema.tree.SchemaTree;
88
import com.github.fge.jsonschema.util.ValueHolder;
99
import com.github.fge.jsonschema2avro.writers.ArrayWriter;
1010
import com.github.fge.jsonschema2avro.writers.EnumWriter;
@@ -18,7 +18,7 @@
1818
import static com.github.fge.jsonschema2avro.predicates.AvroPredicates.*;
1919

2020
public final class AvroWriterProcessor
21-
implements Processor<SchemaHolder, ValueHolder<Schema>>
21+
implements Processor<ValueHolder<SchemaTree>, ValueHolder<Schema>>
2222
{
2323
private final Processor<AvroPayload, ValueHolder<Schema>> processor;
2424

@@ -37,7 +37,7 @@ public AvroWriterProcessor()
3737

3838
@Override
3939
public ValueHolder<Schema> process(final ProcessingReport report,
40-
final SchemaHolder input)
40+
final ValueHolder<SchemaTree> input)
4141
throws ProcessingException
4242
{
4343
final AvroPayload payload = new AvroPayload(input.getValue(), this);

src/main/java/com/github/fge/jsonschema2avro/writers/ArrayWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.github.fge.jsonschema.exceptions.ProcessingException;
55
import com.github.fge.jsonschema.jsonpointer.JsonPointer;
6-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
76
import com.github.fge.jsonschema.report.ProcessingReport;
87
import com.github.fge.jsonschema.tree.SchemaTree;
8+
import com.github.fge.jsonschema.util.ValueHolder;
99
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
1010
import org.apache.avro.Schema;
1111

@@ -33,7 +33,8 @@ protected Schema generate(final AvroWriterProcessor writer,
3333
: JsonPointer.of("additionalItems");
3434

3535
final SchemaTree subTree = tree.append(ptr);
36-
final SchemaHolder input = new SchemaHolder(subTree);
36+
final ValueHolder<SchemaTree> input
37+
= ValueHolder.hold("schema", subTree);
3738
final Schema itemsSchema = writer.process(report, input).getValue();
3839
return Schema.createArray(itemsSchema);
3940
}

src/main/java/com/github/fge/jsonschema2avro/writers/MapWriter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import com.github.fge.jsonschema.exceptions.ProcessingException;
44
import com.github.fge.jsonschema.jsonpointer.JsonPointer;
5-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
65
import com.github.fge.jsonschema.report.ProcessingReport;
76
import com.github.fge.jsonschema.tree.SchemaTree;
7+
import com.github.fge.jsonschema.util.ValueHolder;
88
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
99
import org.apache.avro.Schema;
1010

@@ -30,7 +30,9 @@ protected Schema generate(final AvroWriterProcessor writer,
3030
final ProcessingReport report, final SchemaTree tree)
3131
throws ProcessingException
3232
{
33-
final SchemaHolder input = new SchemaHolder(tree.append(POINTER));
33+
final SchemaTree schemaTree = tree.append(POINTER);
34+
final ValueHolder<SchemaTree> input
35+
= ValueHolder.hold("schema", schemaTree);
3436
final Schema valueSchema = writer.process(report, input).getValue();
3537
return Schema.createMap(valueSchema);
3638
}

src/main/java/com/github/fge/jsonschema2avro/writers/RecordWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import com.github.fge.jsonschema.exceptions.ProcessingException;
44
import com.github.fge.jsonschema.jsonpointer.JsonPointer;
5-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
65
import com.github.fge.jsonschema.report.ProcessingReport;
76
import com.github.fge.jsonschema.tree.SchemaTree;
7+
import com.github.fge.jsonschema.util.ValueHolder;
88
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
99
import com.google.common.collect.Lists;
1010
import org.apache.avro.Schema;
@@ -33,12 +33,12 @@ protected Schema generate(final AvroWriterProcessor writer,
3333
final List<Schema.Field> fields = Lists.newArrayList();
3434

3535
JsonPointer ptr;
36-
SchemaHolder holder;
36+
ValueHolder<SchemaTree> holder;
3737
Schema fieldSchema;
3838

3939
for (final String name: list) {
4040
ptr = JsonPointer.of("properties", name);
41-
holder = new SchemaHolder(tree.append(ptr));
41+
holder = ValueHolder.hold("schema", tree.append(ptr));
4242
fieldSchema = writer.process(report, holder).getValue();
4343
fields.add(new Schema.Field(name, fieldSchema, null, null));
4444
}

src/main/java/com/github/fge/jsonschema2avro/writers/SimpleUnionWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.github.fge.jsonschema.exceptions.ProcessingException;
55
import com.github.fge.jsonschema.jsonpointer.JsonPointer;
6-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
76
import com.github.fge.jsonschema.report.ProcessingReport;
87
import com.github.fge.jsonschema.tree.SchemaTree;
8+
import com.github.fge.jsonschema.util.ValueHolder;
99
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
1010
import com.google.common.collect.Lists;
1111
import org.apache.avro.Schema;
@@ -36,14 +36,14 @@ protected Schema generate(final AvroWriterProcessor writer,
3636
final int size = node.get(keyword).size();
3737

3838
JsonPointer ptr;
39-
SchemaHolder holder;
39+
ValueHolder<SchemaTree> holder;
4040
Schema subSchema;
4141

4242
final List<Schema> schemas = Lists.newArrayList();
4343

4444
for (int index = 0; index < size; index++) {
4545
ptr = JsonPointer.of(keyword, index);
46-
holder = new SchemaHolder(tree.append(ptr));
46+
holder = ValueHolder.hold("schema", tree.append(ptr));
4747
subSchema = writer.process(report, holder).getValue();
4848
if (subSchema.getType() == Schema.Type.UNION)
4949
throw new ProcessingException("union within union is illegal");

src/main/java/com/github/fge/jsonschema2avro/writers/TypeUnionWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import com.fasterxml.jackson.databind.node.ArrayNode;
55
import com.fasterxml.jackson.databind.node.ObjectNode;
66
import com.github.fge.jsonschema.exceptions.ProcessingException;
7-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
87
import com.github.fge.jsonschema.report.ProcessingReport;
98
import com.github.fge.jsonschema.tree.CanonicalSchemaTree;
109
import com.github.fge.jsonschema.tree.SchemaTree;
10+
import com.github.fge.jsonschema.util.ValueHolder;
1111
import com.github.fge.jsonschema2avro.AvroWriterProcessor;
1212
import com.google.common.collect.Lists;
1313
import org.apache.avro.Schema;
@@ -38,18 +38,18 @@ protected Schema generate(final AvroWriterProcessor writer,
3838
final JsonNode node = tree.getNode();
3939
final List<Schema> schemas = Lists.newArrayList();
4040

41-
for (final SchemaHolder holder: expand(node))
41+
for (final ValueHolder<SchemaTree> holder: expand(node))
4242
schemas.add(writer.process(report, holder).getValue());
4343

4444
return Schema.createUnion(schemas);
4545
}
4646

47-
private static List<SchemaHolder> expand(final JsonNode node)
47+
private static List<ValueHolder<SchemaTree>> expand(final JsonNode node)
4848
{
4949
final ObjectNode common = node.deepCopy();
5050
final ArrayNode typeNode = (ArrayNode) common.remove("type");
5151

52-
final List<SchemaHolder> ret = Lists.newArrayList();
52+
final List<ValueHolder<SchemaTree>> ret = Lists.newArrayList();
5353

5454
ObjectNode schema;
5555
SchemaTree tree;
@@ -58,7 +58,7 @@ private static List<SchemaHolder> expand(final JsonNode node)
5858
schema = common.deepCopy();
5959
schema.put("type", element);
6060
tree = new CanonicalSchemaTree(schema);
61-
ret.add(new SchemaHolder(tree));
61+
ret.add(ValueHolder.hold("schema", tree));
6262
}
6363

6464
return ret;

src/test/java/com/github/fge/avro/AvroTranslationsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.github.fge.jsonschema.cfg.ValidationConfiguration;
55
import com.github.fge.jsonschema.exceptions.ProcessingException;
6-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
76
import com.github.fge.jsonschema.processors.syntax.SyntaxValidator;
87
import com.github.fge.jsonschema.report.DevNullProcessingReport;
98
import com.github.fge.jsonschema.report.ProcessingReport;
109
import com.github.fge.jsonschema.tree.JsonTree;
10+
import com.github.fge.jsonschema.tree.SchemaTree;
1111
import com.github.fge.jsonschema.tree.SimpleJsonTree;
1212
import com.github.fge.jsonschema.util.JsonLoader;
1313
import com.github.fge.jsonschema.util.ValueHolder;
@@ -72,7 +72,7 @@ public final void conversionIsCorrectlyPerformed(final JsonNode avroSchema,
7272
final ValueHolder<JsonTree> input
7373
= ValueHolder.<JsonTree>hold(new SimpleJsonTree(avroSchema));
7474

75-
final SchemaHolder output = PROCESSOR.process(report, input);
75+
final ValueHolder<SchemaTree> output = PROCESSOR.process(report, input);
7676
assertEquals(output.getValue().getBaseNode(), jsonSchema);
7777

7878
assertTrue(VALIDATOR.schemaIsValid(jsonSchema));

src/test/java/com/github/fge/jsonschema2avro/AvroWriterProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.github.fge.jsonschema.exceptions.ProcessingException;
5-
import com.github.fge.jsonschema.processors.data.SchemaHolder;
65
import com.github.fge.jsonschema.report.ProcessingReport;
76
import com.github.fge.jsonschema.tree.CanonicalSchemaTree;
87
import com.github.fge.jsonschema.tree.SchemaTree;
98
import com.github.fge.jsonschema.util.JsonLoader;
9+
import com.github.fge.jsonschema.util.ValueHolder;
1010
import com.google.common.collect.Lists;
1111
import org.apache.avro.Schema;
1212
import org.testng.annotations.BeforeMethod;
@@ -61,7 +61,7 @@ public final void JsonSchemasAreCorrectlyTranslated(final JsonNode schema,
6161
throws ProcessingException
6262
{
6363
final SchemaTree tree = new CanonicalSchemaTree(schema);
64-
final SchemaHolder input = new SchemaHolder(tree);
64+
final ValueHolder<SchemaTree> input = ValueHolder.hold("schema", tree);
6565
final Schema expected = new Schema.Parser().parse(avro.toString());
6666

6767
final Schema actual = processor.process(report, input).getValue();

0 commit comments

Comments
 (0)