@SuppressWarnings("unchecked") private <ElementT> TypeDescriptor<List<ElementT>> createListType(TypeDescriptor<?> type) { TypeDescriptor componentType = TypeDescriptor.of(ClassUtils.primitiveToWrapper(type.getComponentType().getRawType())); return new TypeDescriptor<List<ElementT>>() {}.where( new TypeParameter<ElementT>() {}, componentType); } }
private static FieldType getArrayFieldType(TypeDescriptor typeDescriptor) { if (typeDescriptor.isArray()) { if (typeDescriptor.getComponentType().getType().equals(byte.class)) { return FieldType.BYTES; } else { return FieldType.array(fieldTypeForJavaType(typeDescriptor.getComponentType())); } } if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) { TypeDescriptor<Collection<?>> collection = typeDescriptor.getSupertype(Collection.class); if (collection.getType() instanceof ParameterizedType) { ParameterizedType ptype = (ParameterizedType) collection.getType(); java.lang.reflect.Type[] params = ptype.getActualTypeArguments(); checkArgument(params.length == 1); return FieldType.array(fieldTypeForJavaType(TypeDescriptor.of(params[0]))); } } throw new RuntimeException("Could not determine array parameter type for field."); }
@SuppressWarnings("unchecked") static Implementation getArrayComponentType(TypeDescriptor valueType) { if (valueType.isArray()) { Type component = valueType.getComponentType().getType(); if (!component.equals(byte.class)) { return FixedValue.reference(component); } } else if (valueType.isSubtypeOf(TypeDescriptor.of(Collection.class))) { TypeDescriptor<Collection<?>> collection = valueType.getSupertype(Collection.class); if (collection.getType() instanceof ParameterizedType) { ParameterizedType ptype = (ParameterizedType) collection.getType(); java.lang.reflect.Type[] params = ptype.getActualTypeArguments(); checkArgument(params.length == 1); return FixedValue.reference(params[0]); } else { throw new RuntimeException("Collection parameter is not parameterized!"); } } return FixedValue.nullValue(); }
private void checkArray(String context, TypeDescriptor<?> type, Schema schema) { TypeDescriptor<?> elementType = null; if (type.isArray()) { // The type is an array (with ordering)-> deterministic iff the element is deterministic. elementType = type.getComponentType(); } else if (isSubtypeOf(type, Collection.class)) { if (isSubtypeOf(type, List.class, SortedSet.class)) { // Ordered collection -> deterministic iff the element is deterministic elementType = type.resolveType(Collection.class.getTypeParameters()[0]); } else { // Not an ordered collection -> not deterministic reportError(context, "%s may not be deterministically ordered", type); return; } } else { // If it was an unknown type encoded as an array, be conservative and assume // that we don't know anything about the order. reportError(context, "encoding %s as an ARRAY was unexpected", type); return; } // If we get here, it's either a deterministically-ordered Collection, or // an array. Either way, the type is deterministic iff the element type is // deterministic. recurse(context, elementType, schema.getElementType()); }
public T convert(TypeDescriptor typeDescriptor) { if (typeDescriptor.isArray() && !typeDescriptor.getComponentType().getRawType().equals(byte.class)) { // Byte arrays are special, so leave those alone. return convertArray(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) { return convertCollection(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Map.class))) { return convertMap(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(ReadableInstant.class))) { return convertDateTime(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(ByteBuffer.class))) { return convertByteBuffer(typeDescriptor); } else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(CharSequence.class))) { return convertCharSequence(typeDescriptor); } else if (typeDescriptor.getRawType().isPrimitive()) { return convertPrimitive(typeDescriptor); } else { return convertDefault(typeDescriptor); } }
TypeDescriptor component = type.getComponentType(); if (component.getRawType().equals(byte.class)) { return FieldType.BYTES;