Skip to content

Commit b5f2e56

Browse files
committed
Polishing
1 parent 594f4d5 commit b5f2e56

File tree

15 files changed

+99
-88
lines changed

15 files changed

+99
-88
lines changed

spring-core/src/main/java/org/springframework/core/Conventions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private static String pluralize(String name) {
281281

282282
/**
283283
* Retrieves the {@code Class} of an element in the {@code Collection}.
284-
* The exact element for which the {@code Class} is retreived will depend
284+
* The exact element for which the {@code Class} is retrieved will depend
285285
* on the concrete {@code Collection} implementation.
286286
*/
287287
private static <E> E peekAhead(Collection<E> collection) {

spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java

Lines changed: 8 additions & 4 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-2016 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.
@@ -36,18 +36,21 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
3636

3737
private final ConversionService conversionService;
3838

39+
3940
public CollectionToStringConverter(ConversionService conversionService) {
4041
this.conversionService = conversionService;
4142
}
4243

44+
4345
@Override
4446
public Set<ConvertiblePair> getConvertibleTypes() {
4547
return Collections.singleton(new ConvertiblePair(Collection.class, String.class));
4648
}
4749

4850
@Override
4951
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
50-
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
52+
return ConversionUtils.canConvertElements(
53+
sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
5154
}
5255

5356
@Override
@@ -56,7 +59,7 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
5659
return null;
5760
}
5861
Collection<?> sourceCollection = (Collection<?>) source;
59-
if (sourceCollection.size() == 0) {
62+
if (sourceCollection.isEmpty()) {
6063
return "";
6164
}
6265
StringBuilder sb = new StringBuilder();
@@ -65,7 +68,8 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
6568
if (i > 0) {
6669
sb.append(DELIMITER);
6770
}
68-
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType);
71+
Object targetElement = this.conversionService.convert(
72+
sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType);
6973
sb.append(targetElement);
7074
i++;
7175
}

spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ public void removeConvertible(Class<?> sourceType, Class<?> targetType) {
145145

146146
@Override
147147
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
148-
Assert.notNull(targetType, "targetType to convert to cannot be null");
148+
Assert.notNull(targetType, "Target type to convert to cannot be null");
149149
return canConvert((sourceType != null ? TypeDescriptor.valueOf(sourceType) : null),
150150
TypeDescriptor.valueOf(targetType));
151151
}
152152

153153
@Override
154154
public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
155-
Assert.notNull(targetType, "targetType to convert to cannot be null");
155+
Assert.notNull(targetType, "Target type to convert to cannot be null");
156156
if (sourceType == null) {
157157
return true;
158158
}
@@ -161,9 +161,9 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
161161
}
162162

163163
/**
164-
* Return whether conversion between the sourceType and targetType can be bypassed.
164+
* Return whether conversion between the source type and the target type can be bypassed.
165165
* <p>More precisely, this method will return true if objects of sourceType can be
166-
* converted to the targetType by returning the source object unchanged.
166+
* converted to the target type by returning the source object unchanged.
167167
* @param sourceType context about the source type to convert from
168168
* (may be {@code null} if source is {@code null})
169169
* @param targetType context about the target type to convert to (required)
@@ -172,7 +172,7 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
172172
* @since 3.2
173173
*/
174174
public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor targetType) {
175-
Assert.notNull(targetType, "targetType to convert to cannot be null");
175+
Assert.notNull(targetType, "Target type to convert to cannot be null");
176176
if (sourceType == null) {
177177
return true;
178178
}
@@ -183,20 +183,20 @@ public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor target
183183
@Override
184184
@SuppressWarnings("unchecked")
185185
public <T> T convert(Object source, Class<T> targetType) {
186-
Assert.notNull(targetType, "targetType to convert to cannot be null");
186+
Assert.notNull(targetType, "Target type to convert to cannot be null");
187187
return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType));
188188
}
189189

190190
@Override
191191
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
192-
Assert.notNull(targetType, "targetType to convert to cannot be null");
192+
Assert.notNull(targetType, "Target type to convert to cannot be null");
193193
if (sourceType == null) {
194-
Assert.isTrue(source == null, "source must be [null] if sourceType == [null]");
194+
Assert.isTrue(source == null, "Source must be [null] if source type == [null]");
195195
return handleResult(null, targetType, convertNullSource(null, targetType));
196196
}
197197
if (source != null && !sourceType.getObjectType().isInstance(source)) {
198-
throw new IllegalArgumentException("source to convert from must be an instance of " +
199-
sourceType + "; instead it was a " + source.getClass().getName());
198+
throw new IllegalArgumentException("Source to convert from must be an instance of [" +
199+
sourceType + "]; instead it was a [" + source.getClass().getName() + "]");
200200
}
201201
GenericConverter converter = getConverter(sourceType, targetType);
202202
if (converter != null) {
@@ -208,9 +208,9 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
208208

209209
/**
210210
* Convenience operation for converting a source object to the specified targetType,
211-
* where the targetType is a descriptor that provides additional conversion context.
211+
* where the target type is a descriptor that provides additional conversion context.
212212
* Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and
213-
* encapsulates the construction of the sourceType descriptor using
213+
* encapsulates the construction of the source type descriptor using
214214
* {@link TypeDescriptor#forObject(Object)}.
215215
* @param source the source object
216216
* @param targetType the target type
@@ -237,8 +237,8 @@ public String toString() {
237237
* {@link java.util.Optional#empty()} instance if the target type is
238238
* {@code java.util.Optional}. Subclasses may override this to return
239239
* custom {@code null} objects for specific target types.
240-
* @param sourceType the sourceType to convert from
241-
* @param targetType the targetType to convert to
240+
* @param sourceType the source type to convert from
241+
* @param targetType the target type to convert to
242242
* @return the converted null object
243243
*/
244244
protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) {
@@ -282,7 +282,7 @@ protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescripto
282282

283283
/**
284284
* Return the default converter if no converter is found for the given sourceType/targetType pair.
285-
* <p>Returns a NO_OP Converter if the sourceType is assignable to the targetType.
285+
* <p>Returns a NO_OP Converter if the source type is assignable to the target type.
286286
* Returns {@code null} otherwise, indicating no suitable converter could be found.
287287
* @param sourceType the source type to convert from
288288
* @param targetType the target type to convert to

spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java

Lines changed: 5 additions & 5 deletions
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-2016 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.
@@ -68,13 +68,13 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
6868
else if (source instanceof Optional) {
6969
return source;
7070
}
71-
else if (targetType.getResolvableType() == null) {
72-
return Optional.of(source);
73-
}
74-
else {
71+
else if (targetType.getResolvableType() != null) {
7572
Object target = this.conversionService.convert(source, sourceType, new GenericTypeDescriptor(targetType));
7673
return Optional.ofNullable(target);
7774
}
75+
else {
76+
return Optional.of(source);
77+
}
7878
}
7979

8080

spring-core/src/test/java/org/springframework/util/xml/AbstractStaxHandlerTestCase.java

Lines changed: 5 additions & 7 deletions
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-2016 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.
@@ -19,7 +19,6 @@
1919
import java.io.StringReader;
2020
import java.io.StringWriter;
2121
import java.net.Socket;
22-
2322
import javax.xml.parsers.DocumentBuilder;
2423
import javax.xml.parsers.DocumentBuilderFactory;
2524
import javax.xml.stream.XMLStreamException;
@@ -30,7 +29,6 @@
3029
import org.junit.Assume;
3130
import org.junit.Before;
3231
import org.junit.Test;
33-
3432
import org.w3c.dom.Document;
3533
import org.xml.sax.InputSource;
3634
import org.xml.sax.XMLReader;
@@ -58,11 +56,13 @@ public abstract class AbstractStaxHandlerTestCase {
5856

5957
private XMLReader xmlReader;
6058

59+
6160
@Before
6261
public void createXMLReader() throws Exception {
6362
xmlReader = XMLReaderFactory.createXMLReader();
6463
}
6564

65+
6666
@Test
6767
public void noNamespacePrefixes() throws Exception {
6868
Assume.assumeTrue(wwwSpringframeworkOrgIsAccessible());
@@ -109,8 +109,7 @@ public void namespacePrefixes() throws Exception {
109109

110110
@Test
111111
public void noNamespacePrefixesDom() throws Exception {
112-
DocumentBuilderFactory documentBuilderFactory =
113-
DocumentBuilderFactory.newInstance();
112+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
114113
documentBuilderFactory.setNamespaceAware(true);
115114
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
116115

@@ -131,8 +130,7 @@ public void noNamespacePrefixesDom() throws Exception {
131130

132131
@Test
133132
public void namespacePrefixesDom() throws Exception {
134-
DocumentBuilderFactory documentBuilderFactory =
135-
DocumentBuilderFactory.newInstance();
133+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
136134
documentBuilderFactory.setNamespaceAware(true);
137135
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
138136

spring-core/src/test/java/org/springframework/util/xml/StaxEventHandlerTests.java

Lines changed: 2 additions & 3 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-2016 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.
@@ -27,8 +27,7 @@
2727
public class StaxEventHandlerTests extends AbstractStaxHandlerTestCase {
2828

2929
@Override
30-
protected AbstractStaxHandler createStaxHandler(Result result)
31-
throws XMLStreamException {
30+
protected AbstractStaxHandler createStaxHandler(Result result) throws XMLStreamException {
3231
XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
3332
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(result);
3433
return new StaxEventHandler(eventWriter);

spring-core/src/test/java/org/springframework/util/xml/StaxStreamHandlerTests.java

Lines changed: 2 additions & 3 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-2016 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.
@@ -27,8 +27,7 @@
2727
public class StaxStreamHandlerTests extends AbstractStaxHandlerTestCase {
2828

2929
@Override
30-
protected AbstractStaxHandler createStaxHandler(Result result)
31-
throws XMLStreamException {
30+
protected AbstractStaxHandler createStaxHandler(Result result) throws XMLStreamException {
3231
XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
3332
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(result);
3433
return new StaxStreamHandler(streamWriter);

spring-oxm/src/main/java/org/springframework/oxm/Marshaller.java

Lines changed: 3 additions & 3 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-2016 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.
@@ -35,15 +35,15 @@
3535
public interface Marshaller {
3636

3737
/**
38-
* Indicates whether this marshaller can marshal instances of the supplied type.
38+
* Indicate whether this marshaller can marshal instances of the supplied type.
3939
* @param clazz the class that this marshaller is being asked if it can marshal
4040
* @return {@code true} if this marshaller can indeed marshal instances of the supplied class;
4141
* {@code false} otherwise
4242
*/
4343
boolean supports(Class<?> clazz);
4444

4545
/**
46-
* Marshals the object graph with the given root into the provided {@link Result}.
46+
* Marshal the object graph with the given root into the provided {@link Result}.
4747
* @param graph the root of the object graph to marshal
4848
* @param result the result to marshal to
4949
* @throws IOException if an I/O error occurs

spring-oxm/src/main/java/org/springframework/oxm/Unmarshaller.java

Lines changed: 3 additions & 3 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-2016 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.
@@ -30,15 +30,15 @@
3030
public interface Unmarshaller {
3131

3232
/**
33-
* Indicates whether this unmarshaller can unmarshal instances of the supplied type.
33+
* Indicate whether this unmarshaller can unmarshal instances of the supplied type.
3434
* @param clazz the class that this unmarshaller is being asked if it can marshal
3535
* @return {@code true} if this unmarshaller can indeed unmarshal to the supplied class;
3636
* {@code false} otherwise
3737
*/
3838
boolean supports(Class<?> clazz);
3939

4040
/**
41-
* Unmarshals the given {@link Source} into an object graph.
41+
* Unmarshal the given {@link Source} into an object graph.
4242
* @param source the source to marshal from
4343
* @return the object graph
4444
* @throws IOException if an I/O error occurs

0 commit comments

Comments
 (0)