// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
// Code generated by protocol buffer compiler. Do not edit!
package org.wpilib.math.proto;

import java.io.IOException;
import us.hebi.quickbuf.Descriptors;
import us.hebi.quickbuf.FieldName;
import us.hebi.quickbuf.InvalidProtocolBufferException;
import us.hebi.quickbuf.JsonSink;
import us.hebi.quickbuf.JsonSource;
import us.hebi.quickbuf.MessageFactory;
import us.hebi.quickbuf.ProtoMessage;
import us.hebi.quickbuf.ProtoSink;
import us.hebi.quickbuf.ProtoSource;
import us.hebi.quickbuf.RepeatedDouble;

/**
 * Protobuf type {@code ProtobufQuinticHermiteSpline}
 */
@SuppressWarnings("hiding")
public final class ProtobufQuinticHermiteSpline extends ProtoMessage<ProtobufQuinticHermiteSpline> implements Cloneable {
  private static final long serialVersionUID = 0L;

  /**
   * <code>repeated double x_initial = 1;</code>
   */
  private final RepeatedDouble xInitial = RepeatedDouble.newEmptyInstance();

  /**
   * <code>repeated double x_final = 2;</code>
   */
  private final RepeatedDouble xFinal = RepeatedDouble.newEmptyInstance();

  /**
   * <code>repeated double y_initial = 3;</code>
   */
  private final RepeatedDouble yInitial = RepeatedDouble.newEmptyInstance();

  /**
   * <code>repeated double y_final = 4;</code>
   */
  private final RepeatedDouble yFinal = RepeatedDouble.newEmptyInstance();

  private ProtobufQuinticHermiteSpline() {
  }

  /**
   * @return a new empty instance of {@code ProtobufQuinticHermiteSpline}
   */
  public static ProtobufQuinticHermiteSpline newInstance() {
    return new ProtobufQuinticHermiteSpline();
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   * @return whether the xInitial field is set
   */
  public boolean hasXInitial() {
    return (bitField0_ & 0x00000001) != 0;
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   * @return this
   */
  public ProtobufQuinticHermiteSpline clearXInitial() {
    bitField0_ &= ~0x00000001;
    xInitial.clear();
    return this;
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   *
   * This method returns the internal storage object without modifying any has state.
   * The returned object should not be modified and be treated as read-only.
   *
   * Use {@link #getMutableXInitial()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public RepeatedDouble getXInitial() {
    return xInitial;
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   *
   * This method returns the internal storage object and sets the corresponding
   * has state. The returned object will become part of this message and its
   * contents may be modified as long as the has state is not cleared.
   *
   * @return internal storage object for modifications
   */
  public RepeatedDouble getMutableXInitial() {
    bitField0_ |= 0x00000001;
    return xInitial;
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   * @param value the xInitial to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addXInitial(final double value) {
    bitField0_ |= 0x00000001;
    xInitial.add(value);
    return this;
  }

  /**
   * <code>repeated double x_initial = 1;</code>
   * @param values the xInitial to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addAllXInitial(final double... values) {
    bitField0_ |= 0x00000001;
    xInitial.addAll(values);
    return this;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   * @return whether the xFinal field is set
   */
  public boolean hasXFinal() {
    return (bitField0_ & 0x00000002) != 0;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   * @return this
   */
  public ProtobufQuinticHermiteSpline clearXFinal() {
    bitField0_ &= ~0x00000002;
    xFinal.clear();
    return this;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   *
   * This method returns the internal storage object without modifying any has state.
   * The returned object should not be modified and be treated as read-only.
   *
   * Use {@link #getMutableXFinal()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public RepeatedDouble getXFinal() {
    return xFinal;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   *
   * This method returns the internal storage object and sets the corresponding
   * has state. The returned object will become part of this message and its
   * contents may be modified as long as the has state is not cleared.
   *
   * @return internal storage object for modifications
   */
  public RepeatedDouble getMutableXFinal() {
    bitField0_ |= 0x00000002;
    return xFinal;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   * @param value the xFinal to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addXFinal(final double value) {
    bitField0_ |= 0x00000002;
    xFinal.add(value);
    return this;
  }

  /**
   * <code>repeated double x_final = 2;</code>
   * @param values the xFinal to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addAllXFinal(final double... values) {
    bitField0_ |= 0x00000002;
    xFinal.addAll(values);
    return this;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   * @return whether the yInitial field is set
   */
  public boolean hasYInitial() {
    return (bitField0_ & 0x00000004) != 0;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   * @return this
   */
  public ProtobufQuinticHermiteSpline clearYInitial() {
    bitField0_ &= ~0x00000004;
    yInitial.clear();
    return this;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   *
   * This method returns the internal storage object without modifying any has state.
   * The returned object should not be modified and be treated as read-only.
   *
   * Use {@link #getMutableYInitial()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public RepeatedDouble getYInitial() {
    return yInitial;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   *
   * This method returns the internal storage object and sets the corresponding
   * has state. The returned object will become part of this message and its
   * contents may be modified as long as the has state is not cleared.
   *
   * @return internal storage object for modifications
   */
  public RepeatedDouble getMutableYInitial() {
    bitField0_ |= 0x00000004;
    return yInitial;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   * @param value the yInitial to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addYInitial(final double value) {
    bitField0_ |= 0x00000004;
    yInitial.add(value);
    return this;
  }

  /**
   * <code>repeated double y_initial = 3;</code>
   * @param values the yInitial to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addAllYInitial(final double... values) {
    bitField0_ |= 0x00000004;
    yInitial.addAll(values);
    return this;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   * @return whether the yFinal field is set
   */
  public boolean hasYFinal() {
    return (bitField0_ & 0x00000008) != 0;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   * @return this
   */
  public ProtobufQuinticHermiteSpline clearYFinal() {
    bitField0_ &= ~0x00000008;
    yFinal.clear();
    return this;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   *
   * This method returns the internal storage object without modifying any has state.
   * The returned object should not be modified and be treated as read-only.
   *
   * Use {@link #getMutableYFinal()} if you want to modify it.
   *
   * @return internal storage object for reading
   */
  public RepeatedDouble getYFinal() {
    return yFinal;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   *
   * This method returns the internal storage object and sets the corresponding
   * has state. The returned object will become part of this message and its
   * contents may be modified as long as the has state is not cleared.
   *
   * @return internal storage object for modifications
   */
  public RepeatedDouble getMutableYFinal() {
    bitField0_ |= 0x00000008;
    return yFinal;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   * @param value the yFinal to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addYFinal(final double value) {
    bitField0_ |= 0x00000008;
    yFinal.add(value);
    return this;
  }

  /**
   * <code>repeated double y_final = 4;</code>
   * @param values the yFinal to add
   * @return this
   */
  public ProtobufQuinticHermiteSpline addAllYFinal(final double... values) {
    bitField0_ |= 0x00000008;
    yFinal.addAll(values);
    return this;
  }

  @Override
  public ProtobufQuinticHermiteSpline copyFrom(final ProtobufQuinticHermiteSpline other) {
    cachedSize = other.cachedSize;
    if ((bitField0_ | other.bitField0_) != 0) {
      bitField0_ = other.bitField0_;
      xInitial.copyFrom(other.xInitial);
      xFinal.copyFrom(other.xFinal);
      yInitial.copyFrom(other.yInitial);
      yFinal.copyFrom(other.yFinal);
    }
    return this;
  }

  @Override
  public ProtobufQuinticHermiteSpline mergeFrom(final ProtobufQuinticHermiteSpline other) {
    if (other.isEmpty()) {
      return this;
    }
    cachedSize = -1;
    if (other.hasXInitial()) {
      getMutableXInitial().addAll(other.xInitial);
    }
    if (other.hasXFinal()) {
      getMutableXFinal().addAll(other.xFinal);
    }
    if (other.hasYInitial()) {
      getMutableYInitial().addAll(other.yInitial);
    }
    if (other.hasYFinal()) {
      getMutableYFinal().addAll(other.yFinal);
    }
    return this;
  }

  @Override
  public ProtobufQuinticHermiteSpline clear() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    xInitial.clear();
    xFinal.clear();
    yInitial.clear();
    yFinal.clear();
    return this;
  }

  @Override
  public ProtobufQuinticHermiteSpline clearQuick() {
    if (isEmpty()) {
      return this;
    }
    cachedSize = -1;
    bitField0_ = 0;
    xInitial.clear();
    xFinal.clear();
    yInitial.clear();
    yFinal.clear();
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof ProtobufQuinticHermiteSpline)) {
      return false;
    }
    ProtobufQuinticHermiteSpline other = (ProtobufQuinticHermiteSpline) o;
    return bitField0_ == other.bitField0_
      && (!hasXInitial() || xInitial.equals(other.xInitial))
      && (!hasXFinal() || xFinal.equals(other.xFinal))
      && (!hasYInitial() || yInitial.equals(other.yInitial))
      && (!hasYFinal() || yFinal.equals(other.yFinal));
  }

  @Override
  public void writeTo(final ProtoSink output) throws IOException {
    if ((bitField0_ & 0x00000001) != 0) {
      for (int i = 0; i < xInitial.length(); i++) {
        output.writeRawByte((byte) 9);
        output.writeDoubleNoTag(xInitial.array()[i]);
      }
    }
    if ((bitField0_ & 0x00000002) != 0) {
      for (int i = 0; i < xFinal.length(); i++) {
        output.writeRawByte((byte) 17);
        output.writeDoubleNoTag(xFinal.array()[i]);
      }
    }
    if ((bitField0_ & 0x00000004) != 0) {
      for (int i = 0; i < yInitial.length(); i++) {
        output.writeRawByte((byte) 25);
        output.writeDoubleNoTag(yInitial.array()[i]);
      }
    }
    if ((bitField0_ & 0x00000008) != 0) {
      for (int i = 0; i < yFinal.length(); i++) {
        output.writeRawByte((byte) 33);
        output.writeDoubleNoTag(yFinal.array()[i]);
      }
    }
  }

  @Override
  protected int computeSerializedSize() {
    int size = 0;
    if ((bitField0_ & 0x00000001) != 0) {
      size += (1 + 8) * xInitial.length();
    }
    if ((bitField0_ & 0x00000002) != 0) {
      size += (1 + 8) * xFinal.length();
    }
    if ((bitField0_ & 0x00000004) != 0) {
      size += (1 + 8) * yInitial.length();
    }
    if ((bitField0_ & 0x00000008) != 0) {
      size += (1 + 8) * yFinal.length();
    }
    return size;
  }

  @Override
  @SuppressWarnings("fallthrough")
  public ProtobufQuinticHermiteSpline mergeFrom(final ProtoSource input) throws IOException {
    // Enabled Fall-Through Optimization (QuickBuffers)
    int tag = input.readTag();
    while (true) {
      switch (tag) {
        case 10: {
          // xInitial [packed=true]
          input.readPackedDouble(xInitial);
          bitField0_ |= 0x00000001;
          tag = input.readTag();
          if (tag != 18) {
            break;
          }
        }
        case 18: {
          // xFinal [packed=true]
          input.readPackedDouble(xFinal);
          bitField0_ |= 0x00000002;
          tag = input.readTag();
          if (tag != 26) {
            break;
          }
        }
        case 26: {
          // yInitial [packed=true]
          input.readPackedDouble(yInitial);
          bitField0_ |= 0x00000004;
          tag = input.readTag();
          if (tag != 34) {
            break;
          }
        }
        case 34: {
          // yFinal [packed=true]
          input.readPackedDouble(yFinal);
          bitField0_ |= 0x00000008;
          tag = input.readTag();
          if (tag != 0) {
            break;
          }
        }
        case 0: {
          return this;
        }
        default: {
          if (!input.skipField(tag)) {
            return this;
          }
          tag = input.readTag();
          break;
        }
        case 9: {
          // xInitial [packed=false]
          tag = input.readRepeatedDouble(xInitial, tag);
          bitField0_ |= 0x00000001;
          break;
        }
        case 17: {
          // xFinal [packed=false]
          tag = input.readRepeatedDouble(xFinal, tag);
          bitField0_ |= 0x00000002;
          break;
        }
        case 25: {
          // yInitial [packed=false]
          tag = input.readRepeatedDouble(yInitial, tag);
          bitField0_ |= 0x00000004;
          break;
        }
        case 33: {
          // yFinal [packed=false]
          tag = input.readRepeatedDouble(yFinal, tag);
          bitField0_ |= 0x00000008;
          break;
        }
      }
    }
  }

  @Override
  public void writeTo(final JsonSink output) throws IOException {
    output.beginObject();
    if ((bitField0_ & 0x00000001) != 0) {
      output.writeRepeatedDouble(FieldNames.xInitial, xInitial);
    }
    if ((bitField0_ & 0x00000002) != 0) {
      output.writeRepeatedDouble(FieldNames.xFinal, xFinal);
    }
    if ((bitField0_ & 0x00000004) != 0) {
      output.writeRepeatedDouble(FieldNames.yInitial, yInitial);
    }
    if ((bitField0_ & 0x00000008) != 0) {
      output.writeRepeatedDouble(FieldNames.yFinal, yFinal);
    }
    output.endObject();
  }

  @Override
  public ProtobufQuinticHermiteSpline mergeFrom(final JsonSource input) throws IOException {
    if (!input.beginObject()) {
      return this;
    }
    while (!input.isAtEnd()) {
      switch (input.readFieldHash()) {
        case -1998129236:
        case -2134571395: {
          if (input.isAtField(FieldNames.xInitial)) {
            if (!input.trySkipNullValue()) {
              input.readRepeatedDouble(xInitial);
              bitField0_ |= 0x00000001;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case -791585826:
        case 1943464687: {
          if (input.isAtField(FieldNames.xFinal)) {
            if (!input.trySkipNullValue()) {
              input.readRepeatedDouble(xFinal);
              bitField0_ |= 0x00000002;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case -255318901:
        case 352941438: {
          if (input.isAtField(FieldNames.yInitial)) {
            if (!input.trySkipNullValue()) {
              input.readRepeatedDouble(yInitial);
              bitField0_ |= 0x00000004;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        case -762956675:
        case -1463998928: {
          if (input.isAtField(FieldNames.yFinal)) {
            if (!input.trySkipNullValue()) {
              input.readRepeatedDouble(yFinal);
              bitField0_ |= 0x00000008;
            }
          } else {
            input.skipUnknownField();
          }
          break;
        }
        default: {
          input.skipUnknownField();
          break;
        }
      }
    }
    input.endObject();
    return this;
  }

  @Override
  public ProtobufQuinticHermiteSpline clone() {
    return new ProtobufQuinticHermiteSpline().copyFrom(this);
  }

  @Override
  public boolean isEmpty() {
    return ((bitField0_) == 0);
  }

  public static ProtobufQuinticHermiteSpline parseFrom(final byte[] data) throws
      InvalidProtocolBufferException {
    return ProtoMessage.mergeFrom(new ProtobufQuinticHermiteSpline(), data).checkInitialized();
  }

  public static ProtobufQuinticHermiteSpline parseFrom(final ProtoSource input) throws IOException {
    return ProtoMessage.mergeFrom(new ProtobufQuinticHermiteSpline(), input).checkInitialized();
  }

  public static ProtobufQuinticHermiteSpline parseFrom(final JsonSource input) throws IOException {
    return ProtoMessage.mergeFrom(new ProtobufQuinticHermiteSpline(), input).checkInitialized();
  }

  /**
   * @return factory for creating ProtobufQuinticHermiteSpline messages
   */
  public static MessageFactory<ProtobufQuinticHermiteSpline> getFactory() {
    return ProtobufQuinticHermiteSplineFactory.INSTANCE;
  }

  /**
   * @return this type's descriptor.
   */
  public static Descriptors.Descriptor getDescriptor() {
    return ProtobufSplineDescriptor.wpi_proto_ProtobufQuinticHermiteSpline_descriptor;
  }

  private enum ProtobufQuinticHermiteSplineFactory implements MessageFactory<ProtobufQuinticHermiteSpline> {
    INSTANCE;

    @Override
    public ProtobufQuinticHermiteSpline create() {
      return ProtobufQuinticHermiteSpline.newInstance();
    }
  }

  /**
   * Contains name constants used for serializing JSON
   */
  static class FieldNames {
    static final FieldName xInitial = FieldName.forField("xInitial", "x_initial");

    static final FieldName xFinal = FieldName.forField("xFinal", "x_final");

    static final FieldName yInitial = FieldName.forField("yInitial", "y_initial");

    static final FieldName yFinal = FieldName.forField("yFinal", "y_final");
  }
}
