From 8070751da83a01602c911baf1d2615b7c22f2144 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Mon, 5 Jun 2023 13:19:28 +0200 Subject: [PATCH] Improve String concatenation where appropriate --- .../configuration/xml/AbstractListenerParser.java | 7 ++++--- .../batch/core/configuration/xml/TaskletParser.java | 9 +++++---- .../batch/item/data/Neo4jItemReader.java | 6 +++--- .../item/database/support/SqlPagingQueryUtils.java | 8 ++++---- .../domain/order/internal/OrderLineAggregator.java | 12 ++++++------ .../CompositeItemWriterSampleFunctionalTests.java | 8 ++++---- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractListenerParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractListenerParser.java index 5b59b2ab0..1ec84f601 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractListenerParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractListenerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2022 the original author or authors. + * Copyright 2009-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import org.w3c.dom.Element; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 * @see StepListenerParser * @see JobExecutionListenerParser @@ -107,13 +108,13 @@ public abstract class AbstractListenerParser { found.append("<" + BEAN_ELE + "/> element, "); } else if (beanElements.size() > 1) { - found.append(beanElements.size() + " <" + BEAN_ELE + "/> elements, "); + found.append(beanElements.size()).append(" <").append(BEAN_ELE).append("/> elements, "); } if (refElements.size() == 1) { found.append("<" + REF_ELE + "/> element, "); } else if (refElements.size() > 1) { - found.append(refElements.size() + " <" + REF_ELE + "/> elements, "); + found.append(refElements.size()).append(" <").append(REF_ELE).append("/> elements, "); } found.delete(found.length() - 2, found.length()); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletParser.java index f67799e1f..323956f10 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.w3c.dom.Element; * Parse a tasklet element for a step. * * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.1 * */ @@ -136,19 +137,19 @@ public class TaskletParser { found.append("<" + CHUNK_ELE + "/> element, "); } else if (chunkElements.size() > 1) { - found.append(chunkElements.size() + " <" + CHUNK_ELE + "/> elements, "); + found.append(chunkElements.size()).append(" <").append(CHUNK_ELE).append("/> elements, "); } if (beanElements.size() == 1) { found.append("<" + BEAN_ELE + "/> element, "); } else if (beanElements.size() > 1) { - found.append(beanElements.size() + " <" + BEAN_ELE + "/> elements, "); + found.append(beanElements.size()).append(" <").append(BEAN_ELE).append("/> elements, "); } if (refElements.size() == 1) { found.append("<" + REF_ELE + "/> element, "); } else if (refElements.size() > 1) { - found.append(refElements.size() + " <" + REF_ELE + "/> elements, "); + found.append(refElements.size()).append(" <").append(REF_ELE).append("/> elements, "); } found.delete(found.length() - 2, found.length()); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java index a58b51a92..e0a0c5fad 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -173,8 +173,8 @@ public class Neo4jItemReader extends AbstractPaginatedDataItemReader imple query.append(whereStatement != null ? " WHERE " + whereStatement : ""); query.append(" RETURN ").append(returnStatement); query.append(" ORDER BY ").append(orderByStatement); - query.append(" SKIP " + (pageSize * page)); - query.append(" LIMIT " + pageSize); + query.append(" SKIP ").append(pageSize * page); + query.append(" LIMIT ").append(pageSize); String resultingQuery = query.toString(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java index 3717a30b7..f332f92fc 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public class SqlPagingQueryUtils { buildWhereClause(provider, remainingPageQuery, sql); buildGroupByClause(provider, sql); sql.append(" ORDER BY ").append(buildSortClause(provider)); - sql.append(" " + limitClause); + sql.append(" ").append(limitClause); return sql.toString(); } @@ -82,7 +82,7 @@ public class SqlPagingQueryUtils { sql.append("WHERE "); buildSortConditions(provider, sql); sql.append(" ORDER BY ").append(buildSortClause(provider)); - sql.append(" " + limitClause); + sql.append(" ").append(limitClause); return sql.toString(); } @@ -106,7 +106,7 @@ public class SqlPagingQueryUtils { sql.append("WHERE "); buildSortConditions(provider, sql); sql.append(" ORDER BY ").append(buildSortClause(provider)); - sql.append(" " + limitClause); + sql.append(" ").append(limitClause); return sql.toString(); } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderLineAggregator.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderLineAggregator.java index dbb5c4c3c..ef89c3450 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderLineAggregator.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderLineAggregator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,13 +38,13 @@ public class OrderLineAggregator implements LineAggregator { public String aggregate(Order order) { StringBuilder result = new StringBuilder(); - result.append(aggregators.get("header").aggregate(order) + LINE_SEPARATOR); - result.append(aggregators.get("customer").aggregate(order) + LINE_SEPARATOR); - result.append(aggregators.get("address").aggregate(order) + LINE_SEPARATOR); - result.append(aggregators.get("billing").aggregate(order) + LINE_SEPARATOR); + result.append(aggregators.get("header").aggregate(order)).append(LINE_SEPARATOR); + result.append(aggregators.get("customer").aggregate(order)).append(LINE_SEPARATOR); + result.append(aggregators.get("address").aggregate(order)).append(LINE_SEPARATOR); + result.append(aggregators.get("billing").aggregate(order)).append(LINE_SEPARATOR); for (LineItem lineItem : order.getLineItems()) { - result.append(aggregators.get("item").aggregate(lineItem) + LINE_SEPARATOR); + result.append(aggregators.get("item").aggregate(lineItem)).append(LINE_SEPARATOR); } result.append(aggregators.get("footer").aggregate(order)); diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java index 5147b5fd0..041b1f1cc 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CompositeItemWriterSampleFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2022 the original author or authors. + * Copyright 2008-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,12 +106,12 @@ class CompositeItemWriterSampleFunctionalTests { private void checkOutputFile(String fileName) throws IOException { List outputLines = IOUtils.readLines(new FileInputStream(fileName), "UTF-8"); - String output = ""; + StringBuilder output = new StringBuilder(); for (String line : outputLines) { - output += line; + output.append(line); } - assertEquals(EXPECTED_OUTPUT_FILE, output); + assertEquals(EXPECTED_OUTPUT_FILE, output.toString()); } }