Browse Source

renamed mapKey/ValueTypeDescriptor methods back to getMapKey/ValueTypeDescriptor (for Spring 3.0.x compatibility)

pull/7/head
Juergen Hoeller 13 years ago
parent
commit
1cea52b66b
  1. 100
      org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
  2. 4
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
  3. 8
      org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java
  4. 2
      org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

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

@ -382,7 +382,7 @@ public class TypeDescriptor { @@ -382,7 +382,7 @@ public class TypeDescriptor {
* @throws IllegalStateException if this type is not a java.util.Map.
* @see #narrow(Object)
*/
public TypeDescriptor mapKeyTypeDescriptor(Object mapKey) {
public TypeDescriptor getMapKeyTypeDescriptor(Object mapKey) {
return narrow(mapKey, getMapKeyTypeDescriptor());
}
@ -407,55 +407,10 @@ public class TypeDescriptor { @@ -407,55 +407,10 @@ public class TypeDescriptor {
* @return the map value type descriptor
* @throws IllegalStateException if this type is not a java.util.Map.
*/
public TypeDescriptor mapValueTypeDescriptor(Object mapValue) {
public TypeDescriptor getMapValueTypeDescriptor(Object mapValue) {
return narrow(mapValue, getMapValueTypeDescriptor());
}
// extending Object
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof TypeDescriptor)) {
return false;
}
TypeDescriptor other = (TypeDescriptor) obj;
boolean annotatedTypeEquals = ObjectUtils.nullSafeEquals(getType(), other.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), other.getAnnotations());
if (!annotatedTypeEquals) {
return false;
}
if (isCollection() || isArray()) {
return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor());
}
else if (isMap()) {
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor());
}
else {
return true;
}
}
public int hashCode() {
return getType().hashCode();
}
public String toString() {
StringBuilder builder = new StringBuilder();
Annotation[] anns = getAnnotations();
for (Annotation ann : anns) {
builder.append("@").append(ann.annotationType().getName()).append(' ');
}
builder.append(ClassUtils.getQualifiedName(getType()));
if (isMap()) {
builder.append("<").append(wildcard(getMapKeyTypeDescriptor()));
builder.append(", ").append(wildcard(getMapValueTypeDescriptor())).append(">");
}
else if (isCollection()) {
builder.append("<").append(wildcard(getElementTypeDescriptor())).append(">");
}
return builder.toString();
}
// deprecations in Spring 3.1
@ -470,7 +425,7 @@ public class TypeDescriptor { @@ -470,7 +425,7 @@ public class TypeDescriptor {
}
/**
* Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapKeyTypeDescriptor() mapKeyTypeDescriptor}.
* Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapKeyTypeDescriptor() getMapKeyTypeDescriptor}.
* @deprecated in Spring 3.1 in favor of {@link #getMapKeyTypeDescriptor()}.
* @throws IllegalStateException if this type is not a java.util.Map.
*/
@ -480,7 +435,7 @@ public class TypeDescriptor { @@ -480,7 +435,7 @@ public class TypeDescriptor {
}
/**
* Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapValueTypeDescriptor() mapValueTypeDescriptor}.
* Returns the value of {@link TypeDescriptor#getType() getType()} for the {@link #getMapValueTypeDescriptor() getMapValueTypeDescriptor}.
* @deprecated in Spring 3.1 in favor of {@link #getMapValueTypeDescriptor()}.
* @throws IllegalStateException if this type is not a java.util.Map.
*/
@ -503,6 +458,7 @@ public class TypeDescriptor { @@ -503,6 +458,7 @@ public class TypeDescriptor {
return annotations != null ? annotations : EMPTY_ANNOTATION_ARRAY;
}
// internal constructors
private TypeDescriptor(Class<?> type) {
@ -536,6 +492,7 @@ public class TypeDescriptor { @@ -536,6 +492,7 @@ public class TypeDescriptor {
return new TypeDescriptor(descriptor);
}
// internal helpers
private void assertCollectionOrArray() {
@ -570,4 +527,49 @@ public class TypeDescriptor { @@ -570,4 +527,49 @@ public class TypeDescriptor {
return typeDescriptor != null ? typeDescriptor.toString() : "?";
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof TypeDescriptor)) {
return false;
}
TypeDescriptor other = (TypeDescriptor) obj;
boolean annotatedTypeEquals = ObjectUtils.nullSafeEquals(getType(), other.getType()) && ObjectUtils.nullSafeEquals(getAnnotations(), other.getAnnotations());
if (!annotatedTypeEquals) {
return false;
}
if (isCollection() || isArray()) {
return ObjectUtils.nullSafeEquals(getElementTypeDescriptor(), other.getElementTypeDescriptor());
}
else if (isMap()) {
return ObjectUtils.nullSafeEquals(getMapKeyTypeDescriptor(), other.getMapKeyTypeDescriptor()) && ObjectUtils.nullSafeEquals(getMapValueTypeDescriptor(), other.getMapValueTypeDescriptor());
}
else {
return true;
}
}
public int hashCode() {
return getType().hashCode();
}
public String toString() {
StringBuilder builder = new StringBuilder();
Annotation[] anns = getAnnotations();
for (Annotation ann : anns) {
builder.append("@").append(ann.annotationType().getName()).append(' ');
}
builder.append(ClassUtils.getQualifiedName(getType()));
if (isMap()) {
builder.append("<").append(wildcard(getMapKeyTypeDescriptor()));
builder.append(", ").append(wildcard(getMapValueTypeDescriptor())).append(">");
}
else if (isCollection()) {
builder.append("<").append(wildcard(getElementTypeDescriptor())).append(">");
}
return builder.toString();
}
}

4
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java

@ -87,14 +87,14 @@ final class MapToMapConverter implements ConditionalGenericConverter { @@ -87,14 +87,14 @@ final class MapToMapConverter implements ConditionalGenericConverter {
if (targetType == null) {
return sourceKey;
}
return this.conversionService.convert(sourceKey, sourceType.mapKeyTypeDescriptor(sourceKey), targetType);
return this.conversionService.convert(sourceKey, sourceType.getMapKeyTypeDescriptor(sourceKey), targetType);
}
private Object convertValue(Object sourceValue, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (targetType == null) {
return sourceValue;
}
return this.conversionService.convert(sourceValue, sourceType.mapValueTypeDescriptor(sourceValue), targetType);
return this.conversionService.convert(sourceValue, sourceType.getMapValueTypeDescriptor(sourceValue), targetType);
}
}

8
org.springframework.core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java

@ -706,7 +706,7 @@ public class TypeDescriptorTests { @@ -706,7 +706,7 @@ public class TypeDescriptorTests {
public void mapKeyType() {
TypeDescriptor desc = TypeDescriptor.valueOf(Map.class);
Integer value = new Integer(3);
desc = desc.mapKeyTypeDescriptor(value);
desc = desc.getMapKeyTypeDescriptor(value);
assertEquals(Integer.class, desc.getType());
}
@ -715,7 +715,7 @@ public class TypeDescriptorTests { @@ -715,7 +715,7 @@ public class TypeDescriptorTests {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext"));
assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<Integer>(3);
desc = desc.mapKeyTypeDescriptor(value);
desc = desc.getMapKeyTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
@ -727,7 +727,7 @@ public class TypeDescriptorTests { @@ -727,7 +727,7 @@ public class TypeDescriptorTests {
public void mapValueType() {
TypeDescriptor desc = TypeDescriptor.valueOf(Map.class);
Integer value = new Integer(3);
desc = desc.mapValueTypeDescriptor(value);
desc = desc.getMapValueTypeDescriptor(value);
assertEquals(Integer.class, desc.getType());
}
@ -736,7 +736,7 @@ public class TypeDescriptorTests { @@ -736,7 +736,7 @@ public class TypeDescriptorTests {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext"));
assertEquals(Integer.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<Integer>(3);
desc = desc.mapValueTypeDescriptor(value);
desc = desc.getMapValueTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}

2
org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

@ -95,7 +95,7 @@ public class Indexer extends SpelNodeImpl { @@ -95,7 +95,7 @@ public class Indexer extends SpelNodeImpl {
key = state.convertValue(key, targetObjectTypeDescriptor.getMapKeyTypeDescriptor());
}
Object value = ((Map<?, ?>) targetObject).get(key);
return new TypedValue(value, targetObjectTypeDescriptor.mapValueTypeDescriptor(value));
return new TypedValue(value, targetObjectTypeDescriptor.getMapValueTypeDescriptor(value));
}
if (targetObject == null) {

Loading…
Cancel
Save