Skip to content

Commit 85b5c5a

Browse files
committed
Polishing
1 parent ed9afa3 commit 85b5c5a

File tree

18 files changed

+118
-115
lines changed

18 files changed

+118
-115
lines changed

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,8 +43,10 @@
4343
* Decorator for a standard {@link BeanInfo} object, e.g. as created by
4444
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
4545
* and/or non-void returning setter methods. For example:
46+
*
4647
* <pre class="code">
4748
* public class Bean {
49+
*
4850
* private Foo foo;
4951
*
5052
* public Foo getFoo() {
@@ -56,6 +58,7 @@
5658
* return this;
5759
* }
5860
* }</pre>
61+
*
5962
* The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read
6063
* method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void
6164
* returning signature does not comply with the JavaBeans specification.
@@ -68,6 +71,7 @@
6871
* indexed properties</a> are fully supported.
6972
*
7073
* @author Chris Beams
74+
* @author Juergen Hoeller
7175
* @since 3.1
7276
* @see #ExtendedBeanInfo(BeanInfo)
7377
* @see ExtendedBeanInfoFactory

spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void customAsyncAnnotationIsPropagated() {
161161
Object bean = ctx.getBean(CustomAsyncBean.class);
162162
assertTrue(AopUtils.isAopProxy(bean));
163163
boolean isAsyncAdvised = false;
164-
for (Advisor advisor : ((Advised)bean).getAdvisors()) {
164+
for (Advisor advisor : ((Advised) bean).getAdvisors()) {
165165
if (advisor instanceof AsyncAnnotationAdvisor) {
166166
isAsyncAdvised = true;
167167
break;
@@ -365,7 +365,8 @@ public AsyncBean asyncBean() {
365365
@EnableAsync
366366
static class AsyncConfigWithMockito {
367367

368-
@Bean @Lazy
368+
@Bean
369+
@Lazy
369370
public AsyncBean asyncBean() {
370371
return Mockito.mock(AsyncBean.class);
371372
}

spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,28 +23,29 @@
2323
import org.springframework.jndi.JndiTemplate;
2424

2525
/**
26-
* Simple extension of the JndiTemplate class that always returns
27-
* a given object. Very useful for testing. Effectively a mock object.
26+
* Simple extension of the JndiTemplate class that always returns a given object.
27+
*
28+
* <p>Very useful for testing. Effectively a mock object.
2829
*
2930
* @author Rod Johnson
3031
* @author Juergen Hoeller
3132
*/
3233
public class ExpectedLookupTemplate extends JndiTemplate {
3334

34-
private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>();
35+
private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>(16);
3536

3637

3738
/**
38-
* Construct a new JndiTemplate that will always return given objects
39-
* for given names. To be populated through {@code addObject} calls.
39+
* Construct a new JndiTemplate that will always return given objects for
40+
* given names. To be populated through {@code addObject} calls.
4041
* @see #addObject(String, Object)
4142
*/
4243
public ExpectedLookupTemplate() {
4344
}
4445

4546
/**
46-
* Construct a new JndiTemplate that will always return the
47-
* given object, but honour only requests for the given name.
47+
* Construct a new JndiTemplate that will always return the given object,
48+
* but honour only requests for the given name.
4849
* @param name the name the client is expected to look up
4950
* @param object the object that will be returned
5051
*/
@@ -54,20 +55,18 @@ public ExpectedLookupTemplate(String name, Object object) {
5455

5556

5657
/**
57-
* Add the given object to the list of JNDI objects that this
58-
* template will expose.
58+
* Add the given object to the list of JNDI objects that this template will expose.
5959
* @param name the name the client is expected to look up
6060
* @param object the object that will be returned
6161
*/
6262
public void addObject(String name, Object object) {
6363
this.jndiObjects.put(name, object);
6464
}
6565

66-
6766
/**
68-
* If the name is the expected name specified in the constructor,
69-
* return the object provided in the constructor. If the name is
70-
* unexpected, a respective NamingException gets thrown.
67+
* If the name is the expected name specified in the constructor, return the
68+
* object provided in the constructor. If the name is unexpected, a
69+
* respective NamingException gets thrown.
7170
*/
7271
@Override
7372
public Object lookup(String name) throws NamingException {

spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
2828

29+
import org.springframework.util.Assert;
2930
import org.springframework.util.ClassUtils;
3031

3132
/**
@@ -35,13 +36,14 @@
3536
* configure JNDI appropriately, so that {@code new InitialContext()}
3637
* will expose the required objects. Also usable for standalone applications,
3738
* e.g. for binding a JDBC DataSource to a well-known JNDI location, to be
38-
* able to use traditional J2EE data access code outside of a J2EE container.
39+
* able to use traditional Java EE data access code outside of a Java EE
40+
* container.
3941
*
4042
* <p>There are various choices for DataSource implementations:
4143
* <ul>
4244
* <li>{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
4345
* <li>{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
44-
* <li>Apache's Jakarta Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
46+
* <li>Apache's Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
4547
* </ul>
4648
*
4749
* <p>Typical usage in bootstrap code:
@@ -98,7 +100,7 @@ public static SimpleNamingContextBuilder getCurrentContextBuilder() {
98100

99101
/**
100102
* If no SimpleNamingContextBuilder is already configuring JNDI,
101-
* create and activate one. Otherwise take the existing activate
103+
* create and activate one. Otherwise take the existing activated
102104
* SimpleNamingContextBuilder, clear it and return it.
103105
* <p>This is mainly intended for test suites that want to
104106
* reinitialize JNDI bindings from scratch repeatedly.
@@ -137,12 +139,10 @@ public void activate() throws IllegalStateException, NamingException {
137139
logger.info("Activating simple JNDI environment");
138140
synchronized (initializationLock) {
139141
if (!initialized) {
140-
if (NamingManager.hasInitialContextFactoryBuilder()) {
141-
throw new IllegalStateException(
142+
Assert.state(!NamingManager.hasInitialContextFactoryBuilder(),
142143
"Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
143144
"Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
144145
"with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
145-
}
146146
NamingManager.setInitialContextFactoryBuilder(this);
147147
initialized = true;
148148
}

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -170,7 +170,7 @@ public static boolean containsElement(Object[] array, Object element) {
170170
/**
171171
* Check whether the given array of enum constants contains a constant with the given name,
172172
* ignoring case when determining a match.
173-
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
173+
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
174174
* @param constant the constant name to find (must not be null or empty string)
175175
* @return whether the constant has been found in the given array
176176
*/
@@ -180,15 +180,14 @@ public static boolean containsConstant(Enum<?>[] enumValues, String constant) {
180180

181181
/**
182182
* Check whether the given array of enum constants contains a constant with the given name.
183-
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
183+
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
184184
* @param constant the constant name to find (must not be null or empty string)
185185
* @param caseSensitive whether case is significant in determining a match
186186
* @return whether the constant has been found in the given array
187187
*/
188188
public static boolean containsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive) {
189189
for (Enum<?> candidate : enumValues) {
190-
if (caseSensitive ?
191-
candidate.toString().equals(constant) :
190+
if (caseSensitive ? candidate.toString().equals(constant) :
192191
candidate.toString().equalsIgnoreCase(constant)) {
193192
return true;
194193
}
@@ -199,7 +198,7 @@ public static boolean containsConstant(Enum<?>[] enumValues, String constant, bo
199198
/**
200199
* Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
201200
* @param <E> the concrete Enum type
202-
* @param enumValues the array of all Enum constants in question, usually per Enum.values()
201+
* @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()}
203202
* @param constant the constant to get the enum value of
204203
* @throws IllegalArgumentException if the given constant is not found in the given array
205204
* of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
@@ -210,9 +209,8 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
210209
return candidate;
211210
}
212211
}
213-
throw new IllegalArgumentException(
214-
String.format("constant [%s] does not exist in enum type %s",
215-
constant, enumValues.getClass().getComponentType().getName()));
212+
throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " +
213+
enumValues.getClass().getComponentType().getName());
216214
}
217215

218216
/**

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.sql.SQLException;
2626
import java.util.ArrayList;
2727
import java.util.Arrays;
28-
import java.util.LinkedList;
2928
import java.util.List;
3029
import java.util.Map;
3130

@@ -635,7 +634,7 @@ private static List<Method> findConcreteMethodsOnInterfaces(Class<?> clazz) {
635634
for (Method ifcMethod : ifc.getMethods()) {
636635
if (!Modifier.isAbstract(ifcMethod.getModifiers())) {
637636
if (result == null) {
638-
result = new LinkedList<Method>();
637+
result = new ArrayList<Method>();
639638
}
640639
result.add(ifcMethod);
641640
}

spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class ObjectUtilsTests {
4545
@Rule
4646
public final ExpectedException exception = ExpectedException.none();
4747

48+
4849
@Test
4950
public void isCheckedException() {
5051
assertTrue(ObjectUtils.isCheckedException(new Exception()));
@@ -101,8 +102,8 @@ public void isEmptyArray() {
101102
assertTrue(isEmpty(new Object[0]));
102103
assertTrue(isEmpty(new Integer[0]));
103104

104-
assertFalse(isEmpty(new int[] { 42 }));
105-
assertFalse(isEmpty(new Integer[] { new Integer(42) }));
105+
assertFalse(isEmpty(new int[] {42}));
106+
assertFalse(isEmpty(new Integer[] {42}));
106107
}
107108

108109
@Test
@@ -271,7 +272,7 @@ public void hashCodeWithFloat() {
271272
@Test
272273
@Deprecated
273274
public void hashCodeWithLong() {
274-
long lng = 883l;
275+
long lng = 883L;
275276
int expected = (new Long(lng)).hashCode();
276277
assertEquals(expected, ObjectUtils.hashCode(lng));
277278
}
@@ -489,12 +490,12 @@ public void nullSafeHashCodeWithIntArrayEqualToNull() {
489490

490491
@Test
491492
public void nullSafeHashCodeWithLongArray() {
492-
long lng = 7993l;
493+
long lng = 7993L;
493494
int expected = 31 * 7 + (int) (lng ^ (lng >>> 32));
494-
lng = 84320l;
495+
lng = 84320L;
495496
expected = 31 * expected + (int) (lng ^ (lng >>> 32));
496497

497-
long[] array = {7993l, 84320l};
498+
long[] array = {7993L, 84320L};
498499
int actual = ObjectUtils.nullSafeHashCode(array);
499500

500501
assertEquals(expected, actual);
@@ -715,7 +716,7 @@ public void nullSafeToStringWithIntArrayEqualToNull() {
715716

716717
@Test
717718
public void nullSafeToStringWithLongArray() {
718-
long[] array = {434l, 23423l};
719+
long[] array = {434L, 23423L};
719720
assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array));
720721
}
721722

@@ -737,7 +738,7 @@ public void nullSafeToStringWithPlainOldString() {
737738

738739
@Test
739740
public void nullSafeToStringWithObjectArray() {
740-
Object[] array = {"Han", new Long(43)};
741+
Object[] array = {"Han", Long.valueOf(43)};
741742
assertEquals("{Han, 43}", ObjectUtils.nullSafeToString(array));
742743
}
743744

@@ -807,7 +808,8 @@ public void caseInsensitiveValueOf() {
807808
assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "BAR"), is(Tropes.BAR));
808809

809810
exception.expect(IllegalArgumentException.class);
810-
exception.expectMessage(is("constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"));
811+
exception.expectMessage(
812+
is("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"));
811813
ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus");
812814
}
813815

@@ -818,6 +820,6 @@ private void assertEqualHashCodes(int expected, Object array) {
818820
}
819821

820822

821-
enum Tropes { FOO, BAR, baz }
823+
enum Tropes {FOO, BAR, baz}
822824

823825
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -914,6 +914,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
914914
* @param pss ParameterizedPreparedStatementSetter to use
915915
* @return an array containing for each batch another array containing the numbers of rows affected
916916
* by each update in the batch
917+
* @since 3.1
917918
*/
918919
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
919920
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1018,11 +1018,7 @@ public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final
10181018
public int[][] doInPreparedStatement(PreparedStatement ps) throws SQLException {
10191019
List<int[]> rowsAffected = new ArrayList<int[]>();
10201020
try {
1021-
boolean batchSupported = true;
1022-
if (!JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
1023-
batchSupported = false;
1024-
logger.warn("JDBC Driver does not support Batch updates; resorting to single statement execution");
1025-
}
1021+
boolean batchSupported = JdbcUtils.supportsBatchUpdates(ps.getConnection());
10261022
int n = 0;
10271023
for (T obj : batchArgs) {
10281024
pss.setValues(ps, obj);

0 commit comments

Comments
 (0)