@SuppressWarnings({"unchecked", "rawtypes"}) private static TUnion<?, ?> createUnion( Class<?> unionType, TFieldIdEnum setField, Object fieldValue) throws IllegalAccessException, InstantiationException { TUnion union = (TUnion) unionType.newInstance(); union.setFieldValue(setField, fieldValue); return union; }
private static void assertFullyPopulated(String name, Object object, Set<Field> ignoredFields) { if (object instanceof Collection) { Object[] values = ((Collection<?>) object).toArray(); assertFalse("Collection is empty: " + name, values.length == 0); for (int i = 0; i < values.length; i++) { assertFullyPopulated(name + "[" + i + "]", values[i], ignoredFields); } } else if (object instanceof Map) { Map<?, ?> map = (Map<?, ?>) object; assertFalse("Map is empty: " + name, map.isEmpty()); for (Map.Entry<?, ?> entry : map.entrySet()) { assertFullyPopulated(name + " key", entry.getKey(), ignoredFields); assertFullyPopulated(name + "[" + entry.getKey() + "]", entry.getValue(), ignoredFields); } } else if (object instanceof TUnion) { TUnion<?, ?> union = (TUnion<?, ?>) object; assertFullyPopulated( name + "." + union.getSetField().getFieldName(), union.getFieldValue(), ignoredFields); } else if (!(object instanceof String) && !(object instanceof Enum)) { for (Field field : object.getClass().getDeclaredFields()) { if (!Modifier.isStatic(field.getModifiers())) { validateField(name, object, field, ignoredFields); } } } }
public void fillTarget(List<String> ret, Object val) { ret.add("" + ((TUnion) ((TBase)val) .getFieldValue(valueId)) .getSetField() .getThriftFieldId()); }
public static <T extends TBase<?,?>> StructOrUnionType structOrUnionType(Class<T> klass) { return TUnion.class.isAssignableFrom(klass) ? StructOrUnionType.UNION : StructOrUnionType.STRUCT; }