This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 5c5b7ffa96 NIFI-14070 Replaced where possible switch statements with
enhanced switch statements (#9573)
5c5b7ffa96 is described below
commit 5c5b7ffa9648193959a0acdd4b7b855002c2158b
Author: dan-s1 <[email protected]>
AuthorDate: Mon Dec 9 21:46:01 2024 -0500
NIFI-14070 Replaced where possible switch statements with enhanced switch
statements (#9573)
Signed-off-by: David Handermann <[email protected]>
---
.../nifi/provenance/StandardLineageResult.java | 16 ++-----
.../main/java/org/apache/nifi/util/Unpackage.java | 18 ++++----
.../nifi/record/path/paths/RecordPathCompiler.java | 47 ++++++++-----------
.../org/apache/nifi/processors/avro/SplitAvro.java | 25 ++++------
.../aws/ml/translate/GetAwsTranslateJobStatus.java | 36 +++++++--------
.../java/org/apache/nifi/util/db/AvroUtil.java | 20 +++-----
.../java/org/apache/nifi/util/db/JdbcCommon.java | 36 +++++++--------
.../nifi/util/db/TestJdbcCommonConvertToAvro.java | 19 +++-----
.../nifi/processors/hadoop/CompressionType.java | 21 ++++-----
.../processor/util/list/ListedEntityTracker.java | 11 ++---
.../processor/util/pattern/ExceptionHandler.java | 17 +++----
.../util/pattern/TestExceptionHandler.java | 19 ++++----
.../nifi/processors/geohash/GeohashRecord.java | 32 +++++--------
.../hadoop/CreateHadoopSequenceFile.java | 20 +++-----
.../apache/nifi/processors/hadoop/ListHDFS.java | 19 ++++----
.../processors/hadoop/inotify/GetHDFSEvents.java | 18 ++++----
.../org/apache/nifi/processors/AbstractIoTDB.java | 25 ++++------
.../apache/nifi/jolt/util/TransformFactory.java | 33 +++++---------
.../processors/mqtt/common/MqttClientFactory.java | 16 +++----
.../schema/SalesforceToRecordSchemaConverter.java | 53 ++++++----------------
.../nifi/processors/standard/GenerateRecord.java | 34 +++++---------
.../org/apache/nifi/avro/AvroRecordSetWriter.java | 20 +++-----
.../java/org/apache/nifi/csv/WriteCSVResult.java | 15 +++---
.../org/apache/nifi/csv/WriteFastCSVResult.java | 15 +++---
.../windowsevent/WindowsEventLogRecordReader.java | 23 ++--------
25 files changed, 230 insertions(+), 378 deletions(-)
diff --git
a/nifi-commons/nifi-data-provenance-utils/src/main/java/org/apache/nifi/provenance/StandardLineageResult.java
b/nifi-commons/nifi-data-provenance-utils/src/main/java/org/apache/nifi/provenance/StandardLineageResult.java
index 4b34c919cb..2440efdbdf 100644
---
a/nifi-commons/nifi-data-provenance-utils/src/main/java/org/apache/nifi/provenance/StandardLineageResult.java
+++
b/nifi-commons/nifi-data-provenance-utils/src/main/java/org/apache/nifi/provenance/StandardLineageResult.java
@@ -233,18 +233,10 @@ public class StandardLineageResult implements
ComputeLineageResult, ProgressiveR
// SPAWN Event's UUID is not necessarily what we want, since a
SPAWN Event's UUID pertains to
// only one of (potentially) many UUIDs associated with the
event. Otherwise, we know that
// the UUID of this record is appropriate, so we just use it.
- final String edgeUuid;
-
- switch (record.getEventType()) {
- case JOIN:
- case CLONE:
- case REPLAY:
- edgeUuid = lastNode.getFlowFileUuid();
- break;
- default:
- edgeUuid = record.getFlowFileUuid();
- break;
- }
+ final String edgeUuid = switch (record.getEventType()) {
+ case JOIN, CLONE, REPLAY -> lastNode.getFlowFileUuid();
+ default -> record.getFlowFileUuid();
+ };
edges.add(new EdgeNode(edgeUuid, lastNode, lineageNode));
}
diff --git
a/nifi-commons/nifi-flowfile-packager/src/main/java/org/apache/nifi/util/Unpackage.java
b/nifi-commons/nifi-flowfile-packager/src/main/java/org/apache/nifi/util/Unpackage.java
index 19f702ca01..65d2fa5ce3 100644
---
a/nifi-commons/nifi-flowfile-packager/src/main/java/org/apache/nifi/util/Unpackage.java
+++
b/nifi-commons/nifi-flowfile-packager/src/main/java/org/apache/nifi/util/Unpackage.java
@@ -104,16 +104,14 @@ public class Unpackage {
}
public static FlowFileUnpackager createUnpackager(final String version) {
- switch (version) {
- case "1":
- return new FlowFileUnpackagerV1();
- case "2":
- return new FlowFileUnpackagerV2();
- case "3":
- return new FlowFileUnpackagerV3();
- default:
+ return switch (version) {
+ case "1" -> new FlowFileUnpackagerV1();
+ case "2" -> new FlowFileUnpackagerV2();
+ case "3" -> new FlowFileUnpackagerV3();
+ default -> {
System.out.println("ERROR: Invalid version: " + version + ";
must be 1, 2, or 3");
- return null;
- }
+ yield null;
+ }
+ };
}
}
diff --git
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
index ac3efe72ab..9cc9d16145 100644
---
a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
+++
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
@@ -111,18 +111,14 @@ public class RecordPathCompiler {
}
// If the given path tree is an operator, create a Filter Function
that will be responsible for returning true/false based on the provided
operation
- switch (pathTree.getType()) {
- case EQUAL:
- case NOT_EQUAL:
- case LESS_THAN:
- case LESS_THAN_EQUAL:
- case GREATER_THAN:
- case GREATER_THAN_EQUAL:
+ return switch (pathTree.getType()) {
+ case EQUAL, NOT_EQUAL, LESS_THAN, LESS_THAN_EQUAL, GREATER_THAN,
GREATER_THAN_EQUAL -> {
final RecordPathFilter filter = createFilter(pathTree, null,
absolute);
- return new FilterFunction(pathTree.getText(), filter,
absolute);
- }
+ yield new FilterFunction(pathTree.getText(), filter, absolute);
+ }
+ default -> parent;
+ };
- return parent;
}
public static RecordPathSegment buildPath(final Tree tree, final
RecordPathSegment parent, final boolean absolute) {
@@ -479,24 +475,19 @@ public class RecordPathCompiler {
}
private static RecordPathFilter createFilter(final Tree operatorTree,
final RecordPathSegment parent, final boolean absolute) {
- switch (operatorTree.getType()) {
- case EQUAL:
- return createBinaryOperationFilter(operatorTree, parent,
EqualsFilter::new, absolute);
- case NOT_EQUAL:
- return createBinaryOperationFilter(operatorTree, parent,
NotEqualsFilter::new, absolute);
- case LESS_THAN:
- return createBinaryOperationFilter(operatorTree, parent,
LessThanFilter::new, absolute);
- case LESS_THAN_EQUAL:
- return createBinaryOperationFilter(operatorTree, parent,
LessThanOrEqualFilter::new, absolute);
- case GREATER_THAN:
- return createBinaryOperationFilter(operatorTree, parent,
GreaterThanFilter::new, absolute);
- case GREATER_THAN_EQUAL:
- return createBinaryOperationFilter(operatorTree, parent,
GreaterThanOrEqualFilter::new, absolute);
- case FUNCTION:
- return createFunctionFilter(operatorTree, absolute);
- default:
- throw new RecordPathException("Expected an Expression of form
<value> <operator> <value> to follow '[' Token but found " + operatorTree);
- }
+ return switch (operatorTree.getType()) {
+ case EQUAL -> createBinaryOperationFilter(operatorTree, parent,
EqualsFilter::new, absolute);
+ case NOT_EQUAL -> createBinaryOperationFilter(operatorTree,
parent, NotEqualsFilter::new, absolute);
+ case LESS_THAN -> createBinaryOperationFilter(operatorTree,
parent, LessThanFilter::new, absolute);
+ case LESS_THAN_EQUAL ->
+ createBinaryOperationFilter(operatorTree, parent,
LessThanOrEqualFilter::new, absolute);
+ case GREATER_THAN -> createBinaryOperationFilter(operatorTree,
parent, GreaterThanFilter::new, absolute);
+ case GREATER_THAN_EQUAL ->
+ createBinaryOperationFilter(operatorTree, parent,
GreaterThanOrEqualFilter::new, absolute);
+ case FUNCTION -> createFunctionFilter(operatorTree, absolute);
+ default ->
+ throw new RecordPathException("Expected an Expression of
form <value> <operator> <value> to follow '[' Token but found " + operatorTree);
+ };
}
private static RecordPathFilter createBinaryOperationFilter(final Tree
operatorTree, final RecordPathSegment parent,
diff --git
a/nifi-extension-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java
b/nifi-extension-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java
index 7e3821b3dc..487324d731 100644
---
a/nifi-extension-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java
+++
b/nifi-extension-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java
@@ -199,25 +199,18 @@ public class SplitAvro extends AbstractProcessor {
SplitWriter splitWriter;
final String outputStrategy =
context.getProperty(OUTPUT_STRATEGY).getValue();
- switch (outputStrategy) {
- case DATAFILE_OUTPUT_VALUE:
- splitWriter = new DatafileSplitWriter(transferMetadata);
- break;
- case BARE_RECORD_OUTPUT_VALUE:
- splitWriter = new BareRecordSplitWriter();
- break;
- default:
- throw new AssertionError();
- }
+ splitWriter = switch (outputStrategy) {
+ case DATAFILE_OUTPUT_VALUE -> new
DatafileSplitWriter(transferMetadata);
+ case BARE_RECORD_OUTPUT_VALUE -> new BareRecordSplitWriter();
+ default -> throw new AssertionError();
+ };
Splitter splitter;
final String splitStrategy =
context.getProperty(SPLIT_STRATEGY).getValue();
- switch (splitStrategy) {
- case RECORD_SPLIT_VALUE:
- splitter = new RecordSplitter(splitSize, transferMetadata);
- break;
- default:
- throw new AssertionError();
+ if (splitStrategy.equals(RECORD_SPLIT_VALUE)) {
+ splitter = new RecordSplitter(splitSize, transferMetadata);
+ } else {
+ throw new AssertionError();
}
try {
diff --git
a/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/ml/translate/GetAwsTranslateJobStatus.java
b/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/ml/translate/GetAwsTranslateJobStatus.java
index 18c8dbaeea..ac44807438 100644
---
a/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/ml/translate/GetAwsTranslateJobStatus.java
+++
b/nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/ml/translate/GetAwsTranslateJobStatus.java
@@ -61,30 +61,28 @@ public class GetAwsTranslateJobStatus extends
AbstractAwsMachineLearningJobStatu
flowFile = writeToFlowFile(session, flowFile, job);
final Relationship transferRelationship;
String failureReason = null;
- switch (status) {
- case IN_PROGRESS:
- case SUBMITTED:
- case STOP_REQUESTED:
+ transferRelationship = switch (status) {
+ case IN_PROGRESS, SUBMITTED, STOP_REQUESTED -> {
flowFile = session.penalize(flowFile);
- transferRelationship = REL_RUNNING;
- break;
- case COMPLETED:
+ yield REL_RUNNING;
+ }
+ case COMPLETED -> {
flowFile = session.putAttribute(flowFile,
AWS_TASK_OUTPUT_LOCATION,
job.textTranslationJobProperties().outputDataConfig().s3Uri());
- transferRelationship = REL_SUCCESS;
- break;
- case FAILED:
- case COMPLETED_WITH_ERROR:
+ yield REL_SUCCESS;
+ }
+ case FAILED, COMPLETED_WITH_ERROR -> {
failureReason =
job.textTranslationJobProperties().message();
- transferRelationship = REL_FAILURE;
- break;
- case STOPPED:
+ yield REL_FAILURE;
+ }
+ case STOPPED -> {
failureReason = String.format("Job [%s] is stopped",
job.textTranslationJobProperties().jobId());
- transferRelationship = REL_FAILURE;
- break;
- default:
+ yield REL_FAILURE;
+ }
+ default -> {
failureReason = "Unknown Job Status";
- transferRelationship = REL_FAILURE;
- }
+ yield REL_FAILURE;
+ }
+ };
if (failureReason != null) {
flowFile = session.putAttribute(flowFile,
FAILURE_REASON_ATTRIBUTE, failureReason);
}
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/AvroUtil.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/AvroUtil.java
index 8bb2261d67..bb27a0d2aa 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/AvroUtil.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/AvroUtil.java
@@ -33,19 +33,13 @@ public class AvroUtil {
public static CodecFactory getCodecFactory(String property) {
CodecType type = CodecType.valueOf(property);
- switch (type) {
- case BZIP2:
- return CodecFactory.bzip2Codec();
- case DEFLATE:
- return
CodecFactory.deflateCodec(CodecFactory.DEFAULT_DEFLATE_LEVEL);
- case LZO:
- return CodecFactory.xzCodec(CodecFactory.DEFAULT_XZ_LEVEL);
- case SNAPPY:
- return CodecFactory.snappyCodec();
- case NONE:
- default:
- return CodecFactory.nullCodec();
- }
+ return switch (type) {
+ case BZIP2 -> CodecFactory.bzip2Codec();
+ case DEFLATE ->
CodecFactory.deflateCodec(CodecFactory.DEFAULT_DEFLATE_LEVEL);
+ case LZO -> CodecFactory.xzCodec(CodecFactory.DEFAULT_XZ_LEVEL);
+ case SNAPPY -> CodecFactory.snappyCodec();
+ default -> CodecFactory.nullCodec();
+ };
}
}
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java
index 36d6a152c7..12fea67839 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java
@@ -912,24 +912,24 @@ public class JdbcCommon {
}
public static DateTimeFormatter getDateTimeFormatter(String pattern) {
- switch (pattern) {
- case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
- case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
- case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
- case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
- case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
- case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
- case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
- case "ISO_LOCAL_DATE_TIME": return
DateTimeFormatter.ISO_LOCAL_DATE_TIME;
- case "ISO_OFFSET_DATE_TIME": return
DateTimeFormatter.ISO_OFFSET_DATE_TIME;
- case "ISO_ZONED_DATE_TIME": return
DateTimeFormatter.ISO_ZONED_DATE_TIME;
- case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
- case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
- case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
- case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
- case "RFC_1123_DATE_TIME": return
DateTimeFormatter.RFC_1123_DATE_TIME;
- default: return DateTimeFormatter.ofPattern(pattern);
- }
+ return switch (pattern) {
+ case "BASIC_ISO_DATE" -> DateTimeFormatter.BASIC_ISO_DATE;
+ case "ISO_LOCAL_DATE" -> DateTimeFormatter.ISO_LOCAL_DATE;
+ case "ISO_OFFSET_DATE" -> DateTimeFormatter.ISO_OFFSET_DATE;
+ case "ISO_DATE" -> DateTimeFormatter.ISO_DATE;
+ case "ISO_LOCAL_TIME" -> DateTimeFormatter.ISO_LOCAL_TIME;
+ case "ISO_OFFSET_TIME" -> DateTimeFormatter.ISO_OFFSET_TIME;
+ case "ISO_TIME" -> DateTimeFormatter.ISO_TIME;
+ case "ISO_LOCAL_DATE_TIME" ->
DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+ case "ISO_OFFSET_DATE_TIME" ->
DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+ case "ISO_ZONED_DATE_TIME" ->
DateTimeFormatter.ISO_ZONED_DATE_TIME;
+ case "ISO_DATE_TIME" -> DateTimeFormatter.ISO_DATE_TIME;
+ case "ISO_ORDINAL_DATE" -> DateTimeFormatter.ISO_ORDINAL_DATE;
+ case "ISO_WEEK_DATE" -> DateTimeFormatter.ISO_WEEK_DATE;
+ case "ISO_INSTANT" -> DateTimeFormatter.ISO_INSTANT;
+ case "RFC_1123_DATE_TIME" -> DateTimeFormatter.RFC_1123_DATE_TIME;
+ default -> DateTimeFormatter.ofPattern(pattern);
+ };
}
/**
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommonConvertToAvro.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommonConvertToAvro.java
index f7d384331b..2fd1071bec 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommonConvertToAvro.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommonConvertToAvro.java
@@ -88,18 +88,13 @@ public class TestJdbcCommonConvertToAvro {
this.signed = signed;
}
private String humanReadableType() {
- switch (sqlType) {
- case TINYINT:
- return "TINYINT";
- case INTEGER:
- return "INTEGER";
- case SMALLINT:
- return "SMALLINT";
- case BIGINT:
- return "BIGINT";
- default:
- return "UNKNOWN - ADD TO LIST";
- }
+ return switch (sqlType) {
+ case TINYINT -> "TINYINT";
+ case INTEGER -> "INTEGER";
+ case SMALLINT -> "SMALLINT";
+ case BIGINT -> "BIGINT";
+ default -> "UNKNOWN - ADD TO LIST";
+ };
}
private String humanReadableSigned() {
if (signed) return "SIGNED";
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/CompressionType.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/CompressionType.java
index b5a7894511..45eb1fb606 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/CompressionType.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/CompressionType.java
@@ -52,17 +52,16 @@ public enum CompressionType {
@Override
public String toString() {
- switch (this) {
- case NONE: return "NONE";
- case DEFAULT: return DefaultCodec.class.getName();
- case BZIP: return BZip2Codec.class.getName();
- case GZIP: return GzipCodec.class.getName();
- case LZ4: return Lz4Codec.class.getName();
- case LZO: return "com.hadoop.compression.lzo.LzoCodec";
- case SNAPPY: return SnappyCodec.class.getName();
- case AUTOMATIC: return "Automatically Detected";
- }
- return null;
+ return switch (this) {
+ case NONE -> "NONE";
+ case DEFAULT -> DefaultCodec.class.getName();
+ case BZIP -> BZip2Codec.class.getName();
+ case GZIP -> GzipCodec.class.getName();
+ case LZ4 -> Lz4Codec.class.getName();
+ case LZO -> "com.hadoop.compression.lzo.LzoCodec";
+ case SNAPPY -> SnappyCodec.class.getName();
+ case AUTOMATIC -> "Automatically Detected";
+ };
}
public static AllowableValue[] allowableValues() {
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-listed-entity/src/main/java/org/apache/nifi/processor/util/list/ListedEntityTracker.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-listed-entity/src/main/java/org/apache/nifi/processor/util/list/ListedEntityTracker.java
index 5f000bf6d4..5363ad879b 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-listed-entity/src/main/java/org/apache/nifi/processor/util/list/ListedEntityTracker.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-listed-entity/src/main/java/org/apache/nifi/processor/util/list/ListedEntityTracker.java
@@ -200,13 +200,10 @@ public class ListedEntityTracker<T extends
ListableEntity> {
private static final String CACHE_KEY_PREFIX = "ListedEntities";
private String getCacheKey() {
- switch (scope) {
- case LOCAL:
- return format("%s::%s::%s", CACHE_KEY_PREFIX, componentId,
nodeId);
- case CLUSTER:
- return format("%s::%s", CACHE_KEY_PREFIX, componentId);
- }
- throw new IllegalArgumentException("Unknown scope: " + scope);
+ return switch (scope) {
+ case LOCAL -> format("%s::%s::%s", CACHE_KEY_PREFIX, componentId,
nodeId);
+ case CLUSTER -> format("%s::%s", CACHE_KEY_PREFIX, componentId);
+ };
}
private void persistListedEntities(Map<String, ListedEntity>
listedEntities) throws IOException {
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/main/java/org/apache/nifi/processor/util/pattern/ExceptionHandler.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/main/java/org/apache/nifi/processor/util/pattern/ExceptionHandler.java
index bf5058512e..a9d14a82ea 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/main/java/org/apache/nifi/processor/util/pattern/ExceptionHandler.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/main/java/org/apache/nifi/processor/util/pattern/ExceptionHandler.java
@@ -211,17 +211,12 @@ public class ExceptionHandler<C> {
Object inputs = null;
if (g != null) {
final List<FlowFile> flowFiles = g.getFlowFiles();
- switch (flowFiles.size()) {
- case 0:
- inputs = "[]";
- break;
- case 1:
- inputs = flowFiles.get(0);
- break;
- default:
- inputs = String.format("%d FlowFiles
including %s", flowFiles.size(), flowFiles.get(0));
- break;
- }
+ inputs = switch (flowFiles.size()) {
+ case 0 -> "[]";
+ case 1 -> flowFiles.getFirst();
+ default ->
+ String.format("%d FlowFiles including
%s", flowFiles.size(), flowFiles.get(0));
+ };
}
throw new ProcessException(String.format("Failed to
process %s due to %s", inputs, e), e);
}
diff --git
a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java
b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java
index b63f53ccf9..a7ff33e5f0 100644
---
a/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java
+++
b/nifi-extension-bundles/nifi-extension-utils/nifi-put-pattern/src/test/java/org/apache/nifi/processor/util/pattern/TestExceptionHandler.java
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
@@ -139,22 +140,20 @@ public class TestExceptionHandler {
static <C> ExceptionHandler.OnError<C, Integer> createInputErrorHandler() {
return (c, i, r, e) -> {
- switch (r.destination()) {
- case ProcessException:
- throw new ProcessException(String.format("Execution failed
due to %s", e), e);
- default:
- logger.warn(String.format("Routing to %s: %d caused %s",
r, i, e));
+ if (Objects.requireNonNull(r.destination()) ==
ErrorTypes.Destination.ProcessException) {
+ throw new ProcessException(String.format("Execution failed due
to %s", e), e);
+ } else {
+ logger.warn(String.format("Routing to %s: %d caused %s", r, i,
e));
}
};
}
static <C> ExceptionHandler.OnError<C, Integer[]>
createArrayInputErrorHandler() {
return (c, i, r, e) -> {
- switch (r.destination()) {
- case ProcessException:
- throw new ProcessException(String.format("Execution failed
due to %s", e), e);
- default:
- logger.warn(String.format("Routing to %s: %d, %d caused
%s", r, i[0], i[1], e));
+ if (Objects.requireNonNull(r.destination()) ==
ErrorTypes.Destination.ProcessException) {
+ throw new ProcessException(String.format("Execution failed due
to %s", e), e);
+ } else {
+ logger.warn(String.format("Routing to %s: %d, %d caused %s",
r, i[0], i[1], e));
}
};
}
diff --git
a/nifi-extension-bundles/nifi-geohash-bundle/nifi-geohash-processors/src/main/java/org/apache/nifi/processors/geohash/GeohashRecord.java
b/nifi-extension-bundles/nifi-geohash-bundle/nifi-geohash-processors/src/main/java/org/apache/nifi/processors/geohash/GeohashRecord.java
index 5ef0dcf59e..1ec592a540 100644
---
a/nifi-extension-bundles/nifi-geohash-bundle/nifi-geohash-processors/src/main/java/org/apache/nifi/processors/geohash/GeohashRecord.java
+++
b/nifi-extension-bundles/nifi-geohash-bundle/nifi-geohash-processors/src/main/java/org/apache/nifi/processors/geohash/GeohashRecord.java
@@ -466,14 +466,11 @@ public class GeohashRecord extends AbstractProcessor {
double realLongValue = Double.parseDouble(longitudeVal.toString());
GeoHash gh = GeoHash.withCharacterPrecision(realLatValue,
realLongValue, level);
- switch (format) {
- case BINARY:
- return gh.toBinaryString();
- case LONG:
- return gh.longValue();
- default:
- return gh.toBase32();
- }
+ return switch (format) {
+ case BINARY -> gh.toBinaryString();
+ case LONG -> gh.longValue();
+ default -> gh.toBase32();
+ };
}
private WGS84Point getDecodedPointFromGeohash(RecordPath geohashPath,
Record record, GeohashFormat format) {
@@ -491,19 +488,14 @@ public class GeohashRecord extends AbstractProcessor {
}
String geohashString = geohashVal.toString();
- GeoHash decodedHash;
-
- switch (format) {
- case BINARY:
- decodedHash = GeoHash.fromBinaryString(geohashString);
- break;
- case LONG:
+ GeoHash decodedHash = switch (format) {
+ case BINARY -> GeoHash.fromBinaryString(geohashString);
+ case LONG -> {
String binaryString =
Long.toBinaryString(Long.parseLong(geohashString));
- decodedHash = GeoHash.fromBinaryString(binaryString);
- break;
- default:
- decodedHash = GeoHash.fromGeohashString(geohashString);
- }
+ yield GeoHash.fromBinaryString(binaryString);
+ }
+ default -> GeoHash.fromGeohashString(geohashString);
+ };
return decodedHash.getBoundingBoxCenter();
}
diff --git
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/CreateHadoopSequenceFile.java
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/CreateHadoopSequenceFile.java
index 17a0411ca6..2ea7b46bdb 100644
---
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/CreateHadoopSequenceFile.java
+++
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/CreateHadoopSequenceFile.java
@@ -141,20 +141,12 @@ public class CreateHadoopSequenceFile extends
AbstractHadoopProcessor {
}
}
}
- final SequenceFileWriter sequenceFileWriter;
- switch (packagingFormat) {
- case TAR_FORMAT:
- sequenceFileWriter = new TarUnpackerSequenceFileWriter();
- break;
- case ZIP_FORMAT:
- sequenceFileWriter = new ZipUnpackerSequenceFileWriter();
- break;
- case FLOWFILE_STREAM_FORMAT_V3:
- sequenceFileWriter = new
FlowFileStreamUnpackerSequenceFileWriter();
- break;
- default:
- sequenceFileWriter = new SequenceFileWriterImpl();
- }
+ final SequenceFileWriter sequenceFileWriter = switch (packagingFormat)
{
+ case TAR_FORMAT -> new TarUnpackerSequenceFileWriter();
+ case ZIP_FORMAT -> new ZipUnpackerSequenceFileWriter();
+ case FLOWFILE_STREAM_FORMAT_V3 -> new
FlowFileStreamUnpackerSequenceFileWriter();
+ default -> new SequenceFileWriterImpl();
+ };
final Configuration configuration = getConfiguration();
if (configuration == null) {
diff --git
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/ListHDFS.java
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/ListHDFS.java
index 4bba8572ca..f703287b88 100644
---
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/ListHDFS.java
+++
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/ListHDFS.java
@@ -313,18 +313,15 @@ public class ListHDFS extends AbstractHadoopProcessor {
final FilterMode filterMode =
FilterMode.forName(context.getProperty(FILE_FILTER_MODE).getValue());
final boolean recursive =
context.getProperty(RECURSE_SUBDIRS).asBoolean();
- switch (filterMode) {
- case FILTER_MODE_FILES_ONLY:
- return path ->
fileFilterRegexPattern.matcher(path.getName()).matches();
- case FILTER_MODE_FULL_PATH:
- return path ->
fileFilterRegexPattern.matcher(path.toString()).matches()
- ||
fileFilterRegexPattern.matcher(Path.getPathWithoutSchemeAndAuthority(path).toString()).matches();
+ return switch (filterMode) {
+ case FILTER_MODE_FILES_ONLY -> path ->
fileFilterRegexPattern.matcher(path.getName()).matches();
+ case FILTER_MODE_FULL_PATH -> path ->
fileFilterRegexPattern.matcher(path.toString()).matches()
+ ||
fileFilterRegexPattern.matcher(Path.getPathWithoutSchemeAndAuthority(path).toString()).matches();
// FILTER_DIRECTORIES_AND_FILES
- default:
- return path ->
Stream.of(Path.getPathWithoutSchemeAndAuthority(path).toString().split("/"))
- .skip(getPathSegmentsToSkip(recursive))
- .allMatch(v ->
fileFilterRegexPattern.matcher(v).matches());
- }
+ default -> path ->
Stream.of(Path.getPathWithoutSchemeAndAuthority(path).toString().split("/"))
+ .skip(getPathSegmentsToSkip(recursive))
+ .allMatch(v ->
fileFilterRegexPattern.matcher(v).matches());
+ };
}
private int getPathSegmentsToSkip(final boolean recursive) {
diff --git
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/inotify/GetHDFSEvents.java
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/inotify/GetHDFSEvents.java
index 2ec15209f1..c169854a1a 100644
---
a/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/inotify/GetHDFSEvents.java
+++
b/nifi-extension-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/inotify/GetHDFSEvents.java
@@ -292,15 +292,15 @@ public class GetHDFSEvents extends
AbstractHadoopProcessor {
throw new IllegalArgumentException("Event and event type must not
be null.");
}
- switch (event.getEventType()) {
- case CREATE: return ((Event.CreateEvent) event).getPath();
- case CLOSE: return ((Event.CloseEvent) event).getPath();
- case APPEND: return ((Event.AppendEvent) event).getPath();
- case RENAME: return ((Event.RenameEvent) event).getSrcPath();
- case METADATA: return ((Event.MetadataUpdateEvent)
event).getPath();
- case UNLINK: return ((Event.UnlinkEvent) event).getPath();
- default: throw new IllegalArgumentException("Unsupported event
type.");
- }
+ return switch (event.getEventType()) {
+ case CREATE -> ((Event.CreateEvent) event).getPath();
+ case CLOSE -> ((Event.CloseEvent) event).getPath();
+ case APPEND -> ((Event.AppendEvent) event).getPath();
+ case RENAME -> ((Event.RenameEvent) event).getSrcPath();
+ case METADATA -> ((Event.MetadataUpdateEvent) event).getPath();
+ case UNLINK -> ((Event.UnlinkEvent) event).getPath();
+ default -> throw new IllegalArgumentException("Unsupported event
type.");
+ };
}
private static class NotificationConfig {
diff --git
a/nifi-extension-bundles/nifi-iotdb-bundle/nifi-iotdb-processors/src/main/java/org/apache/nifi/processors/AbstractIoTDB.java
b/nifi-extension-bundles/nifi-iotdb-bundle/nifi-iotdb-processors/src/main/java/org/apache/nifi/processors/AbstractIoTDB.java
index 959726933e..e003861f0b 100755
---
a/nifi-extension-bundles/nifi-iotdb-bundle/nifi-iotdb-processors/src/main/java/org/apache/nifi/processors/AbstractIoTDB.java
+++
b/nifi-extension-bundles/nifi-iotdb-bundle/nifi-iotdb-processors/src/main/java/org/apache/nifi/processors/AbstractIoTDB.java
@@ -334,22 +334,15 @@ public abstract class AbstractIoTDB extends
AbstractProcessor {
}
protected Object convertType(Object value, TSDataType type) {
- switch (type) {
- case TEXT:
- return new Binary(String.valueOf(value),
StandardCharsets.UTF_8);
- case INT32:
- return Integer.parseInt(value.toString());
- case INT64:
- return Long.parseLong(value.toString());
- case FLOAT:
- return Float.parseFloat(value.toString());
- case DOUBLE:
- return Double.parseDouble(value.toString());
- case BOOLEAN:
- return Boolean.parseBoolean(value.toString());
- default:
- return null;
- }
+ return switch (type) {
+ case TEXT -> new Binary(String.valueOf(value),
StandardCharsets.UTF_8);
+ case INT32 -> Integer.parseInt(value.toString());
+ case INT64 -> Long.parseLong(value.toString());
+ case FLOAT -> Float.parseFloat(value.toString());
+ case DOUBLE -> Double.parseDouble(value.toString());
+ case BOOLEAN -> Boolean.parseBoolean(value.toString());
+ default -> null;
+ };
}
protected DatabaseSchema convertSchema(final String timeField, final
RecordSchema recordSchema) {
diff --git
a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-utils/src/main/java/org/apache/nifi/jolt/util/TransformFactory.java
b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-utils/src/main/java/org/apache/nifi/jolt/util/TransformFactory.java
index 4c3e3afe25..a25aec4abf 100644
---
a/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-utils/src/main/java/org/apache/nifi/jolt/util/TransformFactory.java
+++
b/nifi-extension-bundles/nifi-jolt-bundle/nifi-jolt-utils/src/main/java/org/apache/nifi/jolt/util/TransformFactory.java
@@ -36,27 +36,18 @@ import java.util.Map;
public class TransformFactory {
public static JoltTransform getTransform(final ClassLoader classLoader,
final String transformType, final Object specJson) throws Exception {
- switch (JoltTransformStrategy.get(transformType)) {
- case DEFAULTR:
- return new Defaultr(specJson);
- case SHIFTR:
- return new Shiftr(specJson);
- case REMOVR:
- return new Removr(specJson);
- case CARDINALITY:
- return new CardinalityTransform(specJson);
- case SORTR:
- return new Sortr();
- case MODIFIER_DEFAULTR:
- return new Modifier.Defaultr(specJson);
- case MODIFIER_OVERWRITER:
- return new Modifier.Overwritr(specJson);
- case MODIFIER_DEFINER:
- return new Modifier.Definr(specJson);
- case CHAINR:
- return new Chainr(getChainrJoltTransformations(classLoader,
specJson));
- }
- return null;
+ return switch (JoltTransformStrategy.get(transformType)) {
+ case DEFAULTR -> new Defaultr(specJson);
+ case SHIFTR -> new Shiftr(specJson);
+ case REMOVR -> new Removr(specJson);
+ case CARDINALITY -> new CardinalityTransform(specJson);
+ case SORTR -> new Sortr();
+ case MODIFIER_DEFAULTR -> new Modifier.Defaultr(specJson);
+ case MODIFIER_OVERWRITER -> new Modifier.Overwritr(specJson);
+ case MODIFIER_DEFINER -> new Modifier.Definr(specJson);
+ case CHAINR -> new
Chainr(getChainrJoltTransformations(classLoader, specJson));
+ default -> null;
+ };
}
public static JoltTransform getCustomTransform(final ClassLoader
classLoader, final String customTransformType, final Object specJson) throws
Exception {
diff --git
a/nifi-extension-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/common/MqttClientFactory.java
b/nifi-extension-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/common/MqttClientFactory.java
index 762f9a40da..d48b4741ff 100644
---
a/nifi-extension-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/common/MqttClientFactory.java
+++
b/nifi-extension-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/main/java/org/apache/nifi/processors/mqtt/common/MqttClientFactory.java
@@ -39,16 +39,12 @@ public class MqttClientFactory {
}
public MqttClient create() throws TlsException {
- switch (clientProperties.getMqttVersion()) {
- case MQTT_VERSION_3_AUTO:
- case MQTT_VERSION_3_1:
- case MQTT_VERSION_3_1_1:
- return new PahoMqttClientAdapter(brokerUris.next(),
clientProperties, logger);
- case MQTT_VERSION_5_0:
- return new HiveMqV5ClientAdapter(brokerUris.next(),
clientProperties, logger);
- default:
- throw new MqttException("Unsupported Mqtt version: " +
clientProperties.getMqttVersion());
- }
+ return switch (clientProperties.getMqttVersion()) {
+ case MQTT_VERSION_3_AUTO, MQTT_VERSION_3_1, MQTT_VERSION_3_1_1 ->
+ new PahoMqttClientAdapter(brokerUris.next(),
clientProperties, logger);
+ case MQTT_VERSION_5_0 -> new
HiveMqV5ClientAdapter(brokerUris.next(), clientProperties, logger);
+ default -> throw new MqttException("Unsupported Mqtt version: " +
clientProperties.getMqttVersion());
+ };
}
static class RoundRobinList<T> {
diff --git
a/nifi-extension-bundles/nifi-salesforce-bundle/nifi-salesforce-processors/src/main/java/org/apache/nifi/processors/salesforce/schema/SalesforceToRecordSchemaConverter.java
b/nifi-extension-bundles/nifi-salesforce-bundle/nifi-salesforce-processors/src/main/java/org/apache/nifi/processors/salesforce/schema/SalesforceToRecordSchemaConverter.java
index 3e0d82d147..417538f70c 100644
---
a/nifi-extension-bundles/nifi-salesforce-bundle/nifi-salesforce-processors/src/main/java/org/apache/nifi/processors/salesforce/schema/SalesforceToRecordSchemaConverter.java
+++
b/nifi-extension-bundles/nifi-salesforce-bundle/nifi-salesforce-processors/src/main/java/org/apache/nifi/processors/salesforce/schema/SalesforceToRecordSchemaConverter.java
@@ -84,45 +84,20 @@ public class SalesforceToRecordSchemaConverter {
private RecordField convertSObjectFieldToRecordField(SObjectField field) {
String soapType = field.getSoapType();
- DataType dataType;
- switch (soapType.substring(soapType.indexOf(':') + 1)) {
- case "ID":
- case "string":
- case "json":
- case "base64Binary":
- case "anyType":
- dataType = RecordFieldType.STRING.getDataType();
- break;
- case "int":
- dataType = RecordFieldType.INT.getDataType();
- break;
- case "long":
- dataType = RecordFieldType.LONG.getDataType();
- break;
- case "double":
- dataType = RecordFieldType.DOUBLE.getDataType();
- break;
- case "boolean":
- dataType = RecordFieldType.BOOLEAN.getDataType();
- break;
- case "date":
- dataType = RecordFieldType.DATE.getDataType(dateFormat);
- break;
- case "dateTime":
- dataType =
RecordFieldType.TIMESTAMP.getDataType(dateTimeFormat);
- break;
- case "time":
- dataType = RecordFieldType.TIME.getDataType(timeFormat);
- break;
- case "address":
- dataType =
RecordFieldType.RECORD.getRecordDataType(createAddressSchema());
- break;
- case "location":
- dataType =
RecordFieldType.RECORD.getRecordDataType(createLocationSchema());
- break;
- default:
- throw new IllegalArgumentException(String.format("Could not
convert field '%s' of soap type '%s'.", field.getName(), soapType));
- }
+ DataType dataType = switch (soapType.substring(soapType.indexOf(':') +
1)) {
+ case "ID", "string", "json", "base64Binary", "anyType" ->
RecordFieldType.STRING.getDataType();
+ case "int" -> RecordFieldType.INT.getDataType();
+ case "long" -> RecordFieldType.LONG.getDataType();
+ case "double" -> RecordFieldType.DOUBLE.getDataType();
+ case "boolean" -> RecordFieldType.BOOLEAN.getDataType();
+ case "date" -> RecordFieldType.DATE.getDataType(dateFormat);
+ case "dateTime" ->
RecordFieldType.TIMESTAMP.getDataType(dateTimeFormat);
+ case "time" -> RecordFieldType.TIME.getDataType(timeFormat);
+ case "address" ->
RecordFieldType.RECORD.getRecordDataType(createAddressSchema());
+ case "location" ->
RecordFieldType.RECORD.getRecordDataType(createLocationSchema());
+ default ->
+ throw new IllegalArgumentException(String.format("Could
not convert field '%s' of soap type '%s'.", field.getName(), soapType));
+ };
return new RecordField(field.getName(), dataType,
field.getDefaultValue(), field.isNillable());
}
diff --git
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateRecord.java
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateRecord.java
index 9049b4413a..cd3e7dc0da 100644
---
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateRecord.java
+++
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateRecord.java
@@ -382,28 +382,18 @@ public class GenerateRecord extends AbstractProcessor {
private String generateRandomString() {
final int categoryChoice = faker.number().numberBetween(0, 10);
- switch (categoryChoice) {
- case 0:
- return faker.name().fullName();
- case 1:
- return faker.lorem().word();
- case 2:
- return faker.shakespeare().romeoAndJulietQuote();
- case 3:
- return faker.educator().university();
- case 4:
- return faker.zelda().game();
- case 5:
- return faker.company().name();
- case 6:
- return faker.chuckNorris().fact();
- case 7:
- return faker.book().title();
- case 8:
- return faker.dog().breed();
- default:
- return faker.animal().name();
- }
+ return switch (categoryChoice) {
+ case 0 -> faker.name().fullName();
+ case 1 -> faker.lorem().word();
+ case 2 -> faker.shakespeare().romeoAndJulietQuote();
+ case 3 -> faker.educator().university();
+ case 4 -> faker.zelda().game();
+ case 5 -> faker.company().name();
+ case 6 -> faker.chuckNorris().fact();
+ case 7 -> faker.book().title();
+ case 8 -> faker.dog().breed();
+ default -> faker.animal().name();
+ };
}
protected RecordSchema generateRecordSchema(final Map<String, String>
fields, final boolean nullable) {
diff --git
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroRecordSetWriter.java
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroRecordSetWriter.java
index 00cb5eef03..3093ba7ebf 100644
---
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroRecordSetWriter.java
+++
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/avro/AvroRecordSetWriter.java
@@ -157,19 +157,13 @@ public class AvroRecordSetWriter extends
SchemaRegistryRecordSetWriter implement
private CodecFactory getCodecFactory(String property) {
CodecType type = CodecType.valueOf(property);
- switch (type) {
- case BZIP2:
- return CodecFactory.bzip2Codec();
- case DEFLATE:
- return
CodecFactory.deflateCodec(CodecFactory.DEFAULT_DEFLATE_LEVEL);
- case LZO:
- return CodecFactory.xzCodec(CodecFactory.DEFAULT_XZ_LEVEL);
- case SNAPPY:
- return CodecFactory.snappyCodec();
- case NONE:
- default:
- return CodecFactory.nullCodec();
- }
+ return switch (type) {
+ case BZIP2 -> CodecFactory.bzip2Codec();
+ case DEFLATE ->
CodecFactory.deflateCodec(CodecFactory.DEFAULT_DEFLATE_LEVEL);
+ case LZO -> CodecFactory.xzCodec(CodecFactory.DEFAULT_XZ_LEVEL);
+ case SNAPPY -> CodecFactory.snappyCodec();
+ default -> CodecFactory.nullCodec();
+ };
}
@Override
diff --git
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteCSVResult.java
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteCSVResult.java
index a8ec4460ce..7c70cd01f2 100644
---
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteCSVResult.java
+++
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteCSVResult.java
@@ -69,16 +69,13 @@ public class WriteCSVResult extends AbstractRecordSetWriter
implements RecordSet
private String getFormat(final RecordField field) {
final DataType dataType = field.getDataType();
- switch (dataType.getFieldType()) {
- case DATE:
- return dateFormat;
- case TIME:
- return timeFormat;
- case TIMESTAMP:
- return timestampFormat;
- }
+ return switch (dataType.getFieldType()) {
+ case DATE -> dateFormat;
+ case TIME -> timeFormat;
+ case TIMESTAMP -> timestampFormat;
+ default -> dataType.getFormat();
+ };
- return dataType.getFormat();
}
@Override
diff --git
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteFastCSVResult.java
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteFastCSVResult.java
index f1b1f41055..8722aa20b7 100644
---
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteFastCSVResult.java
+++
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/WriteFastCSVResult.java
@@ -104,16 +104,13 @@ public class WriteFastCSVResult extends
AbstractRecordSetWriter implements Recor
private String getFormat(final RecordField field) {
final DataType dataType = field.getDataType();
- switch (dataType.getFieldType()) {
- case DATE:
- return dateFormat;
- case TIME:
- return timeFormat;
- case TIMESTAMP:
- return timestampFormat;
- }
+ return switch (dataType.getFieldType()) {
+ case DATE -> dateFormat;
+ case TIME -> timeFormat;
+ case TIMESTAMP -> timestampFormat;
+ default -> dataType.getFormat();
+ };
- return dataType.getFormat();
}
@Override
diff --git
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/windowsevent/WindowsEventLogRecordReader.java
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/windowsevent/WindowsEventLogRecordReader.java
index 5d39500e41..32ae77095b 100644
---
a/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/windowsevent/WindowsEventLogRecordReader.java
+++
b/nifi-extension-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/windowsevent/WindowsEventLogRecordReader.java
@@ -488,24 +488,11 @@ public class WindowsEventLogRecordReader implements
RecordReader {
}
private Object parseStringForType(String data, String fieldName, DataType
dataType) {
- switch (dataType.getFieldType()) {
- case BOOLEAN:
- case BYTE:
- case CHAR:
- case DECIMAL:
- case DOUBLE:
- case FLOAT:
- case INT:
- case LONG:
- case SHORT:
- case STRING:
- case DATE:
- case TIME:
- case TIMESTAMP: {
- return DataTypeUtils.convertType(data, dataType,
Optional.ofNullable(dateFormat), Optional.ofNullable(timeFormat),
Optional.ofNullable(timestampFormat), fieldName);
- }
- }
- return null;
+ return switch (dataType.getFieldType()) {
+ case BOOLEAN, BYTE, CHAR, DECIMAL, DOUBLE, FLOAT, INT, LONG,
SHORT, STRING, DATE, TIME, TIMESTAMP ->
+ DataTypeUtils.convertType(data, dataType,
Optional.ofNullable(dateFormat), Optional.ofNullable(timeFormat),
Optional.ofNullable(timestampFormat), fieldName);
+ default -> null;
+ };
}
private Object parseFieldForType(StartElement startElement, String
fieldName, DataType dataType, Map<String, Object> recordValues,