/** * Returns a type descriptor for the input of the given {@link SerializableFunction}, subject to * Java type erasure: may contain unresolved type variables if the type was erased. */ public static <InputT, OutputT> TypeDescriptor<InputT> inputOf( SerializableFunction<InputT, OutputT> fn) { return extractFromTypeParameters( fn, SerializableFunction.class, new TypeVariableExtractor<SerializableFunction<InputT, OutputT>, InputT>() {}); }
/** * Returns a type descriptor for the output of the given {@link SerializableFunction}, subject to * Java type erasure: may contain unresolved type variables if the type was erased. */ public static <InputT, OutputT> TypeDescriptor<OutputT> outputOf( SerializableFunction<InputT, OutputT> fn) { return extractFromTypeParameters( fn, SerializableFunction.class, new TypeVariableExtractor<SerializableFunction<InputT, OutputT>, OutputT>() {}); }
/** Like {@link #inputOf(SerializableFunction)} but for {@link Contextful.Fn}. */ public static <InputT, OutputT> TypeDescriptor<InputT> inputOf( Contextful.Fn<InputT, OutputT> fn) { return TypeDescriptors.extractFromTypeParameters( fn, Contextful.Fn.class, new TypeDescriptors.TypeVariableExtractor<Contextful.Fn<InputT, OutputT>, InputT>() {}); }
/** Like {@link #outputOf(SerializableFunction)} but for {@link Contextful.Fn}. */ public static <InputT, OutputT> TypeDescriptor<OutputT> outputOf( Contextful.Fn<InputT, OutputT> fn) { return TypeDescriptors.extractFromTypeParameters( fn, Contextful.Fn.class, new TypeDescriptors.TypeVariableExtractor<Contextful.Fn<InputT, OutputT>, OutputT>() {}); } }
private static <ActualFooT, ActualBarT> TypeDescriptor<ActualFooT> extractFooT( Generic<ActualFooT, ActualBarT> instance) { return TypeDescriptors.extractFromTypeParameters( instance, Generic.class, new TypeDescriptors.TypeVariableExtractor< Generic<ActualFooT, ActualBarT>, ActualFooT>() {}); }
private static <ActualFooT, ActualBarT> TypeDescriptor<ActualBarT> extractBarT( Generic<ActualFooT, ActualBarT> instance) { return TypeDescriptors.extractFromTypeParameters( instance, Generic.class, new TypeDescriptors.TypeVariableExtractor< Generic<ActualFooT, ActualBarT>, ActualBarT>() {}); }
private static <ActualFooT, ActualBarT> TypeDescriptor<KV<ActualFooT, ActualBarT>> extractKV( Generic<ActualFooT, ActualBarT> instance) { return TypeDescriptors.extractFromTypeParameters( instance, Generic.class, new TypeDescriptors.TypeVariableExtractor< Generic<ActualFooT, ActualBarT>, KV<ActualFooT, ActualBarT>>() {}); }
public static <T, V> TypeDescriptor<V> extractFromTypeParameters( T instance, Class<? super T> supertype, TypeVariableExtractor<T, V> extractor) { return extractFromTypeParameters( (TypeDescriptor<T>) TypeDescriptor.of(instance.getClass()), supertype, extractor);
final Coder<DestinationT> getDestinationCoderWithDefault(CoderRegistry registry) throws CannotProvideCoderException { Coder<DestinationT> destinationCoder = getDestinationCoder(); if (destinationCoder != null) { return destinationCoder; } // If dynamicDestinations doesn't provide a coder, try to find it in the coder registry. @Nullable TypeDescriptor<DestinationT> descriptor = extractFromTypeParameters( this, DynamicDestinations.class, new TypeVariableExtractor< DynamicDestinations<UserT, DestinationT, OutputT>, DestinationT>() {}); try { return registry.getCoder(descriptor); } catch (CannotProvideCoderException e) { throw new CannotProvideCoderException( "Failed to infer coder for DestinationT from type " + descriptor + ", please provide it explicitly by overriding getDestinationCoder()", e); } } }
Coder<DestinationT> getDestinationCoderWithDefault(CoderRegistry registry) throws CannotProvideCoderException { Coder<DestinationT> destinationCoder = getDestinationCoder(); if (destinationCoder != null) { return destinationCoder; } // If dynamicDestinations doesn't provide a coder, try to find it in the coder registry. TypeDescriptor<DestinationT> descriptor = extractFromTypeParameters( this, DynamicDestinations.class, new TypeDescriptors.TypeVariableExtractor< DynamicDestinations<T, DestinationT>, DestinationT>() {}); try { return registry.getCoder(descriptor); } catch (CannotProvideCoderException e) { throw new CannotProvideCoderException( "Failed to infer coder for DestinationT from type " + descriptor + ", please provide it explicitly by overriding getDestinationCoder()", e); } } }
Contextful<Fn<InputT, Iterable<OutputT>>> wrapped = (Contextful) Contextful.fn(fn); TypeDescriptor<OutputT> outputType = TypeDescriptors.extractFromTypeParameters( (TypeDescriptor<Iterable<OutputT>>) fn.getOutputTypeDescriptor(), Iterable.class,
TypeDescriptors.extractFromTypeParameters( getPollFn().getClosure(), PollFn.class,