/**
 * Autogenerated by Avro
 *
 * DO NOT EDIT DIRECTLY
 */
package ksql;

import org.apache.avro.generic.GenericArray;
import org.apache.avro.specific.SpecificData;
import org.apache.avro.util.Utf8;
import org.apache.avro.message.BinaryMessageEncoder;
import org.apache.avro.message.BinaryMessageDecoder;
import org.apache.avro.message.SchemaStore;

@org.apache.avro.specific.AvroGenerated
public class pageviews extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
  private static final long serialVersionUID = -1536268170520598053L;


  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"pageviews\",\"namespace\":\"ksql\",\"fields\":[{\"name\":\"viewtime\",\"type\":\"long\"},{\"name\":\"userid\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}},{\"name\":\"pageid\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}],\"connect.name\":\"ksql.pageviews\"}");
  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }

  private static final SpecificData MODEL$ = new SpecificData();

  private static final BinaryMessageEncoder<pageviews> ENCODER =
      new BinaryMessageEncoder<>(MODEL$, SCHEMA$);

  private static final BinaryMessageDecoder<pageviews> DECODER =
      new BinaryMessageDecoder<>(MODEL$, SCHEMA$);

  /**
   * Return the BinaryMessageEncoder instance used by this class.
   * @return the message encoder used by this class
   */
  public static BinaryMessageEncoder<pageviews> getEncoder() {
    return ENCODER;
  }

  /**
   * Return the BinaryMessageDecoder instance used by this class.
   * @return the message decoder used by this class
   */
  public static BinaryMessageDecoder<pageviews> 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
   * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
   */
  public static BinaryMessageDecoder<pageviews> createDecoder(SchemaStore resolver) {
    return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver);
  }

  /**
   * Serializes this pageviews to a ByteBuffer.
   * @return a buffer holding the serialized data for this instance
   * @throws java.io.IOException if this instance could not be serialized
   */
  public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
    return ENCODER.encode(this);
  }

  /**
   * Deserializes a pageviews from a ByteBuffer.
   * @param b a byte buffer holding serialized data for an instance of this class
   * @return a pageviews instance decoded from the given buffer
   * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
   */
  public static pageviews fromByteBuffer(
      java.nio.ByteBuffer b) throws java.io.IOException {
    return DECODER.decode(b);
  }

  private long viewtime;
  private java.lang.String userid;
  private java.lang.String pageid;

  /**
   * 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 pageviews() {}

  /**
   * All-args constructor.
   * @param viewtime The new value for viewtime
   * @param userid The new value for userid
   * @param pageid The new value for pageid
   */
  public pageviews(java.lang.Long viewtime, java.lang.String userid, java.lang.String pageid) {
    this.viewtime = viewtime;
    this.userid = userid;
    this.pageid = pageid;
  }

  @Override
  public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }

  @Override
  public org.apache.avro.Schema getSchema() { return SCHEMA$; }

  // Used by DatumWriter.  Applications should not call.
  @Override
  public java.lang.Object get(int field$) {
    switch (field$) {
    case 0: return viewtime;
    case 1: return userid;
    case 2: return pageid;
    default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
    }
  }

  // Used by DatumReader.  Applications should not call.
  @Override
  @SuppressWarnings(value="unchecked")
  public void put(int field$, java.lang.Object value$) {
    switch (field$) {
    case 0: viewtime = (java.lang.Long)value$; break;
    case 1: userid = value$ != null ? value$.toString() : null; break;
    case 2: pageid = value$ != null ? value$.toString() : null; break;
    default: throw new IndexOutOfBoundsException("Invalid index: " + field$);
    }
  }

  /**
   * Gets the value of the 'viewtime' field.
   * @return The value of the 'viewtime' field.
   */
  public long getViewtime() {
    return viewtime;
  }


  /**
   * Sets the value of the 'viewtime' field.
   * @param value the value to set.
   */
  public void setViewtime(long value) {
    this.viewtime = value;
  }

  /**
   * Gets the value of the 'userid' field.
   * @return The value of the 'userid' field.
   */
  public java.lang.String getUserid() {
    return userid;
  }


  /**
   * Sets the value of the 'userid' field.
   * @param value the value to set.
   */
  public void setUserid(java.lang.String value) {
    this.userid = value;
  }

  /**
   * Gets the value of the 'pageid' field.
   * @return The value of the 'pageid' field.
   */
  public java.lang.String getPageid() {
    return pageid;
  }


  /**
   * Sets the value of the 'pageid' field.
   * @param value the value to set.
   */
  public void setPageid(java.lang.String value) {
    this.pageid = value;
  }

  /**
   * Creates a new pageviews RecordBuilder.
   * @return A new pageviews RecordBuilder
   */
  public static ksql.pageviews.Builder newBuilder() {
    return new ksql.pageviews.Builder();
  }

  /**
   * Creates a new pageviews RecordBuilder by copying an existing Builder.
   * @param other The existing builder to copy.
   * @return A new pageviews RecordBuilder
   */
  public static ksql.pageviews.Builder newBuilder(ksql.pageviews.Builder other) {
    if (other == null) {
      return new ksql.pageviews.Builder();
    } else {
      return new ksql.pageviews.Builder(other);
    }
  }

  /**
   * Creates a new pageviews RecordBuilder by copying an existing pageviews instance.
   * @param other The existing instance to copy.
   * @return A new pageviews RecordBuilder
   */
  public static ksql.pageviews.Builder newBuilder(ksql.pageviews other) {
    if (other == null) {
      return new ksql.pageviews.Builder();
    } else {
      return new ksql.pageviews.Builder(other);
    }
  }

  /**
   * RecordBuilder for pageviews instances.
   */
  @org.apache.avro.specific.AvroGenerated
  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<pageviews>
    implements org.apache.avro.data.RecordBuilder<pageviews> {

    private long viewtime;
    private java.lang.String userid;
    private java.lang.String pageid;

    /** Creates a new Builder */
    private Builder() {
      super(SCHEMA$, MODEL$);
    }

    /**
     * Creates a Builder by copying an existing Builder.
     * @param other The existing Builder to copy.
     */
    private Builder(ksql.pageviews.Builder other) {
      super(other);
      if (isValidValue(fields()[0], other.viewtime)) {
        this.viewtime = data().deepCopy(fields()[0].schema(), other.viewtime);
        fieldSetFlags()[0] = other.fieldSetFlags()[0];
      }
      if (isValidValue(fields()[1], other.userid)) {
        this.userid = data().deepCopy(fields()[1].schema(), other.userid);
        fieldSetFlags()[1] = other.fieldSetFlags()[1];
      }
      if (isValidValue(fields()[2], other.pageid)) {
        this.pageid = data().deepCopy(fields()[2].schema(), other.pageid);
        fieldSetFlags()[2] = other.fieldSetFlags()[2];
      }
    }

    /**
     * Creates a Builder by copying an existing pageviews instance
     * @param other The existing instance to copy.
     */
    private Builder(ksql.pageviews other) {
      super(SCHEMA$, MODEL$);
      if (isValidValue(fields()[0], other.viewtime)) {
        this.viewtime = data().deepCopy(fields()[0].schema(), other.viewtime);
        fieldSetFlags()[0] = true;
      }
      if (isValidValue(fields()[1], other.userid)) {
        this.userid = data().deepCopy(fields()[1].schema(), other.userid);
        fieldSetFlags()[1] = true;
      }
      if (isValidValue(fields()[2], other.pageid)) {
        this.pageid = data().deepCopy(fields()[2].schema(), other.pageid);
        fieldSetFlags()[2] = true;
      }
    }

    /**
      * Gets the value of the 'viewtime' field.
      * @return The value.
      */
    public long getViewtime() {
      return viewtime;
    }


    /**
      * Sets the value of the 'viewtime' field.
      * @param value The value of 'viewtime'.
      * @return This builder.
      */
    public ksql.pageviews.Builder setViewtime(long value) {
      validate(fields()[0], value);
      this.viewtime = value;
      fieldSetFlags()[0] = true;
      return this;
    }

    /**
      * Checks whether the 'viewtime' field has been set.
      * @return True if the 'viewtime' field has been set, false otherwise.
      */
    public boolean hasViewtime() {
      return fieldSetFlags()[0];
    }


    /**
      * Clears the value of the 'viewtime' field.
      * @return This builder.
      */
    public ksql.pageviews.Builder clearViewtime() {
      fieldSetFlags()[0] = false;
      return this;
    }

    /**
      * Gets the value of the 'userid' field.
      * @return The value.
      */
    public java.lang.String getUserid() {
      return userid;
    }


    /**
      * Sets the value of the 'userid' field.
      * @param value The value of 'userid'.
      * @return This builder.
      */
    public ksql.pageviews.Builder setUserid(java.lang.String value) {
      validate(fields()[1], value);
      this.userid = value;
      fieldSetFlags()[1] = true;
      return this;
    }

    /**
      * Checks whether the 'userid' field has been set.
      * @return True if the 'userid' field has been set, false otherwise.
      */
    public boolean hasUserid() {
      return fieldSetFlags()[1];
    }


    /**
      * Clears the value of the 'userid' field.
      * @return This builder.
      */
    public ksql.pageviews.Builder clearUserid() {
      userid = null;
      fieldSetFlags()[1] = false;
      return this;
    }

    /**
      * Gets the value of the 'pageid' field.
      * @return The value.
      */
    public java.lang.String getPageid() {
      return pageid;
    }


    /**
      * Sets the value of the 'pageid' field.
      * @param value The value of 'pageid'.
      * @return This builder.
      */
    public ksql.pageviews.Builder setPageid(java.lang.String value) {
      validate(fields()[2], value);
      this.pageid = value;
      fieldSetFlags()[2] = true;
      return this;
    }

    /**
      * Checks whether the 'pageid' field has been set.
      * @return True if the 'pageid' field has been set, false otherwise.
      */
    public boolean hasPageid() {
      return fieldSetFlags()[2];
    }


    /**
      * Clears the value of the 'pageid' field.
      * @return This builder.
      */
    public ksql.pageviews.Builder clearPageid() {
      pageid = null;
      fieldSetFlags()[2] = false;
      return this;
    }

    @Override
    @SuppressWarnings("unchecked")
    public pageviews build() {
      try {
        pageviews record = new pageviews();
        record.viewtime = fieldSetFlags()[0] ? this.viewtime : (java.lang.Long) defaultValue(fields()[0]);
        record.userid = fieldSetFlags()[1] ? this.userid : (java.lang.String) defaultValue(fields()[1]);
        record.pageid = fieldSetFlags()[2] ? this.pageid : (java.lang.String) defaultValue(fields()[2]);
        return record;
      } catch (org.apache.avro.AvroMissingFieldException e) {
        throw e;
      } catch (java.lang.Exception e) {
        throw new org.apache.avro.AvroRuntimeException(e);
      }
    }
  }

  @SuppressWarnings("unchecked")
  private static final org.apache.avro.io.DatumWriter<pageviews>
    WRITER$ = (org.apache.avro.io.DatumWriter<pageviews>)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<pageviews>
    READER$ = (org.apache.avro.io.DatumReader<pageviews>)MODEL$.createDatumReader(SCHEMA$);

  @Override public void readExternal(java.io.ObjectInput in)
    throws java.io.IOException {
    READER$.read(this, SpecificData.getDecoder(in));
  }

  @Override protected boolean hasCustomCoders() { return true; }

  @Override public void customEncode(org.apache.avro.io.Encoder out)
    throws java.io.IOException
  {
    out.writeLong(this.viewtime);

    out.writeString(this.userid);

    out.writeString(this.pageid);

  }

  @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
    throws java.io.IOException
  {
    org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
    if (fieldOrder == null) {
      this.viewtime = in.readLong();

      this.userid = in.readString();

      this.pageid = in.readString();

    } else {
      for (int i = 0; i < 3; i++) {
        switch (fieldOrder[i].pos()) {
        case 0:
          this.viewtime = in.readLong();
          break;

        case 1:
          this.userid = in.readString();
          break;

        case 2:
          this.pageid = in.readString();
          break;

        default:
          throw new java.io.IOException("Corrupt ResolvingDecoder.");
        }
      }
    }
  }
}










