/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.BitSet;
import java.util.Arrays;
import com.facebook.thrift.*;
import com.facebook.thrift.annotations.*;
import com.facebook.thrift.async.*;
import com.facebook.thrift.meta_data.*;
import com.facebook.thrift.server.*;
import com.facebook.thrift.transport.*;
import com.facebook.thrift.protocol.*;

@SuppressWarnings({ "unused", "serial", "unchecked" })
public class VirtualComplexUnion extends TUnion<VirtualComplexUnion> implements Comparable<VirtualComplexUnion> {
  private static final TStruct STRUCT_DESC = new TStruct("VirtualComplexUnion");
  private static final TField THING_ONE_FIELD_DESC = new TField("thingOne", TType.STRING, (short)1);
  private static final TField THING_TWO_FIELD_DESC = new TField("thingTwo", TType.STRING, (short)2);

  public static final int THINGONE = 1;
  public static final int THINGTWO = 2;

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(THINGONE, new FieldMetaData("thingOne", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(THINGTWO, new FieldMetaData("thingTwo", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

  public VirtualComplexUnion() {
    super();
  }

  public VirtualComplexUnion(int setField, Object __value) {
    super(setField, __value);
  }

  public VirtualComplexUnion(VirtualComplexUnion other) {
    super(other);
  }

  public VirtualComplexUnion deepCopy() {
    return new VirtualComplexUnion(this);
  }

  public static VirtualComplexUnion thingOne(String __value) {
    VirtualComplexUnion x = new VirtualComplexUnion();
    x.setThingOne(__value);
    return x;
  }

  public static VirtualComplexUnion thingTwo(String __value) {
    VirtualComplexUnion x = new VirtualComplexUnion();
    x.setThingTwo(__value);
    return x;
  }


  @Override
  protected void checkType(short setField, Object __value) throws ClassCastException {
    switch (setField) {
      case THINGONE:
        if (__value instanceof String) {
          break;
        }
        throw new ClassCastException("Was expecting value of type String for field 'thingOne', but got " + __value.getClass().getSimpleName());
      case THINGTWO:
        if (__value instanceof String) {
          break;
        }
        throw new ClassCastException("Was expecting value of type String for field 'thingTwo', but got " + __value.getClass().getSimpleName());
      default:
        throw new IllegalArgumentException("Unknown field id " + setField);
    }
  }

  @Override
  public void read(TProtocol iprot) throws TException {
    setField_ = 0;
    value_ = null;
    iprot.readStructBegin(metaDataMap);
    TField __field = iprot.readFieldBegin();
    if (__field.type != TType.STOP)
    {
      value_ = readValue(iprot, __field);
      if (value_ != null)
      {
        switch (__field.id) {
          case THINGONE:
            if (__field.type == THING_ONE_FIELD_DESC.type) {
              setField_ = __field.id;
            }
            break;
          case THINGTWO:
            if (__field.type == THING_TWO_FIELD_DESC.type) {
              setField_ = __field.id;
            }
            break;
        }
      }
      iprot.readFieldEnd();
      TField __stopField = iprot.readFieldBegin();
      if (__stopField.type != TType.STOP) {
        throw new TProtocolException(TProtocolException.INVALID_DATA, "Union 'VirtualComplexUnion' is missing a STOP byte");
      }
    }
    iprot.readStructEnd();
  }

  @Override
  protected Object readValue(TProtocol iprot, TField __field) throws TException {
    switch (__field.id) {
      case THINGONE:
        if (__field.type == THING_ONE_FIELD_DESC.type) {
          String thingOne;
          thingOne = iprot.readString();
          return thingOne;
        }
        break;
      case THINGTWO:
        if (__field.type == THING_TWO_FIELD_DESC.type) {
          String thingTwo;
          thingTwo = iprot.readString();
          return thingTwo;
        }
        break;
    }
    TProtocolUtil.skip(iprot, __field.type);
    return null;
  }

  @Override
  protected void writeValue(TProtocol oprot, short setField, Object __value) throws TException {
    switch (setField) {
      case THINGONE:
        String thingOne = (String)getFieldValue();
        oprot.writeString(thingOne);
        return;
      case THINGTWO:
        String thingTwo = (String)getFieldValue();
        oprot.writeString(thingTwo);
        return;
      default:
        throw new IllegalStateException("Cannot write union with unknown field " + setField);
    }
  }

  @Override
  protected TField getFieldDesc(int setField) {
    switch (setField) {
      case THINGONE:
        return THING_ONE_FIELD_DESC;
      case THINGTWO:
        return THING_TWO_FIELD_DESC;
      default:
        throw new IllegalArgumentException("Unknown field id " + setField);
    }
  }

  @Override
  protected TStruct getStructDesc() {
    return STRUCT_DESC;
  }

  @Override
  protected Map<Integer, FieldMetaData> getMetaDataMap() { return metaDataMap; }

  private Object __getValue(int expectedFieldId) {
    if (getSetField() == expectedFieldId) {
      return getFieldValue();
    } else {
      throw new RuntimeException("Cannot get field '" + getFieldDesc(expectedFieldId).name + "' because union is currently set to " + getFieldDesc(getSetField()).name);
    }
  }

  private void __setValue(int fieldId, Object __value) {
    if (__value == null) throw new NullPointerException();
    setField_ = fieldId;
    value_ = __value;
  }

  public String getThingOne() {
    return (String) __getValue(THINGONE);
  }

  public void setThingOne(String __value) {
    __setValue(THINGONE, __value);
  }

  public String getThingTwo() {
    return (String) __getValue(THINGTWO);
  }

  public void setThingTwo(String __value) {
    __setValue(THINGTWO, __value);
  }

  public boolean equals(Object other) {
    if (other instanceof VirtualComplexUnion) {
      return equals((VirtualComplexUnion)other);
    } else {
      return false;
    }
  }

  public boolean equals(VirtualComplexUnion other) {
    return equalsNobinaryImpl(other);
  }

  @Override
  public int compareTo(VirtualComplexUnion other) {
    return compareToImpl(other);
  }


  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {getSetField(), getFieldValue()});
  }

}
