endzeit created NIFI-12452:
------------------------------
Summary: Improve support for Enum & DescribedValue for
allowableValues
Key: NIFI-12452
URL: https://issues.apache.org/jira/browse/NIFI-12452
Project: Apache NiFi
Issue Type: Improvement
Components: Core Framework
Reporter: endzeit
The {{PropertyDescriptor.Builder}} supports providing a {{Class}} that is both
an {{Enum}} and {{{}DescribedValue{}}}. This improves type safety, by avoiding
the passing of sheer arbitrary {{String}} values.
I'd like to propose extensions to both the {{PropertyDescriptor.Builder}} class
as well as the {{PropertyValue}} interface.
----
The {{PropertyDescriptor.Builder}} should allow not only a raw {{String}} to be
provided as {{{}defaultValue(){}}}, but also provide an overload that instead
accepts an {{{}DescribedValue{}}}.
{code:java}
public Builder defaultValue(final DescribedValue value) {code}
This allows to replace
{code:java}
.allowableValues(Foo.class)
.defaultValue(Foo.BAR.getValue()) {code}
with
{code:java}
.allowableValues(Foo.class)
.defaultValue(Foo.BAR) {code}
----
The {{PropertyValue}} should allow to receive the value as one of the Enum
constants, similar to one of the existing {{as...}} methods.
{code:java}
<E extends Enum<E> & DescribedValue> E asAllowableValue(Class<E> clazz) {code}
This way processor implementations rely on type-safe mappings of allowable
values instead of matching on {{String}} values manually.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)