Skip to content

Commit 95e2d06

Browse files
author
eugenp
committed
general formatting work
1 parent fc59834 commit 95e2d06

36 files changed

Lines changed: 71 additions & 97 deletions

File tree

‎guava/src/test/java/org/baeldung/java/CollectionJavaPartitionUnitTest.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,4 @@ public final void givenList_whenSplittingBySeparator_thenCorrect() {
6767
assertThat(lastPartition, equalTo(expectedLastPartition));
6868
}
6969

70-
71-
72-
73-
7470
}

‎spring-all/src/main/java/org/baeldung/customannotation/DataAccess.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
1111
@Documented
1212
public @interface DataAccess {
13-
Class<?>entity();
13+
Class<?> entity();
1414
}

‎spring-all/src/main/java/org/baeldung/customannotation/DataAccessAnnotationProcessor.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ public DataAccessAnnotationProcessor(ConfigurableListableBeanFactory bf) {
1919
}
2020

2121
@Override
22-
public Object postProcessBeforeInitialization(Object bean, String beanName)
23-
throws BeansException {
22+
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
2423
scanDataAccessAnnotation(bean, beanName);
2524
return bean;
2625
}
2726

2827
@Override
29-
public Object postProcessAfterInitialization(Object bean, String beanName)
30-
throws BeansException {
28+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
3129
return bean;
3230
}
3331

‎spring-all/src/main/java/org/baeldung/customannotation/DataAccessFieldCallback.java‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
import org.springframework.util.ReflectionUtils;
1313
import org.springframework.util.ReflectionUtils.FieldCallback;
1414

15-
1615
public final class DataAccessFieldCallback implements FieldCallback {
1716

1817
private static Logger logger = LoggerFactory.getLogger(DataAccessFieldCallback.class);
1918
private static int AUTOWIRE_MODE = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
2019

21-
private static String ERROR_ENTITY_VALUE_NOT_SAME = "@DataAccess(entity) "
22-
+ "value should have same type with injected generic type.";
23-
private static String WARN_NON_GENERIC_VALUE = "@DataAccess annotation assigned "
24-
+ "to raw (non-generic) declaration. This will make your code less type-safe.";
25-
private static String ERROR_CREATE_INSTANCE = "Cannot create instance of "
26-
+ "type '{}' or instance creation is failed because: {}";
20+
private static String ERROR_ENTITY_VALUE_NOT_SAME = "@DataAccess(entity) " + "value should have same type with injected generic type.";
21+
private static String WARN_NON_GENERIC_VALUE = "@DataAccess annotation assigned " + "to raw (non-generic) declaration. This will make your code less type-safe.";
22+
private static String ERROR_CREATE_INSTANCE = "Cannot create instance of " + "type '{}' or instance creation is failed because: {}";
2723

2824
private ConfigurableListableBeanFactory configurableListableBeanFactory;
2925
private Object bean;
@@ -34,15 +30,14 @@ public DataAccessFieldCallback(final ConfigurableListableBeanFactory bf, final O
3430
}
3531

3632
@Override
37-
public void doWith(final Field field)
38-
throws IllegalArgumentException, IllegalAccessException {
33+
public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
3934
if (!field.isAnnotationPresent(DataAccess.class)) {
4035
return;
4136
}
4237
ReflectionUtils.makeAccessible(field);
4338
final Type fieldGenericType = field.getGenericType();
44-
// In this example, get actual "GenericDAO' type.
45-
final Class<?> generic = field.getType();
39+
// In this example, get actual "GenericDAO' type.
40+
final Class<?> generic = field.getType();
4641
final Class<?> classValue = field.getDeclaredAnnotation(DataAccess.class).entity();
4742

4843
if (genericTypeIsValid(classValue, fieldGenericType)) {
@@ -54,7 +49,6 @@ public void doWith(final Field field)
5449
}
5550
}
5651

57-
5852
/**
5953
* For example, if user write:
6054
* <pre>
@@ -75,8 +69,6 @@ public boolean genericTypeIsValid(final Class<?> clazz, final Type field) {
7569
}
7670
}
7771

78-
79-
8072
public final Object getBeanInstance(final String beanName, final Class<?> genericClass, final Class<?> paramClass) {
8173
Object daoInstance = null;
8274
if (!configurableListableBeanFactory.containsBean(beanName)) {
@@ -90,7 +82,7 @@ public final Object getBeanInstance(final String beanName, final Class<?> generi
9082
logger.error(ERROR_CREATE_INSTANCE, genericClass.getTypeName(), e);
9183
throw new RuntimeException(e);
9284
}
93-
85+
9486
daoInstance = configurableListableBeanFactory.initializeBean(toRegister, beanName);
9587
configurableListableBeanFactory.autowireBeanProperties(daoInstance, AUTOWIRE_MODE, true);
9688
configurableListableBeanFactory.registerSingleton(beanName, daoInstance);

‎spring-all/src/test/java/org/baeldung/customannotation/BeanWithGenericDAO.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
@Repository
66
public class BeanWithGenericDAO {
77

8-
@DataAccess(entity=Person.class)
8+
@DataAccess(entity = Person.class)
99
private GenericDAO<Person> personGenericDAO;
1010

11-
public BeanWithGenericDAO() {}
11+
public BeanWithGenericDAO() {
12+
}
1213

1314
public GenericDAO<Person> getPersonGenericDAO() {
1415
return personGenericDAO;

‎spring-all/src/test/java/org/baeldung/customannotation/DataAccessFieldCallbackTest.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.springframework.test.context.ContextConfiguration;
1616
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1717

18-
1918
@RunWith(SpringJUnit4ClassRunner.class)
2019
@ContextConfiguration(classes = { CustomAnnotationConfiguration.class })
2120
public class DataAccessFieldCallbackTest {
@@ -36,8 +35,7 @@ public void whenObjectCreated_thenObjectCreationIsSuccessful() {
3635
}
3736

3837
@Test
39-
public void whenMethodGenericTypeIsValidCalled_thenReturnCorrectValue()
40-
throws NoSuchFieldException, SecurityException {
38+
public void whenMethodGenericTypeIsValidCalled_thenReturnCorrectValue() throws NoSuchFieldException, SecurityException {
4139
final DataAccessFieldCallback callback = new DataAccessFieldCallback(configurableListableBeanFactory, beanWithGenericDAO);
4240
final Type fieldType = BeanWithGenericDAO.class.getDeclaredField("personGenericDAO").getGenericType();
4341
final boolean result = callback.genericTypeIsValid(Person.class, fieldType);

‎spring-batch/src/main/java/org/baeldung/spring_batch_intro/SpringBatchConfig.java‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class SpringBatchConfig {
4040
private Resource outputXml;
4141

4242
@Bean
43-
public ItemReader<Transaction> itemReader()
44-
throws UnexpectedInputException, ParseException {
43+
public ItemReader<Transaction> itemReader() throws UnexpectedInputException, ParseException {
4544
FlatFileItemReader<Transaction> reader = new FlatFileItemReader<Transaction>();
4645
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
4746
String[] tokens = { "username", "userid", "transactiondate", "amount" };
@@ -61,8 +60,7 @@ public ItemProcessor<Transaction, Transaction> itemProcessor() {
6160
}
6261

6362
@Bean
64-
public ItemWriter<Transaction> itemWriter(Marshaller marshaller)
65-
throws MalformedURLException {
63+
public ItemWriter<Transaction> itemWriter(Marshaller marshaller) throws MalformedURLException {
6664
StaxEventItemWriter<Transaction> itemWriter = new StaxEventItemWriter<Transaction>();
6765
itemWriter.setMarshaller(marshaller);
6866
itemWriter.setRootTagName("transactionRecord");
@@ -78,11 +76,8 @@ public Marshaller marshaller() {
7876
}
7977

8078
@Bean
81-
protected Step step1(ItemReader<Transaction> reader,
82-
ItemProcessor<Transaction, Transaction> processor,
83-
ItemWriter<Transaction> writer) {
84-
return steps.get("step1").<Transaction, Transaction> chunk(10)
85-
.reader(reader).processor(processor).writer(writer).build();
79+
protected Step step1(ItemReader<Transaction> reader, ItemProcessor<Transaction, Transaction> processor, ItemWriter<Transaction> writer) {
80+
return steps.get("step1").<Transaction, Transaction> chunk(10).reader(reader).processor(processor).writer(writer).build();
8681
}
8782

8883
@Bean(name = "firstBatchJob")

‎spring-batch/src/main/java/org/baeldung/spring_batch_intro/SpringConfig.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public DataSource dataSource() {
3838
}
3939

4040
@Bean
41-
public DataSourceInitializer dataSourceInitializer(DataSource dataSource)
42-
throws MalformedURLException {
41+
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) throws MalformedURLException {
4342
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
4443

4544
databasePopulator.addScript(dropReopsitoryTables);

‎spring-batch/src/main/java/org/baeldung/spring_batch_intro/model/Transaction.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public void setAmount(double amount) {
4848

4949
@Override
5050
public String toString() {
51-
return "Transaction [username=" + username + ", userId=" + userId
52-
+ ", transactionDate=" + transactionDate + ", amount=" + amount
53-
+ "]";
51+
return "Transaction [username=" + username + ", userId=" + userId + ", transactionDate=" + transactionDate + ", amount=" + amount + "]";
5452
}
5553

5654
}

‎spring-batch/src/main/java/org/baeldung/spring_batch_intro/service/CustomItemProcessor.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import org.baeldung.spring_batch_intro.model.Transaction;
44
import org.springframework.batch.item.ItemProcessor;
55

6-
public class CustomItemProcessor implements
7-
ItemProcessor<Transaction, Transaction> {
6+
public class CustomItemProcessor implements ItemProcessor<Transaction, Transaction> {
87

98
public Transaction process(Transaction item) {
109
System.out.println("Processing..." + item);

0 commit comments

Comments
 (0)