package org.apache.avro.specific;
import java.io.Externalizable;
import java.io.ObjectOutput;
import java.io.ObjectInput;
import java.io.IOException;
import org.apache.avro.Conversion;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.ResolvingDecoder;
import org.apache.avro.io.Encoder;
import org.apache.avro.message.MessageDecoder;
import org.apache.avro.message.MessageEncoder;
public abstract class SpecificRecordBase
implements SpecificRecord, Comparable<SpecificRecord>, GenericRecord, Externalizable {
@Override
public abstract Schema getSchema();
@Override
public abstract Object get(int field);
@Override
public abstract void put(int field, Object value);
public SpecificData getSpecificData() {
return SpecificData.get();
}
public Conversion<?> getConversion(int field) {
return null;
}
@Override
public void put(String fieldName, Object value) {
put(getSchema().getField(fieldName).pos(), value);
}
@Override
public Object get(String fieldName) {
return get(getSchema().getField(fieldName).pos());
}
public Conversion<?> getConversion(String fieldName) {
return getConversion(getSchema().getField(fieldName).pos());
}
@Override
public boolean equals(Object that) {
if (that == this)
return true;
if (!(that instanceof SpecificRecord))
return false;
if (this.getClass() != that.getClass())
return false;
return getSpecificData().compare(this, that, this.getSchema(), true) == 0;
}
@Override
public int hashCode() {
return getSpecificData().hashCode(this, this.getSchema());
}
@Override
public int compareTo(SpecificRecord that) {
return getSpecificData().compare(this, that, this.getSchema());
}
@Override
public String toString() {
return getSpecificData().toString(this);
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
new SpecificDatumWriter(getSchema()).write(this, SpecificData.getEncoder(out));
}
@Override
public void readExternal(ObjectInput in) throws IOException {
new SpecificDatumReader(getSchema()).read(this, SpecificData.getDecoder(in));
}
protected boolean hasCustomCoders() {
return false;
}
public void customEncode(Encoder out) throws IOException {
throw new UnsupportedOperationException();
}
public void customDecode(ResolvingDecoder in) throws IOException {
throw new UnsupportedOperationException();
}
}