use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class SnsResponse method of.
public static <T> SnsResponse<T> of(@NonNull T element, @Nullable PublishResponse response) {
final Optional<PublishResponse> publishResponse = Optional.ofNullable(response);
OptionalInt statusCode = publishResponse.map(r -> OptionalInt.of(r.sdkHttpResponse().statusCode())).orElse(OptionalInt.empty());
Optional<String> statusText = publishResponse.flatMap(r -> r.sdkHttpResponse().statusText());
return create(element, statusCode, statusText);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class PipelineOptionsFactory method printHelp.
/**
* Outputs the set of options available to be set for the passed in {@link PipelineOptions}
* interface. The output is in a human readable format. The format is:
*
* <pre>
* OptionGroup:
* ... option group description ...
*
* --option1={@code <type>} or list of valid enum choices
* Default: value (if available, see {@link Default})
* ... option description ... (if available, see {@link Description})
* Required groups (if available, see {@link Required})
* --option2={@code <type>} or list of valid enum choices
* Default: value (if available, see {@link Default})
* ... option description ... (if available, see {@link Description})
* Required groups (if available, see {@link Required})
* </pre>
*
* This method will attempt to format its output to be compatible with a terminal window.
*/
public static void printHelp(PrintStream out, Class<? extends PipelineOptions> iface) {
checkNotNull(out);
checkNotNull(iface);
CACHE.get().validateWellFormed(iface);
Set<PipelineOptionSpec> properties = PipelineOptionsReflector.getOptionSpecs(iface, true);
RowSortedTable<Class<?>, String, Method> ifacePropGetterTable = TreeBasedTable.create(ClassNameComparator.INSTANCE, Ordering.natural());
for (PipelineOptionSpec prop : properties) {
ifacePropGetterTable.put(prop.getDefiningInterface(), prop.getName(), prop.getGetterMethod());
}
for (Map.Entry<Class<?>, Map<String, Method>> ifaceToPropertyMap : ifacePropGetterTable.rowMap().entrySet()) {
Class<?> currentIface = ifaceToPropertyMap.getKey();
Map<String, Method> propertyNamesToGetters = ifaceToPropertyMap.getValue();
SortedSetMultimap<String, String> requiredGroupNameToProperties = getRequiredGroupNamesToProperties(propertyNamesToGetters);
out.format("%s:%n", currentIface.getName());
Description ifaceDescription = currentIface.getAnnotation(Description.class);
if (ifaceDescription != null && ifaceDescription.value() != null) {
prettyPrintDescription(out, ifaceDescription);
}
out.println();
List<@KeyFor("propertyNamesToGetters") String> lists = Lists.newArrayList(propertyNamesToGetters.keySet());
lists.sort(String.CASE_INSENSITIVE_ORDER);
for (String propertyName : lists) {
Method method = propertyNamesToGetters.get(propertyName);
String printableType = method.getReturnType().getSimpleName();
if (method.getReturnType().isEnum()) {
Object @Nullable [] enumConstants = method.getReturnType().getEnumConstants();
assert enumConstants != null : "@AssumeAssertion(nullness): checked that it is an enum";
printableType = Joiner.on(" | ").join(method.getReturnType().getEnumConstants());
}
out.format(" --%s=<%s>%n", propertyName, printableType);
Optional<String> defaultValue = getDefaultValueFromAnnotation(method);
if (defaultValue.isPresent()) {
out.format(" Default: %s%n", defaultValue.get());
}
@Nullable Description methodDescription = method.getAnnotation(Description.class);
if (methodDescription != null && methodDescription.value() != null) {
prettyPrintDescription(out, methodDescription);
}
prettyPrintRequiredGroups(out, method.getAnnotation(Validation.Required.class), requiredGroupNameToProperties);
}
out.println();
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class AutoValueUtils method getConstructorCreator.
/**
* Try to find an accessible constructor for creating an AutoValue class. Otherwise return null.
*/
@Nullable
public static SchemaUserTypeCreator getConstructorCreator(Class<?> clazz, Schema schema, FieldValueTypeSupplier fieldValueTypeSupplier) {
Class<?> generatedClass = getAutoValueGenerated(clazz);
List<FieldValueTypeInformation> schemaTypes = fieldValueTypeSupplier.get(clazz, schema);
Optional<Constructor<?>> constructor = Arrays.stream(generatedClass.getDeclaredConstructors()).filter(c -> !Modifier.isPrivate(c.getModifiers())).filter(c -> matchConstructor(c, schemaTypes)).findAny();
return constructor.map(c -> JavaBeanUtils.getConstructorCreator(generatedClass, c, schema, fieldValueTypeSupplier, new DefaultTypeConversionsFactory())).orElse(null);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class FromRowUsingCreator method fromValue.
@SuppressWarnings("unchecked")
@Nullable
private <ValueT> ValueT fromValue(FieldType type, ValueT value, Type fieldType, FieldValueTypeInformation fieldValueTypeInformation, Factory<List<FieldValueTypeInformation>> typeFactory) {
FieldValueTypeInformation elementType = fieldValueTypeInformation.getElementType();
FieldValueTypeInformation keyType = fieldValueTypeInformation.getMapKeyType();
FieldValueTypeInformation valueType = fieldValueTypeInformation.getMapValueType();
if (value == null) {
return null;
}
if (TypeName.ROW.equals(type.getTypeName())) {
return (ValueT) fromRow((Row) value, (Class) fieldType, typeFactory);
} else if (TypeName.ARRAY.equals(type.getTypeName())) {
return (ValueT) fromCollectionValue(type.getCollectionElementType(), (Collection) value, elementType, typeFactory);
} else if (TypeName.ITERABLE.equals(type.getTypeName())) {
return (ValueT) fromIterableValue(type.getCollectionElementType(), (Iterable) value, elementType, typeFactory);
}
if (TypeName.MAP.equals(type.getTypeName())) {
return (ValueT) fromMapValue(type.getMapKeyType(), type.getMapValueType(), (Map) value, keyType, valueType, typeFactory);
} else {
if (type.isLogicalType(OneOfType.IDENTIFIER)) {
OneOfType oneOfType = type.getLogicalType(OneOfType.class);
EnumerationType oneOfEnum = oneOfType.getCaseEnumType();
OneOfType.Value oneOfValue = (OneOfType.Value) value;
FieldValueTypeInformation oneOfFieldValueTypeInformation = checkNotNull(fieldValueTypeInformation.getOneOfTypes().get(oneOfEnum.toString(oneOfValue.getCaseType())));
Object fromValue = fromValue(oneOfType.getFieldType(oneOfValue), oneOfValue.getValue(), oneOfFieldValueTypeInformation.getRawType(), oneOfFieldValueTypeInformation, typeFactory);
return (ValueT) oneOfType.createValue(oneOfValue.getCaseType(), fromValue);
} else if (type.getTypeName().isLogicalType()) {
return (ValueT) type.getLogicalType().toBaseType(value);
}
return value;
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.
the class SchemaTranslation method fieldTypeFromProtoWithoutNullable.
private static FieldType fieldTypeFromProtoWithoutNullable(SchemaApi.FieldType protoFieldType) {
switch(protoFieldType.getTypeInfoCase()) {
case ATOMIC_TYPE:
switch(protoFieldType.getAtomicType()) {
case BYTE:
return FieldType.of(TypeName.BYTE);
case INT16:
return FieldType.of(TypeName.INT16);
case INT32:
return FieldType.of(TypeName.INT32);
case INT64:
return FieldType.of(TypeName.INT64);
case FLOAT:
return FieldType.of(TypeName.FLOAT);
case DOUBLE:
return FieldType.of(TypeName.DOUBLE);
case STRING:
return FieldType.of(TypeName.STRING);
case BOOLEAN:
return FieldType.of(TypeName.BOOLEAN);
case BYTES:
return FieldType.of(TypeName.BYTES);
case UNSPECIFIED:
throw new IllegalArgumentException("Encountered UNSPECIFIED AtomicType");
default:
throw new IllegalArgumentException("Encountered unknown AtomicType: " + protoFieldType.getAtomicType());
}
case ROW_TYPE:
return FieldType.row(schemaFromProto(protoFieldType.getRowType().getSchema()));
case ARRAY_TYPE:
return FieldType.array(fieldTypeFromProto(protoFieldType.getArrayType().getElementType()));
case ITERABLE_TYPE:
return FieldType.iterable(fieldTypeFromProto(protoFieldType.getIterableType().getElementType()));
case MAP_TYPE:
return FieldType.map(fieldTypeFromProto(protoFieldType.getMapType().getKeyType()), fieldTypeFromProto(protoFieldType.getMapType().getValueType()));
case LOGICAL_TYPE:
String urn = protoFieldType.getLogicalType().getUrn();
Class<? extends LogicalType<?, ?>> logicalTypeClass = STANDARD_LOGICAL_TYPES.get(urn);
if (logicalTypeClass != null) {
try {
return FieldType.logicalType(logicalTypeClass.getConstructor().newInstance());
} catch (NoSuchMethodException e) {
throw new RuntimeException(String.format("Standard logical type '%s' does not have a zero-argument constructor.", urn), e);
} catch (IllegalAccessException e) {
throw new RuntimeException(String.format("Standard logical type '%s' has a zero-argument constructor, but it is not accessible.", urn), e);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(String.format("Error instantiating logical type '%s' with zero-argument constructor.", urn), e);
}
}
// but not yet in Java. (BEAM-7554)
if (urn.equals(URN_BEAM_LOGICAL_DATETIME)) {
return FieldType.DATETIME;
} else if (urn.equals(URN_BEAM_LOGICAL_DECIMAL)) {
return FieldType.DECIMAL;
} else if (urn.equals(URN_BEAM_LOGICAL_JAVASDK)) {
return FieldType.logicalType((LogicalType) SerializableUtils.deserializeFromByteArray(protoFieldType.getLogicalType().getPayload().toByteArray(), "logicalType"));
} else {
@Nullable FieldType argumentType = null;
@Nullable Object argumentValue = null;
if (protoFieldType.getLogicalType().hasArgumentType()) {
argumentType = fieldTypeFromProto(protoFieldType.getLogicalType().getArgumentType());
argumentValue = fieldValueFromProto(argumentType, protoFieldType.getLogicalType().getArgument());
}
return FieldType.logicalType(new UnknownLogicalType(urn, protoFieldType.getLogicalType().getPayload().toByteArray(), argumentType, argumentValue, fieldTypeFromProto(protoFieldType.getLogicalType().getRepresentation())));
}
default:
throw new IllegalArgumentException("Unexpected type_info: " + protoFieldType.getTypeInfoCase());
}
}
Aggregations