Merge branch 'eugenp:master' into master
This commit is contained in:
commit
59dcedba09
|
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
||||||
public class February29thMatcher implements DateMatcher {
|
public class February29thMatcher implements DateMatcher {
|
||||||
|
|
||||||
private static final Pattern DATE_PATTERN = Pattern.compile(
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$");
|
"^((2000|2400|2800|(19|2[0-9])(0[48]|[2468][048]|[13579][26]))-02-29)$");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(String date) {
|
public boolean matches(String date) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
||||||
class GregorianDateMatcher implements DateMatcher {
|
class GregorianDateMatcher implements DateMatcher {
|
||||||
|
|
||||||
private static final Pattern DATE_PATTERN = Pattern.compile(
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"
|
"^((2000|2400|2800|(19|2[0-9])(0[48]|[2468][048]|[13579][26]))-02-29)$"
|
||||||
+ "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$"
|
+ "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$"
|
||||||
+ "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"
|
+ "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"
|
||||||
+ "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$");
|
+ "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$");
|
||||||
|
|
|
@ -37,6 +37,8 @@ public class GregorianDateTestHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertFebruary29th() {
|
public void assertFebruary29th() {
|
||||||
|
Assert.assertTrue(matcher.matches("1904-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("1996-02-29"));
|
||||||
Assert.assertTrue(matcher.matches("2000-02-29"));
|
Assert.assertTrue(matcher.matches("2000-02-29"));
|
||||||
Assert.assertTrue(matcher.matches("2400-02-29"));
|
Assert.assertTrue(matcher.matches("2400-02-29"));
|
||||||
Assert.assertTrue(matcher.matches("2800-02-29"));
|
Assert.assertTrue(matcher.matches("2800-02-29"));
|
||||||
|
@ -44,6 +46,8 @@ public class GregorianDateTestHelper {
|
||||||
Assert.assertTrue(matcher.matches("2024-02-29"));
|
Assert.assertTrue(matcher.matches("2024-02-29"));
|
||||||
Assert.assertTrue(matcher.matches("2028-02-29"));
|
Assert.assertTrue(matcher.matches("2028-02-29"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("1900-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("1999-02-29"));
|
||||||
Assert.assertFalse(matcher.matches("2017-02-29"));
|
Assert.assertFalse(matcher.matches("2017-02-29"));
|
||||||
Assert.assertFalse(matcher.matches("2018-02-29"));
|
Assert.assertFalse(matcher.matches("2018-02-29"));
|
||||||
Assert.assertFalse(matcher.matches("2019-02-29"));
|
Assert.assertFalse(matcher.matches("2019-02-29"));
|
||||||
|
|
|
@ -0,0 +1,517 @@
|
||||||
|
/**
|
||||||
|
* Autogenerated by Avro
|
||||||
|
*
|
||||||
|
* DO NOT EDIT DIRECTLY
|
||||||
|
*/
|
||||||
|
package com.baeldung.schema;
|
||||||
|
|
||||||
|
import org.apache.avro.specific.SpecificData;
|
||||||
|
import org.apache.avro.message.BinaryMessageEncoder;
|
||||||
|
import org.apache.avro.message.BinaryMessageDecoder;
|
||||||
|
import org.apache.avro.message.SchemaStore;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@org.apache.avro.specific.AvroGenerated
|
||||||
|
public class Employee extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
|
||||||
|
private static final long serialVersionUID = 7340575283344282036L;
|
||||||
|
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Employee\",\"namespace\":\"com.baeldung.schema\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"firstName\",\"type\":\"string\"},{\"name\":\"lastName\",\"type\":\"string\"},{\"name\":\"department\",\"type\":\"string\",\"default\":\"IT \"},{\"name\":\"designation\",\"type\":\"string\",\"default\":\"Software Engineer\"}]}");
|
||||||
|
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
|
||||||
|
|
||||||
|
private static SpecificData MODEL$ = new SpecificData();
|
||||||
|
|
||||||
|
private static final BinaryMessageEncoder<Employee> ENCODER =
|
||||||
|
new BinaryMessageEncoder<Employee>(MODEL$, SCHEMA$);
|
||||||
|
|
||||||
|
private static final BinaryMessageDecoder<Employee> DECODER =
|
||||||
|
new BinaryMessageDecoder<Employee>(MODEL$, SCHEMA$);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the BinaryMessageDecoder instance used by this class.
|
||||||
|
*/
|
||||||
|
public static BinaryMessageDecoder<Employee> getDecoder() {
|
||||||
|
return DECODER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
|
||||||
|
* @param resolver a {@link SchemaStore} used to find schemas by fingerprint
|
||||||
|
*/
|
||||||
|
public static BinaryMessageDecoder<Employee> createDecoder(SchemaStore resolver) {
|
||||||
|
return new BinaryMessageDecoder<Employee>(MODEL$, SCHEMA$, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Serializes this Employee to a ByteBuffer. */
|
||||||
|
public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
|
||||||
|
return ENCODER.encode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Deserializes a Employee from a ByteBuffer. */
|
||||||
|
public static Employee fromByteBuffer(
|
||||||
|
java.nio.ByteBuffer b) throws java.io.IOException {
|
||||||
|
return DECODER.decode(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated public int id;
|
||||||
|
@Deprecated public java.lang.CharSequence firstName;
|
||||||
|
@Deprecated public java.lang.CharSequence lastName;
|
||||||
|
@Deprecated public java.lang.CharSequence department;
|
||||||
|
@Deprecated public java.lang.CharSequence designation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor. Note that this does not initialize fields
|
||||||
|
* to their default values from the schema. If that is desired then
|
||||||
|
* one should use <code>newBuilder()</code>.
|
||||||
|
*/
|
||||||
|
public Employee() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All-args constructor.
|
||||||
|
* @param id The new value for id
|
||||||
|
* @param firstName The new value for firstName
|
||||||
|
* @param lastName The new value for lastName
|
||||||
|
* @param department The new value for department
|
||||||
|
* @param designation The new value for designation
|
||||||
|
*/
|
||||||
|
public Employee(java.lang.Integer id, java.lang.CharSequence firstName, java.lang.CharSequence lastName, java.lang.CharSequence department, java.lang.CharSequence designation) {
|
||||||
|
this.id = id;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
this.department = department;
|
||||||
|
this.designation = designation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
|
||||||
|
// Used by DatumWriter. Applications should not call.
|
||||||
|
public java.lang.Object get(int field$) {
|
||||||
|
switch (field$) {
|
||||||
|
case 0: return id;
|
||||||
|
case 1: return firstName;
|
||||||
|
case 2: return lastName;
|
||||||
|
case 3: return department;
|
||||||
|
case 4: return designation;
|
||||||
|
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used by DatumReader. Applications should not call.
|
||||||
|
@SuppressWarnings(value="unchecked")
|
||||||
|
public void put(int field$, java.lang.Object value$) {
|
||||||
|
switch (field$) {
|
||||||
|
case 0: id = (java.lang.Integer)value$; break;
|
||||||
|
case 1: firstName = (java.lang.CharSequence)value$; break;
|
||||||
|
case 2: lastName = (java.lang.CharSequence)value$; break;
|
||||||
|
case 3: department = (java.lang.CharSequence)value$; break;
|
||||||
|
case 4: designation = (java.lang.CharSequence)value$; break;
|
||||||
|
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'id' field.
|
||||||
|
* @return The value of the 'id' field.
|
||||||
|
*/
|
||||||
|
public java.lang.Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'id' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setId(java.lang.Integer value) {
|
||||||
|
this.id = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'firstName' field.
|
||||||
|
* @return The value of the 'firstName' field.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'firstName' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setFirstName(java.lang.CharSequence value) {
|
||||||
|
this.firstName = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'lastName' field.
|
||||||
|
* @return The value of the 'lastName' field.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'lastName' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setLastName(java.lang.CharSequence value) {
|
||||||
|
this.lastName = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'department' field.
|
||||||
|
* @return The value of the 'department' field.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDepartment() {
|
||||||
|
return department;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'department' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setDepartment(java.lang.CharSequence value) {
|
||||||
|
this.department = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'designation' field.
|
||||||
|
* @return The value of the 'designation' field.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDesignation() {
|
||||||
|
return designation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'designation' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setDesignation(java.lang.CharSequence value) {
|
||||||
|
this.designation = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Employee RecordBuilder.
|
||||||
|
* @return A new Employee RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.Employee.Builder newBuilder() {
|
||||||
|
return new com.baeldung.schema.Employee.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Employee RecordBuilder by copying an existing Builder.
|
||||||
|
* @param other The existing builder to copy.
|
||||||
|
* @return A new Employee RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.Employee.Builder newBuilder(com.baeldung.schema.Employee.Builder other) {
|
||||||
|
return new com.baeldung.schema.Employee.Builder(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Employee RecordBuilder by copying an existing Employee instance.
|
||||||
|
* @param other The existing instance to copy.
|
||||||
|
* @return A new Employee RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.Employee.Builder newBuilder(com.baeldung.schema.Employee other) {
|
||||||
|
return new com.baeldung.schema.Employee.Builder(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RecordBuilder for Employee instances.
|
||||||
|
*/
|
||||||
|
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<Employee>
|
||||||
|
implements org.apache.avro.data.RecordBuilder<Employee> {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private java.lang.CharSequence firstName;
|
||||||
|
private java.lang.CharSequence lastName;
|
||||||
|
private java.lang.CharSequence department;
|
||||||
|
private java.lang.CharSequence designation;
|
||||||
|
|
||||||
|
/** Creates a new Builder */
|
||||||
|
private Builder() {
|
||||||
|
super(SCHEMA$);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Builder by copying an existing Builder.
|
||||||
|
* @param other The existing Builder to copy.
|
||||||
|
*/
|
||||||
|
private Builder(com.baeldung.schema.Employee.Builder other) {
|
||||||
|
super(other);
|
||||||
|
if (isValidValue(fields()[0], other.id)) {
|
||||||
|
this.id = data().deepCopy(fields()[0].schema(), other.id);
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[1], other.firstName)) {
|
||||||
|
this.firstName = data().deepCopy(fields()[1].schema(), other.firstName);
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[2], other.lastName)) {
|
||||||
|
this.lastName = data().deepCopy(fields()[2].schema(), other.lastName);
|
||||||
|
fieldSetFlags()[2] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[3], other.department)) {
|
||||||
|
this.department = data().deepCopy(fields()[3].schema(), other.department);
|
||||||
|
fieldSetFlags()[3] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[4], other.designation)) {
|
||||||
|
this.designation = data().deepCopy(fields()[4].schema(), other.designation);
|
||||||
|
fieldSetFlags()[4] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Builder by copying an existing Employee instance
|
||||||
|
* @param other The existing instance to copy.
|
||||||
|
*/
|
||||||
|
private Builder(com.baeldung.schema.Employee other) {
|
||||||
|
super(SCHEMA$);
|
||||||
|
if (isValidValue(fields()[0], other.id)) {
|
||||||
|
this.id = data().deepCopy(fields()[0].schema(), other.id);
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[1], other.firstName)) {
|
||||||
|
this.firstName = data().deepCopy(fields()[1].schema(), other.firstName);
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[2], other.lastName)) {
|
||||||
|
this.lastName = data().deepCopy(fields()[2].schema(), other.lastName);
|
||||||
|
fieldSetFlags()[2] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[3], other.department)) {
|
||||||
|
this.department = data().deepCopy(fields()[3].schema(), other.department);
|
||||||
|
fieldSetFlags()[3] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[4], other.designation)) {
|
||||||
|
this.designation = data().deepCopy(fields()[4].schema(), other.designation);
|
||||||
|
fieldSetFlags()[4] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'id' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'id' field.
|
||||||
|
* @param value The value of 'id'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder setId(int value) {
|
||||||
|
validate(fields()[0], value);
|
||||||
|
this.id = value;
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'id' field has been set.
|
||||||
|
* @return True if the 'id' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasId() {
|
||||||
|
return fieldSetFlags()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'id' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder clearId() {
|
||||||
|
fieldSetFlags()[0] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'firstName' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'firstName' field.
|
||||||
|
* @param value The value of 'firstName'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder setFirstName(java.lang.CharSequence value) {
|
||||||
|
validate(fields()[1], value);
|
||||||
|
this.firstName = value;
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'firstName' field has been set.
|
||||||
|
* @return True if the 'firstName' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasFirstName() {
|
||||||
|
return fieldSetFlags()[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'firstName' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder clearFirstName() {
|
||||||
|
firstName = null;
|
||||||
|
fieldSetFlags()[1] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'lastName' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'lastName' field.
|
||||||
|
* @param value The value of 'lastName'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder setLastName(java.lang.CharSequence value) {
|
||||||
|
validate(fields()[2], value);
|
||||||
|
this.lastName = value;
|
||||||
|
fieldSetFlags()[2] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'lastName' field has been set.
|
||||||
|
* @return True if the 'lastName' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasLastName() {
|
||||||
|
return fieldSetFlags()[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'lastName' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder clearLastName() {
|
||||||
|
lastName = null;
|
||||||
|
fieldSetFlags()[2] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'department' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDepartment() {
|
||||||
|
return department;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'department' field.
|
||||||
|
* @param value The value of 'department'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder setDepartment(java.lang.CharSequence value) {
|
||||||
|
validate(fields()[3], value);
|
||||||
|
this.department = value;
|
||||||
|
fieldSetFlags()[3] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'department' field has been set.
|
||||||
|
* @return True if the 'department' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasDepartment() {
|
||||||
|
return fieldSetFlags()[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'department' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder clearDepartment() {
|
||||||
|
department = null;
|
||||||
|
fieldSetFlags()[3] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'designation' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDesignation() {
|
||||||
|
return designation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'designation' field.
|
||||||
|
* @param value The value of 'designation'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder setDesignation(java.lang.CharSequence value) {
|
||||||
|
validate(fields()[4], value);
|
||||||
|
this.designation = value;
|
||||||
|
fieldSetFlags()[4] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'designation' field has been set.
|
||||||
|
* @return True if the 'designation' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasDesignation() {
|
||||||
|
return fieldSetFlags()[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'designation' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.Employee.Builder clearDesignation() {
|
||||||
|
designation = null;
|
||||||
|
fieldSetFlags()[4] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Employee build() {
|
||||||
|
try {
|
||||||
|
Employee record = new Employee();
|
||||||
|
record.id = fieldSetFlags()[0] ? this.id : (java.lang.Integer) defaultValue(fields()[0]);
|
||||||
|
record.firstName = fieldSetFlags()[1] ? this.firstName : (java.lang.CharSequence) defaultValue(fields()[1]);
|
||||||
|
record.lastName = fieldSetFlags()[2] ? this.lastName : (java.lang.CharSequence) defaultValue(fields()[2]);
|
||||||
|
record.department = fieldSetFlags()[3] ? this.department : (java.lang.CharSequence) defaultValue(fields()[3]);
|
||||||
|
record.designation = fieldSetFlags()[4] ? this.designation : (java.lang.CharSequence) defaultValue(fields()[4]);
|
||||||
|
return record;
|
||||||
|
} catch (java.lang.Exception e) {
|
||||||
|
throw new org.apache.avro.AvroRuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final org.apache.avro.io.DatumWriter<Employee>
|
||||||
|
WRITER$ = (org.apache.avro.io.DatumWriter<Employee>)MODEL$.createDatumWriter(SCHEMA$);
|
||||||
|
|
||||||
|
@Override public void writeExternal(java.io.ObjectOutput out)
|
||||||
|
throws java.io.IOException {
|
||||||
|
WRITER$.write(this, SpecificData.getEncoder(out));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final org.apache.avro.io.DatumReader<Employee>
|
||||||
|
READER$ = (org.apache.avro.io.DatumReader<Employee>)MODEL$.createDatumReader(SCHEMA$);
|
||||||
|
|
||||||
|
@Override public void readExternal(java.io.ObjectInput in)
|
||||||
|
throws java.io.IOException {
|
||||||
|
READER$.read(this, SpecificData.getDecoder(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,307 @@
|
||||||
|
/**
|
||||||
|
* Autogenerated by Avro
|
||||||
|
*
|
||||||
|
* DO NOT EDIT DIRECTLY
|
||||||
|
*/
|
||||||
|
package com.baeldung.schema;
|
||||||
|
|
||||||
|
import org.apache.avro.specific.SpecificData;
|
||||||
|
import org.apache.avro.message.BinaryMessageEncoder;
|
||||||
|
import org.apache.avro.message.BinaryMessageDecoder;
|
||||||
|
import org.apache.avro.message.SchemaStore;
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@org.apache.avro.specific.AvroGenerated
|
||||||
|
public class EmployeeKey extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
|
||||||
|
private static final long serialVersionUID = 5288483459411046896L;
|
||||||
|
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"EmployeeKey\",\"namespace\":\"com.baeldung.schema\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"departmentName\",\"type\":\"string\"}]}");
|
||||||
|
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
|
||||||
|
|
||||||
|
private static SpecificData MODEL$ = new SpecificData();
|
||||||
|
|
||||||
|
private static final BinaryMessageEncoder<EmployeeKey> ENCODER =
|
||||||
|
new BinaryMessageEncoder<EmployeeKey>(MODEL$, SCHEMA$);
|
||||||
|
|
||||||
|
private static final BinaryMessageDecoder<EmployeeKey> DECODER =
|
||||||
|
new BinaryMessageDecoder<EmployeeKey>(MODEL$, SCHEMA$);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the BinaryMessageDecoder instance used by this class.
|
||||||
|
*/
|
||||||
|
public static BinaryMessageDecoder<EmployeeKey> getDecoder() {
|
||||||
|
return DECODER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
|
||||||
|
* @param resolver a {@link SchemaStore} used to find schemas by fingerprint
|
||||||
|
*/
|
||||||
|
public static BinaryMessageDecoder<EmployeeKey> createDecoder(SchemaStore resolver) {
|
||||||
|
return new BinaryMessageDecoder<EmployeeKey>(MODEL$, SCHEMA$, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Serializes this EmployeeKey to a ByteBuffer. */
|
||||||
|
public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
|
||||||
|
return ENCODER.encode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Deserializes a EmployeeKey from a ByteBuffer. */
|
||||||
|
public static EmployeeKey fromByteBuffer(
|
||||||
|
java.nio.ByteBuffer b) throws java.io.IOException {
|
||||||
|
return DECODER.decode(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated public int id;
|
||||||
|
@Deprecated public java.lang.CharSequence departmentName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor. Note that this does not initialize fields
|
||||||
|
* to their default values from the schema. If that is desired then
|
||||||
|
* one should use <code>newBuilder()</code>.
|
||||||
|
*/
|
||||||
|
public EmployeeKey() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All-args constructor.
|
||||||
|
* @param id The new value for id
|
||||||
|
* @param departmentName The new value for departmentName
|
||||||
|
*/
|
||||||
|
public EmployeeKey(java.lang.Integer id, java.lang.CharSequence departmentName) {
|
||||||
|
this.id = id;
|
||||||
|
this.departmentName = departmentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
|
||||||
|
// Used by DatumWriter. Applications should not call.
|
||||||
|
public java.lang.Object get(int field$) {
|
||||||
|
switch (field$) {
|
||||||
|
case 0: return id;
|
||||||
|
case 1: return departmentName;
|
||||||
|
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used by DatumReader. Applications should not call.
|
||||||
|
@SuppressWarnings(value="unchecked")
|
||||||
|
public void put(int field$, java.lang.Object value$) {
|
||||||
|
switch (field$) {
|
||||||
|
case 0: id = (java.lang.Integer)value$; break;
|
||||||
|
case 1: departmentName = (java.lang.CharSequence)value$; break;
|
||||||
|
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'id' field.
|
||||||
|
* @return The value of the 'id' field.
|
||||||
|
*/
|
||||||
|
public java.lang.Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'id' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setId(java.lang.Integer value) {
|
||||||
|
this.id = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'departmentName' field.
|
||||||
|
* @return The value of the 'departmentName' field.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDepartmentName() {
|
||||||
|
return departmentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'departmentName' field.
|
||||||
|
* @param value the value to set.
|
||||||
|
*/
|
||||||
|
public void setDepartmentName(java.lang.CharSequence value) {
|
||||||
|
this.departmentName = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new EmployeeKey RecordBuilder.
|
||||||
|
* @return A new EmployeeKey RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.EmployeeKey.Builder newBuilder() {
|
||||||
|
return new com.baeldung.schema.EmployeeKey.Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new EmployeeKey RecordBuilder by copying an existing Builder.
|
||||||
|
* @param other The existing builder to copy.
|
||||||
|
* @return A new EmployeeKey RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.EmployeeKey.Builder newBuilder(com.baeldung.schema.EmployeeKey.Builder other) {
|
||||||
|
return new com.baeldung.schema.EmployeeKey.Builder(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new EmployeeKey RecordBuilder by copying an existing EmployeeKey instance.
|
||||||
|
* @param other The existing instance to copy.
|
||||||
|
* @return A new EmployeeKey RecordBuilder
|
||||||
|
*/
|
||||||
|
public static com.baeldung.schema.EmployeeKey.Builder newBuilder(com.baeldung.schema.EmployeeKey other) {
|
||||||
|
return new com.baeldung.schema.EmployeeKey.Builder(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RecordBuilder for EmployeeKey instances.
|
||||||
|
*/
|
||||||
|
public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<EmployeeKey>
|
||||||
|
implements org.apache.avro.data.RecordBuilder<EmployeeKey> {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private java.lang.CharSequence departmentName;
|
||||||
|
|
||||||
|
/** Creates a new Builder */
|
||||||
|
private Builder() {
|
||||||
|
super(SCHEMA$);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Builder by copying an existing Builder.
|
||||||
|
* @param other The existing Builder to copy.
|
||||||
|
*/
|
||||||
|
private Builder(com.baeldung.schema.EmployeeKey.Builder other) {
|
||||||
|
super(other);
|
||||||
|
if (isValidValue(fields()[0], other.id)) {
|
||||||
|
this.id = data().deepCopy(fields()[0].schema(), other.id);
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[1], other.departmentName)) {
|
||||||
|
this.departmentName = data().deepCopy(fields()[1].schema(), other.departmentName);
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Builder by copying an existing EmployeeKey instance
|
||||||
|
* @param other The existing instance to copy.
|
||||||
|
*/
|
||||||
|
private Builder(com.baeldung.schema.EmployeeKey other) {
|
||||||
|
super(SCHEMA$);
|
||||||
|
if (isValidValue(fields()[0], other.id)) {
|
||||||
|
this.id = data().deepCopy(fields()[0].schema(), other.id);
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
}
|
||||||
|
if (isValidValue(fields()[1], other.departmentName)) {
|
||||||
|
this.departmentName = data().deepCopy(fields()[1].schema(), other.departmentName);
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'id' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'id' field.
|
||||||
|
* @param value The value of 'id'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.EmployeeKey.Builder setId(int value) {
|
||||||
|
validate(fields()[0], value);
|
||||||
|
this.id = value;
|
||||||
|
fieldSetFlags()[0] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'id' field has been set.
|
||||||
|
* @return True if the 'id' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasId() {
|
||||||
|
return fieldSetFlags()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'id' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.EmployeeKey.Builder clearId() {
|
||||||
|
fieldSetFlags()[0] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the 'departmentName' field.
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public java.lang.CharSequence getDepartmentName() {
|
||||||
|
return departmentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the 'departmentName' field.
|
||||||
|
* @param value The value of 'departmentName'.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.EmployeeKey.Builder setDepartmentName(java.lang.CharSequence value) {
|
||||||
|
validate(fields()[1], value);
|
||||||
|
this.departmentName = value;
|
||||||
|
fieldSetFlags()[1] = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the 'departmentName' field has been set.
|
||||||
|
* @return True if the 'departmentName' field has been set, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasDepartmentName() {
|
||||||
|
return fieldSetFlags()[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the value of the 'departmentName' field.
|
||||||
|
* @return This builder.
|
||||||
|
*/
|
||||||
|
public com.baeldung.schema.EmployeeKey.Builder clearDepartmentName() {
|
||||||
|
departmentName = null;
|
||||||
|
fieldSetFlags()[1] = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public EmployeeKey build() {
|
||||||
|
try {
|
||||||
|
EmployeeKey record = new EmployeeKey();
|
||||||
|
record.id = fieldSetFlags()[0] ? this.id : (java.lang.Integer) defaultValue(fields()[0]);
|
||||||
|
record.departmentName = fieldSetFlags()[1] ? this.departmentName : (java.lang.CharSequence) defaultValue(fields()[1]);
|
||||||
|
return record;
|
||||||
|
} catch (java.lang.Exception e) {
|
||||||
|
throw new org.apache.avro.AvroRuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final org.apache.avro.io.DatumWriter<EmployeeKey>
|
||||||
|
WRITER$ = (org.apache.avro.io.DatumWriter<EmployeeKey>)MODEL$.createDatumWriter(SCHEMA$);
|
||||||
|
|
||||||
|
@Override public void writeExternal(java.io.ObjectOutput out)
|
||||||
|
throws java.io.IOException {
|
||||||
|
WRITER$.write(this, SpecificData.getEncoder(out));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final org.apache.avro.io.DatumReader<EmployeeKey>
|
||||||
|
READER$ = (org.apache.avro.io.DatumReader<EmployeeKey>)MODEL$.createDatumReader(SCHEMA$);
|
||||||
|
|
||||||
|
@Override public void readExternal(java.io.ObjectInput in)
|
||||||
|
throws java.io.IOException {
|
||||||
|
READER$.read(this, SpecificData.getDecoder(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue