Skip to content

Commit 4cef52a

Browse files
committed
polishing
1 parent de866a0 commit 4cef52a

File tree

7 files changed

+128
-109
lines changed

7 files changed

+128
-109
lines changed

org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 89 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public class TypeDescriptor {
6464
typeDescriptorCache.put(Double.class, new TypeDescriptor(Double.class));
6565
typeDescriptorCache.put(String.class, new TypeDescriptor(String.class));
6666
}
67-
67+
68+
6869
private Class<?> type;
6970

7071
private MethodParameter methodParameter;
@@ -81,6 +82,7 @@ public class TypeDescriptor {
8182

8283
private Annotation[] annotations;
8384

85+
8486
/**
8587
* Create a new type descriptor from a method or constructor parameter.
8688
* <p>Use this constructor when a target conversion point originates from a method parameter,
@@ -127,38 +129,36 @@ public TypeDescriptor(Field field, Class<?> type) {
127129
this.type = type;
128130
}
129131

130-
// static factory methods
132+
/**
133+
* Internal constructor for a NULL descriptor.
134+
*/
135+
private TypeDescriptor() {
136+
}
131137

132138
/**
133-
* Create a new type descriptor for the class of the given object.
134-
* @param object the object
135-
* @return the type descriptor
139+
* Create a new descriptor for the type of the given value.
140+
* <p>Use this constructor when a conversion point comes from a source such as a Map or
141+
* Collection, where no additional context is available but elements can be introspected.
142+
* @param type the actual type to wrap
136143
*/
137-
public static TypeDescriptor forObject(Object object) {
138-
if (object == null) {
139-
return NULL;
140-
}
141-
else if (object instanceof Collection<?> || object instanceof Map<?, ?>) {
142-
return new TypeDescriptor(object);
143-
}
144-
else {
145-
return valueOf(object.getClass());
146-
}
144+
private TypeDescriptor(Object value) {
145+
Assert.notNull(value, "Value must not be null");
146+
this.value = value;
147+
this.type = value.getClass();
147148
}
148-
149+
149150
/**
150-
* Create a new type descriptor for the given class.
151-
* @param type the class
152-
* @return the type descriptor
151+
* Create a new descriptor for the given type.
152+
* <p>Use this constructor when a conversion point comes from a plain source type,
153+
* where no additional context is available.
154+
* @param type the actual type to wrap
153155
*/
154-
public static TypeDescriptor valueOf(Class<?> type) {
155-
if (type == null) {
156-
return TypeDescriptor.NULL;
157-
}
158-
TypeDescriptor desc = typeDescriptorCache.get(type);
159-
return (desc != null ? desc : new TypeDescriptor(type));
156+
private TypeDescriptor(Class<?> type) {
157+
Assert.notNull(type, "Type must not be null");
158+
this.type = type;
160159
}
161160

161+
162162
/**
163163
* Return the wrapped MethodParameter, if any.
164164
* <p>Note: Either MethodParameter or Field is available.
@@ -255,13 +255,14 @@ public synchronized TypeDescriptor getElementTypeDescriptor() {
255255
}
256256

257257
/**
258-
* Return the element type as a type descriptor; if the element type is null (cannot be determined), the type descriptor is derived from the element argument.
258+
* Return the element type as a type descriptor; if the element type is null (cannot be determined),
259+
* the type descriptor is derived from the element argument.
259260
* @param element the element
260261
* @return the element type descriptor
261262
*/
262263
public TypeDescriptor getElementTypeDescriptor(Object element) {
263264
TypeDescriptor elementType = getElementTypeDescriptor();
264-
return elementType != TypeDescriptor.NULL ? elementType : TypeDescriptor.forObject(element);
265+
return (elementType != TypeDescriptor.NULL ? elementType : forObject(element));
265266
}
266267

267268
/**
@@ -318,20 +319,21 @@ public Class<?> getMapValueType() {
318319
* Returns map value type as a type descriptor.
319320
*/
320321
public synchronized TypeDescriptor getMapValueTypeDescriptor() {
321-
if (mapValueType == null) {
322+
if (this.mapValueType == null) {
322323
mapValueType = forElementType(resolveMapValueType());
323324
}
324-
return mapValueType;
325+
return this.mapValueType;
325326
}
326327

327328
/**
328-
* Return the map value type as a type descriptor; if the value type is null (cannot be determined), the type descriptor is derived from the value argument.
329+
* Return the map value type as a type descriptor; if the value type is null
330+
* (cannot be determined), the type descriptor is derived from the value argument.
329331
* @param value the value
330332
* @return the map value type descriptor
331333
*/
332334
public TypeDescriptor getMapValueTypeDescriptor(Object value) {
333335
TypeDescriptor valueType = getMapValueTypeDescriptor();
334-
return valueType != TypeDescriptor.NULL ? valueType : TypeDescriptor.forObject(value);
336+
return (valueType != TypeDescriptor.NULL ? valueType : TypeDescriptor.forObject(value));
335337
}
336338

337339
/**
@@ -366,10 +368,15 @@ public boolean isAssignableTo(TypeDescriptor targetType) {
366368
return true;
367369
}
368370
if (isCollection() && targetType.isCollection() || isArray() && targetType.isArray()) {
369-
return targetType.getType().isAssignableFrom(getType()) && getElementTypeDescriptor().isAssignableTo(targetType.getElementTypeDescriptor());
370-
} else if (isMap() && targetType.isMap()) {
371-
return targetType.getType().isAssignableFrom(getType()) && getMapKeyTypeDescriptor().isAssignableTo(targetType.getMapKeyTypeDescriptor()) && getMapValueTypeDescriptor().isAssignableTo(targetType.getMapValueTypeDescriptor());
372-
} else {
371+
return targetType.getType().isAssignableFrom(getType()) &&
372+
getElementTypeDescriptor().isAssignableTo(targetType.getElementTypeDescriptor());
373+
}
374+
else if (isMap() && targetType.isMap()) {
375+
return targetType.getType().isAssignableFrom(getType()) &&
376+
getMapKeyTypeDescriptor().isAssignableTo(targetType.getMapKeyTypeDescriptor()) &&
377+
getMapValueTypeDescriptor().isAssignableTo(targetType.getMapValueTypeDescriptor());
378+
}
379+
else {
373380
return targetType.getObjectType().isAssignableFrom(getObjectType());
374381
}
375382
}
@@ -383,14 +390,17 @@ public boolean isAssignableTo(TypeDescriptor targetType) {
383390
public TypeDescriptor forElementType(Class<?> elementType) {
384391
if (getType().equals(elementType)) {
385392
return this;
386-
} else if (elementType == null) {
393+
}
394+
else if (elementType == null) {
387395
return TypeDescriptor.NULL;
388-
} else if (this.methodParameter != null) {
396+
}
397+
else if (this.methodParameter != null) {
389398
return new TypeDescriptor(this.methodParameter, elementType);
390399
}
391400
else if (this.field != null) {
392401
return new TypeDescriptor(this.field, elementType);
393-
} else {
402+
}
403+
else {
394404
return TypeDescriptor.valueOf(elementType);
395405
}
396406
}
@@ -403,12 +413,16 @@ public boolean equals(Object obj) {
403413
if (this == td) {
404414
return true;
405415
}
406-
boolean annotatedTypeEquals = getType().equals(td.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), td.getAnnotations());
416+
boolean annotatedTypeEquals =
417+
getType().equals(td.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), td.getAnnotations());
407418
if (isCollection()) {
408419
return annotatedTypeEquals && ObjectUtils.nullSafeEquals(getElementType(), td.getElementType());
409-
} else if (isMap()) {
410-
return annotatedTypeEquals && ObjectUtils.nullSafeEquals(getMapKeyType(), td.getMapKeyType()) && ObjectUtils.nullSafeEquals(getMapValueType(), td.getMapValueType());
411-
} else {
420+
}
421+
else if (isMap()) {
422+
return annotatedTypeEquals && ObjectUtils.nullSafeEquals(getMapKeyType(), td.getMapKeyType()) &&
423+
ObjectUtils.nullSafeEquals(getMapValueType(), td.getMapValueType());
424+
}
425+
else {
412426
return annotatedTypeEquals;
413427
}
414428
}
@@ -439,8 +453,11 @@ public String toString() {
439453
if (isMap()) {
440454
Class<?> mapKeyType = getMapKeyType();
441455
Class<?> valueKeyType = getMapValueType();
442-
builder.append("<").append(mapKeyType != null ? ClassUtils.getQualifiedName(mapKeyType) : "?").append(", ").append(valueKeyType != null ? ClassUtils.getQualifiedName(valueKeyType) : "?").append(">");
443-
} else if (isCollection()) {
456+
builder.append("<").append(mapKeyType != null ? ClassUtils.getQualifiedName(mapKeyType) : "?");
457+
builder.append(", ").append(valueKeyType != null ? ClassUtils.getQualifiedName(valueKeyType) : "?");
458+
builder.append(">");
459+
}
460+
else if (isCollection()) {
444461
Class<?> elementType = getElementType();
445462
builder.append("<").append(elementType != null ? ClassUtils.getQualifiedName(elementType) : "?").append(">");
446463
}
@@ -481,7 +498,7 @@ else if (this.value instanceof Collection) {
481498
}
482499
}
483500
}
484-
return type != null ? GenericCollectionTypeResolver.getCollectionType((Class<? extends Collection>) this.type) : null;
501+
return (this.type != null ? GenericCollectionTypeResolver.getCollectionType((Class<? extends Collection>) this.type) : null);
485502
}
486503

487504
@SuppressWarnings("unchecked")
@@ -501,7 +518,7 @@ else if (this.value instanceof Map<?, ?>) {
501518
}
502519
}
503520
}
504-
return type != null && isMap() ? GenericCollectionTypeResolver.getMapKeyType((Class<? extends Map>) this.type) : null;
521+
return (this.type != null && isMap() ? GenericCollectionTypeResolver.getMapKeyType((Class<? extends Map>) this.type) : null);
505522
}
506523

507524
@SuppressWarnings("unchecked")
@@ -521,7 +538,7 @@ else if (this.value instanceof Map<?, ?>) {
521538
}
522539
}
523540
}
524-
return isMap() && type != null ? GenericCollectionTypeResolver.getMapValueType((Class<? extends Map>) this.type) : null;
541+
return (isMap() && this.type != null ? GenericCollectionTypeResolver.getMapValueType((Class<? extends Map>) this.type) : null);
525542
}
526543

527544
private Annotation[] resolveAnnotations() {
@@ -540,34 +557,38 @@ else if (this.methodParameter != null) {
540557
return EMPTY_ANNOTATION_ARRAY;
541558
}
542559
}
543-
544-
/**
545-
* Internal constructor for a NULL descriptor.
546-
*/
547-
private TypeDescriptor() {
548-
}
560+
561+
562+
// static factory methods
549563

550564
/**
551-
* Create a new descriptor for the type of the given value.
552-
* <p>Use this constructor when a conversion point comes from a source such as a Map or
553-
* Collection, where no additional context is available but elements can be introspected.
554-
* @param type the actual type to wrap
565+
* Create a new type descriptor for the class of the given object.
566+
* @param object the object
567+
* @return the type descriptor
555568
*/
556-
private TypeDescriptor(Object value) {
557-
Assert.notNull(value, "Value must not be null");
558-
this.value = value;
559-
this.type = value.getClass();
569+
public static TypeDescriptor forObject(Object object) {
570+
if (object == null) {
571+
return NULL;
572+
}
573+
else if (object instanceof Collection<?> || object instanceof Map<?, ?>) {
574+
return new TypeDescriptor(object);
575+
}
576+
else {
577+
return valueOf(object.getClass());
578+
}
560579
}
561580

562581
/**
563-
* Create a new descriptor for the given type.
564-
* <p>Use this constructor when a conversion point comes from a plain source type,
565-
* where no additional context is available.
566-
* @param type the actual type to wrap
582+
* Create a new type descriptor for the given class.
583+
* @param type the class
584+
* @return the type descriptor
567585
*/
568-
private TypeDescriptor(Class<?> type) {
569-
Assert.notNull(type, "Type must not be null");
570-
this.type = type;
586+
public static TypeDescriptor valueOf(Class<?> type) {
587+
if (type == null) {
588+
return TypeDescriptor.NULL;
589+
}
590+
TypeDescriptor desc = typeDescriptorCache.get(type);
591+
return (desc != null ? desc : new TypeDescriptor(type));
571592
}
572593

573594
}

org.springframework.core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuf
7171

7272
/**
7373
* Creates a new <code>PropertyPlaceholderHelper</code> that uses the supplied prefix and suffix.
74-
* @param placeholderPrefix the prefix that denotes the start of a placeholder.
75-
* @param placeholderSuffix the suffix that denotes the end of a placeholder.
74+
* @param placeholderPrefix the prefix that denotes the start of a placeholder
75+
* @param placeholderSuffix the suffix that denotes the end of a placeholder
76+
* @param valueSeparator the separating character between the placeholder variable
77+
* and the associated default value, if any
7678
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should be ignored
7779
* (<code>true</code>) or cause an exception (<code>false</code>).
7880
*/
@@ -158,11 +160,9 @@ protected String parseStringValue(
158160
// previously resolved placeholder value.
159161
propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders);
160162
buf.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal);
161-
162163
if (logger.isTraceEnabled()) {
163164
logger.trace("Resolved placeholder '" + placeholder + "'");
164165
}
165-
166166
startIndex = buf.indexOf(this.placeholderPrefix, startIndex + propVal.length());
167167
}
168168
else if (this.ignoreUnresolvablePlaceholders) {

org.springframework.core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 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.
@@ -550,7 +550,7 @@ public static String stripFilenameExtension(String path) {
550550

551551
/**
552552
* Apply the given relative path to the given path,
553-
* assuming standard Java folder separation (i.e. "/" separators);
553+
* assuming standard Java folder separation (i.e. "/" separators).
554554
* @param path the path to start from (usually a full file path)
555555
* @param relativePath the relative path to apply
556556
* (relative to the full file path above)

org.springframework.web/src/main/java/org/springframework/http/client/CommonsClientHttpRequest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ final class CommonsClientHttpRequest extends AbstractClientHttpRequest {
5353
this.httpMethod = httpMethod;
5454
}
5555

56+
5657
public HttpMethod getMethod() {
57-
return HttpMethod.valueOf(httpMethod.getName());
58+
return HttpMethod.valueOf(this.httpMethod.getName());
5859
}
5960

6061
public URI getURI() {
6162
try {
62-
return URI.create(httpMethod.getURI().getEscapedURI());
63+
return URI.create(this.httpMethod.getURI().getEscapedURI());
6364
}
6465
catch (URIException ex) {
6566
throw new IllegalStateException("Could not get HttpMethod URI: " + ex.getMessage(), ex);
@@ -74,13 +75,13 @@ public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) th
7475
httpMethod.addRequestHeader(headerName, headerValue);
7576
}
7677
}
77-
if (httpMethod instanceof EntityEnclosingMethod) {
78-
EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;
78+
if (this.httpMethod instanceof EntityEnclosingMethod) {
79+
EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod;
7980
RequestEntity requestEntity = new ByteArrayRequestEntity(output);
8081
entityEnclosingMethod.setRequestEntity(requestEntity);
8182
}
82-
httpClient.executeMethod(httpMethod);
83-
return new CommonsClientHttpResponse(httpMethod);
83+
this.httpClient.executeMethod(this.httpMethod);
84+
return new CommonsClientHttpResponse(this.httpMethod);
8485
}
8586

8687
}

0 commit comments

Comments
 (0)