[ https://issues.apache.org/jira/browse/AVRO-2069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16715627#comment-16715627 ]
ASF GitHub Bot commented on AVRO-2069: -------------------------------------- dkulp closed pull request #243: AVRO-2069: Use primitive fields in generated getters & setters in Java code URL: https://github.com/apache/avro/pull/243 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm index 25b4101a6..f2e3bcfe4 100644 --- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm +++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm @@ -228,7 +228,7 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or #else * @return The value of the '${this.mangle($field.name(), $schema.isError())}' field. #end */ - public ${this.javaType($field.schema())} ${this.generateGetMethod($schema, $field)}() { + public ${this.javaUnbox($field.schema())} ${this.generateGetMethod($schema, $field)}() { return ${this.mangle($field.name(), $schema.isError())}; } #end @@ -252,7 +252,7 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or #end * @param value the value to set. */ - public void ${this.generateSetMethod($schema, $field)}(${this.javaType($field.schema())} value) { + public void ${this.generateSetMethod($schema, $field)}(${this.javaUnbox($field.schema())} value) { this.${this.mangle($field.name(), $schema.isError())} = value; } #end @@ -384,7 +384,7 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or #end * @return The value. */ - public ${this.javaType($field.schema())} ${this.generateGetMethod($schema, $field)}() { + public ${this.javaUnbox($field.schema())} ${this.generateGetMethod($schema, $field)}() { return ${this.mangle($field.name(), $schema.isError())}; } diff --git a/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java b/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java index ba960442a..5de9d6a38 100644 --- a/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java +++ b/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java @@ -62,7 +62,7 @@ public void testCompatibleReadWithSchemaFromSchemaStore() throws Exception { // Should work assertEquals(nestedEvolve1.getRootName(), "RootName"); assertEquals(nestedEvolve1.getNested().getName(), "Name"); - assertEquals(nestedEvolve1.getNested().getValue(), Long.valueOf(1)); + assertEquals(nestedEvolve1.getNested().getValue(), 1); } @Test(expected = MissingSchemaException.class) diff --git a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java index 4fa6fe0b7..1223e2325 100644 --- a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java +++ b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java @@ -47,7 +47,7 @@ public void testSpecificBuilder() { Assert.assertTrue(builder.hasName()); Assert.assertEquals("James Gosling", builder.getName()); Assert.assertTrue(builder.hasYearOfBirth()); - Assert.assertEquals(new Integer(1955), builder.getYearOfBirth()); + Assert.assertEquals(1955, builder.getYearOfBirth()); Assert.assertFalse(builder.hasCountry()); Assert.assertNull(builder.getCountry()); Assert.assertTrue(builder.hasState()); @@ -102,13 +102,13 @@ public void testUnions() { .setProduct(product) .build()) .build(); - Assert.assertEquals(datetime, p.getDatetime().longValue()); + Assert.assertEquals(datetime, p.getDatetime()); Assert.assertEquals(ProductPage.class, p.getPageContext().getClass()); Assert.assertEquals(product, ((ProductPage)p.getPageContext()).getProduct()); PageView p2 = PageView.newBuilder(p).build(); - Assert.assertEquals(datetime, p2.getDatetime().longValue()); + Assert.assertEquals(datetime, p2.getDatetime()); Assert.assertEquals(ProductPage.class, p2.getPageContext().getClass()); Assert.assertEquals(product, ((ProductPage)p2.getPageContext()).getProduct()); @@ -141,10 +141,10 @@ public void testInterop() { Assert.assertEquals(interop.getArrayField(), copy.getArrayField()); Assert.assertEquals(interop.getBoolField(), copy.getBoolField()); Assert.assertEquals(interop.getBytesField(), copy.getBytesField()); - Assert.assertEquals(interop.getDoubleField(), copy.getDoubleField()); + Assert.assertEquals(interop.getDoubleField(), copy.getDoubleField(), 0.001); Assert.assertEquals(interop.getEnumField(), copy.getEnumField()); Assert.assertEquals(interop.getFixedField(), copy.getFixedField()); - Assert.assertEquals(interop.getFloatField(), copy.getFloatField()); + Assert.assertEquals(interop.getFloatField(), copy.getFloatField(), 0.001); Assert.assertEquals(interop.getIntField(), copy.getIntField()); Assert.assertEquals(interop.getLongField(), copy.getLongField()); Assert.assertEquals(interop.getMapField(), copy.getMapField()); diff --git a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java index 531cc6fd9..8f8a9a4ed 100644 --- a/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java +++ b/lang/java/tools/src/test/compiler/output-string/avro/examples/baseball/Player.java @@ -127,7 +127,7 @@ public void put(int field$, java.lang.Object value$) { * Gets the value of the 'number' field. * @return The number of the player */ - public java.lang.Integer getNumber() { + public int getNumber() { return number; } @@ -136,7 +136,7 @@ public void put(int field$, java.lang.Object value$) { * The number of the player * @param value the value to set. */ - public void setNumber(java.lang.Integer value) { + public void setNumber(int value) { this.number = value; } @@ -292,7 +292,7 @@ private Builder(avro.examples.baseball.Player other) { * The number of the player * @return The value. */ - public java.lang.Integer getNumber() { + public int getNumber() { return number; } diff --git a/lang/java/tools/src/test/compiler/output/Player.java b/lang/java/tools/src/test/compiler/output/Player.java index 94fc7d0b3..f20af1db5 100644 --- a/lang/java/tools/src/test/compiler/output/Player.java +++ b/lang/java/tools/src/test/compiler/output/Player.java @@ -127,7 +127,7 @@ public void put(int field$, java.lang.Object value$) { * Gets the value of the 'number' field. * @return The number of the player */ - public java.lang.Integer getNumber() { + public int getNumber() { return number; } @@ -136,7 +136,7 @@ public void put(int field$, java.lang.Object value$) { * The number of the player * @param value the value to set. */ - public void setNumber(java.lang.Integer value) { + public void setNumber(int value) { this.number = value; } @@ -292,7 +292,7 @@ private Builder(avro.examples.baseball.Player other) { * The number of the player * @return The value. */ - public java.lang.Integer getNumber() { + public int getNumber() { return number; } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Use primitive fields in generated getters & setters in Java code > ---------------------------------------------------------------- > > Key: AVRO-2069 > URL: https://issues.apache.org/jira/browse/AVRO-2069 > Project: Apache Avro > Issue Type: Improvement > Affects Versions: 1.8.2 > Reporter: Daniil Gitelson > Assignee: Daniil Gitelson > Priority: Major > Fix For: 1.9.0 > > > Currently, for primitive types (such as int, long, etc) generated getters and > setters return and accept java.lang.* boxed (while fields actually holds > primitive values). This is inefeccient and produces code boilerplate. > Changed this behaviour in pull request: > https://github.com/apache/avro/pull/243 -- This message was sent by Atlassian JIRA (v7.6.3#76005)