use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Collections2.transform in project beam by apache.
the class PipelineOptionsFactoryTest method testDescribe.
@Test
public void testDescribe() {
List<PipelineOptionDescriptor> described = PipelineOptionsFactory.describe(Sets.newHashSet(PipelineOptions.class, TestDescribeOptions.class));
Map<String, PipelineOptionDescriptor> mapped = uniqueIndex(described, input -> input.getName());
assertEquals("no duplicates", described.size(), mapped.size());
Collection<PipelineOptionDescriptor> filtered = Collections2.filter(described, input -> input.getGroup().equals(TestDescribeOptions.class.getName()));
assertEquals(6, filtered.size());
mapped = uniqueIndex(filtered, input -> input.getName());
PipelineOptionDescriptor listDesc = mapped.get("list");
assertThat(listDesc, notNullValue());
assertThat(listDesc.getDescription(), isEmptyString());
assertEquals(PipelineOptionType.Enum.ARRAY, listDesc.getType());
assertThat(listDesc.getDefaultValue(), isEmptyString());
PipelineOptionDescriptor stringDesc = mapped.get("string");
assertThat(stringDesc, notNullValue());
assertThat(stringDesc.getDescription(), isEmptyString());
assertEquals(PipelineOptionType.Enum.STRING, stringDesc.getType());
assertThat(stringDesc.getDefaultValue(), isEmptyString());
PipelineOptionDescriptor integerDesc = mapped.get("integer");
assertThat(integerDesc, notNullValue());
assertEquals("integer property", integerDesc.getDescription());
assertEquals(PipelineOptionType.Enum.INTEGER, integerDesc.getType());
assertThat(integerDesc.getDefaultValue(), isEmptyString());
PipelineOptionDescriptor floatDesc = mapped.get("float");
assertThat(integerDesc, notNullValue());
assertEquals("float number property", floatDesc.getDescription());
assertEquals(PipelineOptionType.Enum.NUMBER, floatDesc.getType());
assertThat(floatDesc.getDefaultValue(), isEmptyString());
PipelineOptionDescriptor booleanSimpleDesc = mapped.get("boolean_simple");
assertThat(booleanSimpleDesc, notNullValue());
assertEquals("simple boolean property", booleanSimpleDesc.getDescription());
assertEquals(PipelineOptionType.Enum.BOOLEAN, booleanSimpleDesc.getType());
assertThat(booleanSimpleDesc.getDefaultValue(), equalTo("true"));
PipelineOptionDescriptor booleanWrapperDesc = mapped.get("boolean_wrapper");
assertThat(booleanWrapperDesc, notNullValue());
assertThat(booleanWrapperDesc.getDescription(), isEmptyString());
assertEquals(PipelineOptionType.Enum.BOOLEAN, booleanWrapperDesc.getType());
assertThat(booleanWrapperDesc.getDefaultValue(), equalTo("false"));
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Collections2.transform in project beam by apache.
the class ByteBuddyUtils method createCollectionTransformFunction.
// When processing a container (e.g. List<T>) we need to recursively process the element type.
// This function
// generates a subclass of Function that can be used to recursively transform each element of the
// container.
static Class createCollectionTransformFunction(Type fromType, Type toType, Function<StackManipulation, StackManipulation> convertElement) {
// Generate a TypeDescription for the class we want to generate.
TypeDescription.Generic functionGenericType = TypeDescription.Generic.Builder.parameterizedType(Function.class, Primitives.wrap((Class) fromType), Primitives.wrap((Class) toType)).build();
DynamicType.Builder<Function> builder = (DynamicType.Builder<Function>) BYTE_BUDDY.with(new InjectPackageStrategy((Class) fromType)).subclass(functionGenericType).method(ElementMatchers.named("apply")).intercept(new Implementation() {
@Override
public ByteCodeAppender appender(Target target) {
return (methodVisitor, implementationContext, instrumentedMethod) -> {
// this + method parameters.
int numLocals = 1 + instrumentedMethod.getParameters().size();
StackManipulation readValue = MethodVariableAccess.REFERENCE.loadFrom(1);
StackManipulation stackManipulation = new StackManipulation.Compound(convertElement.apply(readValue), MethodReturn.REFERENCE);
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
return new ByteCodeAppender.Size(size.getMaximalSize(), numLocals);
};
}
@Override
public InstrumentedType prepare(InstrumentedType instrumentedType) {
return instrumentedType;
}
});
return builder.visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES)).make().load(ReflectHelpers.findClassLoader(((Class) fromType).getClassLoader()), ClassLoadingStrategy.Default.INJECTION).getLoaded();
}
Aggregations