[
https://issues.apache.org/jira/browse/NIFI-16073?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Stieglitz updated NIFI-16073:
------------------------------------
Status: Patch Available (was: In Progress)
> Apply Pattern variable in other places in the code base and make preexisting
> pattern variables final
> ----------------------------------------------------------------------------------------------------
>
> Key: NIFI-16073
> URL: https://issues.apache.org/jira/browse/NIFI-16073
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Daniel Stieglitz
> Assignee: Daniel Stieglitz
> Priority: Minor
>
> This ticket picks up where tickets NIFI-16041 and NIFI-16052 left off in that
> it aims to implement the pattern variable in other places of the code and
> make preexisting ones final.
> In many cases, the use of the pattern variable cleans up a lot of duplicate
> casts for example in
> nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/util/OutputStreamWritable
> .java the following snippet is before the pattern variable:
> {code:java}
> if (in instanceof DataInputBuffer) {
> byte[] bytes = ((DataInputBuffer) in).getData();
> int pos = ((DataInputBuffer) in).getPosition();
> int length = ((DataInputBuffer) in).getLength();
> int bytesRemaining = length - pos;{code}
> and after the use of the pattern variable
> {code:java}
> if (in instanceof final DataInputBuffer dataInputBuffer) {
> byte[] bytes = dataInputBuffer.getData();
> int pos = dataInputBuffer.getPosition();
> int length = dataInputBuffer.getLength();{code}
>
> Another example is
> nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/RepositoryContextFactory.java
> Before
> {code:java}
> public RepositoryContext newProcessContext(final Connectable connectable,
> final AtomicLong connectionIndex) {
> final Class<?> componentClass = (connectable instanceof ProcessorNode
> && ((ProcessorNode) connectable).getProcessor() != null)
> ? ((ProcessorNode) connectable).getProcessor().getClass()
> : null;{code}
> After
> {code:java}
> public RepositoryContext newProcessContext(final Connectable connectable,
> final AtomicLong connectionIndex) {
> final Class<?> componentClass = (connectable instanceof final
> ProcessorNode processorNode && processorNode.getProcessor() != null)
> ? processorNode.getProcessor().getClass()
> : null;{code}
>
> Another example
> nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/bigquery/PutBigQuery.java
> Before
> {code:java}
> else if (obj instanceof Object[] && ((Object[]) obj).length > 0 &&
> ((Object[]) obj)[0] instanceof MapRecord) {
> List<Map<String, Object>> list = new ArrayList<>();
> for (Object item : (Object[]) obj) {
> list.add(convertMapRecord(((MapRecord) item).toMap(),
> fieldSchema.getFieldsList()));
> }
> result.put(key, list);
> continue;
> }{code}
> After
> {code:java}
> else if (obj instanceof final Object[] objects && objects.length > 0 &&
> objects[0] instanceof MapRecord) {
> List<Map<String, Object>> list = new ArrayList<>();
> for (Object item : objects) {
> list.add(convertMapRecord(((MapRecord) item).toMap(),
> fieldSchema.getFieldsList()));
> }
> result.put(key, list);
> continue;
> }{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)