Cache key classes implement Comparable and consistently provide a toString representation

Issue: SPR-14017
This commit is contained in:
Juergen Hoeller
2016-03-26 14:32:10 +01:00
parent a8b5ea1c51
commit 54aeb7a5d6
15 changed files with 222 additions and 54 deletions

View File

@@ -1802,7 +1802,7 @@ public abstract class AnnotationUtils {
/**
* Cache key for the AnnotatedElement cache.
*/
private static class AnnotationCacheKey {
private static final class AnnotationCacheKey implements Comparable<AnnotationCacheKey> {
private final AnnotatedElement element;
@@ -1829,6 +1829,20 @@ public abstract class AnnotationUtils {
public int hashCode() {
return (this.element.hashCode() * 29 + this.annotationType.hashCode());
}
@Override
public String toString() {
return "@" + this.annotationType + " on " + this.element;
}
@Override
public int compareTo(AnnotationCacheKey other) {
int result = this.element.toString().compareTo(other.element.toString());
if (result == 0) {
result = this.annotationType.getName().compareTo(other.annotationType.getName());
}
return result;
}
}

View File

@@ -435,7 +435,7 @@ public class GenericConversionService implements ConfigurableConversionService {
/**
* Key for use with the converter cache.
*/
private static final class ConverterCacheKey {
private static final class ConverterCacheKey implements Comparable<ConverterCacheKey> {
private final TypeDescriptor sourceType;
@@ -470,6 +470,17 @@ public class GenericConversionService implements ConfigurableConversionService {
return ("ConverterCacheKey [sourceType = " + this.sourceType +
", targetType = " + this.targetType + "]");
}
@Override
public int compareTo(ConverterCacheKey other) {
int result = this.sourceType.getResolvableType().toString().compareTo(
other.sourceType.getResolvableType().toString());
if (result == 0) {
result = this.targetType.getResolvableType().toString().compareTo(
other.targetType.getResolvableType().toString());
}
return result;
}
}