Skip to content

Commit

Permalink
renamed mapKey/ValueTypeDescriptor methods back to getMapKey/ValueTyp…
Browse files Browse the repository at this point in the history
…eDescriptor (for Spring 3.0.x compatibility)
  • Loading branch information
jhoeller committed Oct 11, 2011
1 parent ba2c8fc commit 1cea52b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public TypeDescriptor getMapKeyTypeDescriptor() {
* @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());
}

Expand All @@ -407,55 +407,10 @@ public TypeDescriptor getMapValueTypeDescriptor() {
* @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

Expand All @@ -470,7 +425,7 @@ public Class<?> getElementType() {
}

/**
* 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.
*/
Expand All @@ -480,7 +435,7 @@ public Class<?> getMapKeyType() {
}

/**
* 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.
*/
Expand All @@ -503,6 +458,7 @@ static Annotation[] nullSafeAnnotations(Annotation[] annotations) {
return annotations != null ? annotations : EMPTY_ANNOTATION_ARRAY;
}


// internal constructors

private TypeDescriptor(Class<?> type) {
Expand Down Expand Up @@ -536,6 +492,7 @@ private static TypeDescriptor nested(AbstractDescriptor descriptor, int nestingL
return new TypeDescriptor(descriptor);
}


// internal helpers

private void assertCollectionOrArray() {
Expand Down Expand Up @@ -570,4 +527,49 @@ private String wildcard(TypeDescriptor 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ private Object convertKey(Object sourceKey, TypeDescriptor sourceType, TypeDescr
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public void elementTypePreserveContext() throws Exception {
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());
}

Expand All @@ -715,7 +715,7 @@ public void mapKeyTypePreserveContext() throws Exception {
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));
}
Expand All @@ -727,7 +727,7 @@ public void mapKeyTypePreserveContext() throws Exception {
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());
}

Expand All @@ -736,7 +736,7 @@ public void mapValueTypePreserveContext() throws Exception {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
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) {
Expand Down

0 comments on commit 1cea52b

Please sign in to comment.