Mark fields as final where appropriate

This commit is contained in:
Mahmoud Ben Hassine
2023-07-04 21:45:20 +02:00
parent 241e37e672
commit 0a1cdb095f
166 changed files with 411 additions and 365 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 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.
@@ -24,10 +24,11 @@ import org.apache.commons.logging.LogFactory;
* representation of the object to the log.
*
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*/
public class LogAdvice {
private static Log log = LogFactory.getLog(LogAdvice.class);
private static final Log log = LogFactory.getLog(LogAdvice.class);
public void doStronglyTypedLogging(Object item) {
if (log.isInfoEnabled()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 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.
@@ -24,12 +24,13 @@ package org.springframework.batch.sample.common;
* @see StagingItemReader
* @see StagingItemProcessor
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
*/
public class ProcessIndicatorItemWrapper<T> {
private long id;
private final long id;
private T item;
private final T item;
public ProcessIndicatorItemWrapper(long id, T item) {
this.id = id;

View File

@@ -46,7 +46,7 @@ import org.springframework.util.Assert;
public class StagingItemReader<T>
implements ItemReader<ProcessIndicatorItemWrapper<T>>, StepExecutionListener, InitializingBean, DisposableBean {
private static Log logger = LogFactory.getLog(StagingItemReader.class);
private static final Log logger = LogFactory.getLog(StagingItemReader.class);
private StepExecution stepExecution;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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.
@@ -29,13 +29,14 @@ import org.springframework.mail.MailMessage;
*
* @author Dan Garrette
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @since 2.1
*/
public class TestMailErrorHandler implements MailErrorHandler {
private static final Log LOGGER = LogFactory.getLog(TestMailErrorHandler.class);
private List<MailMessage> failedMessages = new ArrayList<>();
private final List<MailMessage> failedMessages = new ArrayList<>();
@Override
public void handle(MailMessage failedMessage, Exception ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 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.
@@ -37,7 +37,7 @@ public class TestMailSender implements MailSender {
private List<String> subjectsToFail = new ArrayList<>();
private List<SimpleMailMessage> received = new ArrayList<>();
private final List<SimpleMailMessage> received = new ArrayList<>();
public void clear() {
received.clear();

View File

@@ -60,7 +60,7 @@ public class AggregateItem<T> {
return HEADER;
}
private T item;
private final T item;
private boolean footer = false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 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.
@@ -39,6 +39,7 @@ import org.springframework.lang.Nullable;
* @see AggregateItem#isHeader()
* @see AggregateItem#isFooter()
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class AggregateItemReader<T> implements ItemReader<List<T>> {
@@ -109,7 +110,7 @@ public class AggregateItemReader<T> implements ItemReader<List<T>> {
*/
private class ResultHolder {
private List<T> records = new ArrayList<>();
private final List<T> records = new ArrayList<>();
private boolean exhausted = false;

View File

@@ -38,7 +38,7 @@ import org.springframework.lang.Nullable;
*/
public class OrderItemReader implements ItemReader<Order> {
private static Log log = LogFactory.getLog(OrderItemReader.class);
private static final Log log = LogFactory.getLog(OrderItemReader.class);
private Order order;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2014 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.
@@ -22,11 +22,12 @@ import org.springframework.batch.sample.domain.order.Order;
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0.1
*/
public class HeaderFieldExtractor implements FieldExtractor<Order> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
@Override
public Object[] extract(Order order) {

View File

@@ -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.
@@ -25,7 +25,7 @@ import org.springframework.batch.sample.domain.person.Person;
public class PersonWriter implements ItemWriter<Person> {
private static Log log = LogFactory.getLog(PersonWriter.class);
private static final Log log = LogFactory.getLog(PersonWriter.class);
@Override
public void write(Chunk<? extends Person> data) {

View File

@@ -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.
@@ -28,13 +28,14 @@ import org.springframework.batch.sample.domain.trade.CustomerCreditDao;
/**
* @author Lucas Ward
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class HibernateCreditDao implements CustomerCreditDao, RepeatListener {
private int failOnFlush = -1;
private List<Throwable> errors = new ArrayList<>();
private final List<Throwable> errors = new ArrayList<>();
private SessionFactory sessionFactory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 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.
@@ -30,10 +30,11 @@ import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer
* Writes a Trade object to a database
*
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
*/
public class JdbcTradeDao implements TradeDao {
private Log log = LogFactory.getLog(JdbcTradeDao.class);
private final Log log = LogFactory.getLog(JdbcTradeDao.class);
/**
* template for inserting a row

View File

@@ -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.
@@ -38,7 +38,7 @@ import org.springframework.util.Assert;
*/
public class TradeWriter extends ItemStreamSupport implements ItemWriter<Trade> {
private static Log log = LogFactory.getLog(TradeWriter.class);
private static final Log log = LogFactory.getLog(TradeWriter.class);
public static final String TOTAL_AMOUNT_KEY = "TOTAL_AMOUNT";

View File

@@ -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.
@@ -20,12 +20,13 @@ import org.springframework.context.ApplicationEvent;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
@SuppressWarnings("serial")
public class SimpleMessageApplicationEvent extends ApplicationEvent {
private String message;
private final String message;
public SimpleMessageApplicationEvent(Object source, String message) {
super(source);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 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,7 +36,7 @@ public class DefaultJobLoader implements JobLoader, ApplicationContextAware {
private ApplicationContext applicationContext;
private Map<String, String> configurations = new HashMap<>();
private final Map<String, String> configurations = new HashMap<>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-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.
@@ -30,7 +30,7 @@ import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class Job1Configuration {
private Random random;
private final Random random;
public Job1Configuration() {
this.random = new Random();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-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,7 +34,7 @@ import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class Job2Configuration {
private Random random;
private final Random random;
public Job2Configuration() {
this.random = new Random();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 the original author or authors.
* Copyright 2021-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.
@@ -45,7 +45,7 @@ public class PrometheusConfiguration {
@Value("${prometheus.pushgateway.url}")
private String prometheusPushGatewayUrl;
private Map<String, String> groupingKey = new HashMap<>();
private final Map<String, String> groupingKey = new HashMap<>();
private PushGateway pushGateway;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 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.
@@ -31,6 +31,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public class JobLauncherDetails extends QuartzJobBean {
@@ -40,7 +41,7 @@ public class JobLauncherDetails extends QuartzJobBean {
*/
static final String JOB_NAME = "jobName";
private static Log log = LogFactory.getLog(JobLauncherDetails.class);
private static final Log log = LogFactory.getLog(JobLauncherDetails.class);
private JobLocator jobLocator;

View File

@@ -108,9 +108,9 @@ class CustomerFilterJobFunctionalTests {
private static class Customer {
private String name;
private final String name;
private double credit;
private final double credit;
public Customer(String name, double credit) {
this.name = name;

View File

@@ -116,9 +116,9 @@ class TradeJobFunctionalTests {
private static class Customer {
private String name;
private final String name;
private double credit;
private final double credit;
public Customer(String name, double credit) {
this.name = name;

View File

@@ -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.
@@ -37,7 +37,7 @@ class ColumnRangePartitionerTests {
this.dataSource = dataSource;
}
private ColumnRangePartitioner partitioner = new ColumnRangePartitioner();
private final ColumnRangePartitioner partitioner = new ColumnRangePartitioner();
@Test
void testPartition() {

View File

@@ -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.
@@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
*
* @author Lucas Ward
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
*
*/
class CustomItemReaderTests {
@@ -80,7 +81,7 @@ class CustomItemReaderTests {
private static final String CURRENT_INDEX = "current.index";
private List<T> items;
private final List<T> items;
private int currentIndex = 0;

View File

@@ -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.
@@ -47,7 +47,7 @@ class CustomItemWriterTests {
static class CustomItemWriter<T> implements ItemWriter<T> {
private List<T> output = TransactionAwareProxyFactory.createTransactionalList();
private final List<T> output = TransactionAwareProxyFactory.createTransactionalList();
@Override
public void write(Chunk<? extends T> chunk) throws Exception {

View File

@@ -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.
@@ -29,7 +29,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
public class ItemTrackingTradeItemWriter implements ItemWriter<Trade> {
private List<Trade> items = new ArrayList<>();
private final List<Trade> items = new ArrayList<>();
private String writeFailureISIN;