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> implements Comparable<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;
34 
35   static {
36     Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
tmpMetaDataMap.put(V1, new FieldMetaData(R, TFieldRequirementType.DEFAULT, new StructMetaData(TType.STRUCT, Val.class)))37     tmpMetaDataMap.put(V1, new FieldMetaData("v1", TFieldRequirementType.DEFAULT,
38         new StructMetaData(TType.STRUCT, Val.class)));
tmpMetaDataMap.put(V2, new FieldMetaData(R, TFieldRequirementType.DEFAULT, new StructMetaData(TType.STRUCT, Val.class)))39     tmpMetaDataMap.put(V2, new FieldMetaData("v2", TFieldRequirementType.DEFAULT,
40         new StructMetaData(TType.STRUCT, Val.class)));
41     metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
42   }
43 
ValUnion()44   public ValUnion() {
45     super();
46   }
47 
ValUnion(int setField, Object __value)48   public ValUnion(int setField, Object __value) {
49     super(setField, __value);
50   }
51 
ValUnion(ValUnion other)52   public ValUnion(ValUnion other) {
53     super(other);
54   }
55 
deepCopy()56   public ValUnion deepCopy() {
57     return new ValUnion(this);
58   }
59 
v1(Val __value)60   public static ValUnion v1(Val __value) {
61     ValUnion x = new ValUnion();
62     x.setV1(__value);
63     return x;
64   }
65 
v2(Val __value)66   public static ValUnion v2(Val __value) {
67     ValUnion x = new ValUnion();
68     x.setV2(__value);
69     return x;
70   }
71 
72 
73   @Override
checkType(short setField, Object __value)74   protected void checkType(short setField, Object __value) throws ClassCastException {
75     switch (setField) {
76       case V1:
77         if (__value instanceof Val) {
78           break;
79         }
80         throw new ClassCastException("Was expecting value of type Val for field 'v1', but got " + __value.getClass().getSimpleName());
81       case V2:
82         if (__value instanceof Val) {
83           break;
84         }
85         throw new ClassCastException("Was expecting value of type Val for field 'v2', but got " + __value.getClass().getSimpleName());
86       default:
87         throw new IllegalArgumentException("Unknown field id " + setField);
88     }
89   }
90 
91   @Override
read(TProtocol iprot)92   public void read(TProtocol iprot) throws TException {
93     setField_ = 0;
94     value_ = null;
95     iprot.readStructBegin(metaDataMap);
96     TField __field = iprot.readFieldBegin();
97     if (__field.type != TType.STOP)
98     {
99       value_ = readValue(iprot, __field);
100       if (value_ != null)
101       {
102         switch (__field.id) {
103           case V1:
104             if (__field.type == V1_FIELD_DESC.type) {
105               setField_ = __field.id;
106             }
107             break;
108           case V2:
109             if (__field.type == V2_FIELD_DESC.type) {
110               setField_ = __field.id;
111             }
112             break;
113         }
114       }
115       iprot.readFieldEnd();
116       TField __stopField = iprot.readFieldBegin();
117       if (__stopField.type != TType.STOP) {
118         throw new TProtocolException(TProtocolException.INVALID_DATA, "Union 'ValUnion' is missing a STOP byte");
119       }
120     }
121     iprot.readStructEnd();
122   }
123 
124   @Override
readValue(TProtocol iprot, TField __field)125   protected Object readValue(TProtocol iprot, TField __field) throws TException {
126     switch (__field.id) {
127       case V1:
128         if (__field.type == V1_FIELD_DESC.type) {
129           Val v1;
130           v1 = new Val();
131           v1.read(iprot);
132           return v1;
133         }
134         break;
135       case V2:
136         if (__field.type == V2_FIELD_DESC.type) {
137           Val v2;
138           v2 = new Val();
139           v2.read(iprot);
140           return v2;
141         }
142         break;
143     }
144     TProtocolUtil.skip(iprot, __field.type);
145     return null;
146   }
147 
148   @Override
writeValue(TProtocol oprot, short setField, Object __value)149   protected void writeValue(TProtocol oprot, short setField, Object __value) throws TException {
150     switch (setField) {
151       case V1:
152         Val v1 = (Val)getFieldValue();
153         v1.write(oprot);
154         return;
155       case V2:
156         Val v2 = (Val)getFieldValue();
157         v2.write(oprot);
158         return;
159       default:
160         throw new IllegalStateException("Cannot write union with unknown field " + setField);
161     }
162   }
163 
164   @Override
getFieldDesc(int setField)165   protected TField getFieldDesc(int setField) {
166     switch (setField) {
167       case V1:
168         return V1_FIELD_DESC;
169       case V2:
170         return V2_FIELD_DESC;
171       default:
172         throw new IllegalArgumentException("Unknown field id " + setField);
173     }
174   }
175 
176   @Override
getStructDesc()177   protected TStruct getStructDesc() {
178     return STRUCT_DESC;
179   }
180 
181   @Override
getMetaDataMap()182   protected Map<Integer, FieldMetaData> getMetaDataMap() { return metaDataMap; }
183 
__getValue(int expectedFieldId)184   private Object __getValue(int expectedFieldId) {
185     if (getSetField() == expectedFieldId) {
186       return getFieldValue();
187     } else {
188       throw new RuntimeException("Cannot get field '" + getFieldDesc(expectedFieldId).name + "' because union is currently set to " + getFieldDesc(getSetField()).name);
189     }
190   }
191 
__setValue(int fieldId, Object __value)192   private void __setValue(int fieldId, Object __value) {
193     if (__value == null) throw new NullPointerException();
194     setField_ = fieldId;
195     value_ = __value;
196   }
197 
getV1()198   public Val getV1() {
199     return (Val) __getValue(V1);
200   }
201 
setV1(Val __value)202   public void setV1(Val __value) {
203     __setValue(V1, __value);
204   }
205 
getV2()206   public Val getV2() {
207     return (Val) __getValue(V2);
208   }
209 
setV2(Val __value)210   public void setV2(Val __value) {
211     __setValue(V2, __value);
212   }
213 
equals(Object other)214   public boolean equals(Object other) {
215     if (other instanceof ValUnion) {
216       return equals((ValUnion)other);
217     } else {
218       return false;
219     }
220   }
221 
equals(ValUnion other)222   public boolean equals(ValUnion other) {
223     return equalsNobinaryImpl(other);
224   }
225 
226   @Override
compareTo(ValUnion other)227   public int compareTo(ValUnion other) {
228     return compareToImpl(other);
229   }
230 
231 
232   @Override
hashCode()233   public int hashCode() {
234     return Arrays.deepHashCode(new Object[] {getSetField(), getFieldValue()});
235   }
236 
237 }
238