1 /** 2 * Autogenerated by Thrift 3 * 4 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 * @generated 6 */ 7 import java.util.List; 8 import java.util.ArrayList; 9 import java.util.Map; 10 import java.util.HashMap; 11 import java.util.Set; 12 import java.util.HashSet; 13 import java.util.Collections; 14 import java.util.BitSet; 15 import java.util.Arrays; 16 import com.facebook.thrift.*; 17 import com.facebook.thrift.annotations.*; 18 import com.facebook.thrift.async.*; 19 import com.facebook.thrift.meta_data.*; 20 import com.facebook.thrift.server.*; 21 import com.facebook.thrift.transport.*; 22 import com.facebook.thrift.protocol.*; 23 24 @SuppressWarnings({ "unused", "serial", "unchecked" }) 25 public class ValUnion extends TUnion<ValUnion> { 26 private static final TStruct STRUCT_DESC = new TStruct("ValUnion"); 27 private static final TField V1_FIELD_DESC = new TField("v1", TType.STRUCT, (short)1); 28 private static final TField V2_FIELD_DESC = new TField("v2", TType.STRUCT, (short)2); 29 30 public static final int V1 = 1; 31 public static final int V2 = 2; 32 33 public static final Map<Integer, FieldMetaData> metaDataMap = new HashMap<>(); 34 ValUnion()35 public ValUnion() { 36 super(); 37 } 38 ValUnion(int setField, Object __value)39 public ValUnion(int setField, Object __value) { 40 super(setField, __value); 41 } 42 ValUnion(ValUnion other)43 public ValUnion(ValUnion other) { 44 super(other); 45 } 46 deepCopy()47 public ValUnion deepCopy() { 48 return new ValUnion(this); 49 } 50 v1(Val __value)51 public static ValUnion v1(Val __value) { 52 ValUnion x = new ValUnion(); 53 x.setV1(__value); 54 return x; 55 } 56 v2(Val __value)57 public static ValUnion v2(Val __value) { 58 ValUnion x = new ValUnion(); 59 x.setV2(__value); 60 return x; 61 } 62 63 64 @Override readValue(TProtocol iprot, TField __field)65 protected Object readValue(TProtocol iprot, TField __field) throws TException { 66 switch (__field.id) { 67 case V1: 68 if (__field.type == V1_FIELD_DESC.type) { 69 Val v1; 70 v1 = Val.deserialize(iprot); 71 return v1; 72 } 73 break; 74 case V2: 75 if (__field.type == V2_FIELD_DESC.type) { 76 Val v2; 77 v2 = Val.deserialize(iprot); 78 return v2; 79 } 80 break; 81 } 82 TProtocolUtil.skip(iprot, __field.type); 83 return null; 84 } 85 86 @Override writeValue(TProtocol oprot, short setField, Object __value)87 protected void writeValue(TProtocol oprot, short setField, Object __value) throws TException { 88 switch (setField) { 89 case V1: 90 Val v1 = (Val)getFieldValue(); 91 v1.write(oprot); 92 return; 93 case V2: 94 Val v2 = (Val)getFieldValue(); 95 v2.write(oprot); 96 return; 97 default: 98 throw new IllegalStateException("Cannot write union with unknown field " + setField); 99 } 100 } 101 102 @Override getFieldDesc(int setField)103 protected TField getFieldDesc(int setField) { 104 switch (setField) { 105 case V1: 106 return V1_FIELD_DESC; 107 case V2: 108 return V2_FIELD_DESC; 109 default: 110 throw new IllegalArgumentException("Unknown field id " + setField); 111 } 112 } 113 114 @Override getStructDesc()115 protected TStruct getStructDesc() { 116 return STRUCT_DESC; 117 } 118 119 @Override getMetaDataMap()120 protected Map<Integer, FieldMetaData> getMetaDataMap() { return metaDataMap; } 121 __getValue(int expectedFieldId)122 private Object __getValue(int expectedFieldId) { 123 if (getSetField() == expectedFieldId) { 124 return getFieldValue(); 125 } else { 126 throw new RuntimeException("Cannot get field '" + getFieldDesc(expectedFieldId).name + "' because union is currently set to " + getFieldDesc(getSetField()).name); 127 } 128 } 129 __setValue(int fieldId, Object __value)130 private void __setValue(int fieldId, Object __value) { 131 if (__value == null) throw new NullPointerException(); 132 setField_ = fieldId; 133 value_ = __value; 134 } 135 getV1()136 public Val getV1() { 137 return (Val) __getValue(V1); 138 } 139 setV1(Val __value)140 public void setV1(Val __value) { 141 __setValue(V1, __value); 142 } 143 getV2()144 public Val getV2() { 145 return (Val) __getValue(V2); 146 } 147 setV2(Val __value)148 public void setV2(Val __value) { 149 __setValue(V2, __value); 150 } 151 equals(Object other)152 public boolean equals(Object other) { 153 if (other instanceof ValUnion) { 154 return equals((ValUnion)other); 155 } else { 156 return false; 157 } 158 } 159 equals(ValUnion other)160 public boolean equals(ValUnion other) { 161 return equalsNobinaryImpl(other); 162 } 163 164 165 @Override hashCode()166 public int hashCode() { 167 return Arrays.deepHashCode(new Object[] {getSetField(), getFieldValue()}); 168 } 169 170 } 171