提交 ecea82d3 编写于 作者: J Juergen Hoeller

Polishing

上级 f31069ac
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -156,7 +156,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements ...@@ -156,7 +156,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
try { try {
Method[] methods = getIntrospectedClass().getDeclaredMethods(); Method[] methods = getIntrospectedClass().getDeclaredMethods();
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(); Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4);
for (Method method : methods) { for (Method method : methods) {
if (!method.isBridge() && method.getAnnotations().length > 0 && if (!method.isBridge() && method.getAnnotations().length > 0 &&
AnnotatedElementUtils.isAnnotated(method, annotationName)) { AnnotatedElementUtils.isAnnotated(method, annotationName)) {
......
...@@ -79,12 +79,13 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho ...@@ -79,12 +79,13 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho
@Override @Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
String className = Type.getType(desc).getClassName();
this.methodMetadataSet.add(this); this.methodMetadataSet.add(this);
String className = Type.getType(desc).getClassName();
return new AnnotationAttributesReadingVisitor( return new AnnotationAttributesReadingVisitor(
className, this.attributesMap, this.metaAnnotationMap, this.classLoader); className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
} }
@Override @Override
public String getMethodName() { public String getMethodName() {
return this.methodName; return this.methodName;
......
...@@ -27,9 +27,8 @@ import org.springframework.util.Assert; ...@@ -27,9 +27,8 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.*;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.time.format.DateTimeFormatter.*;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
/** /**
* Represent the Content-Disposition type and parameters as defined in RFC 2183. * Represent the Content-Disposition type and parameters as defined in RFC 2183.
...@@ -151,6 +150,85 @@ public class ContentDisposition { ...@@ -151,6 +150,85 @@ public class ContentDisposition {
} }
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ContentDisposition)) {
return false;
}
ContentDisposition otherCd = (ContentDisposition) other;
return (ObjectUtils.nullSafeEquals(this.type, otherCd.type) &&
ObjectUtils.nullSafeEquals(this.name, otherCd.name) &&
ObjectUtils.nullSafeEquals(this.filename, otherCd.filename) &&
ObjectUtils.nullSafeEquals(this.charset, otherCd.charset) &&
ObjectUtils.nullSafeEquals(this.size, otherCd.size) &&
ObjectUtils.nullSafeEquals(this.creationDate, otherCd.creationDate)&&
ObjectUtils.nullSafeEquals(this.modificationDate, otherCd.modificationDate)&&
ObjectUtils.nullSafeEquals(this.readDate, otherCd.readDate));
}
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(this.type);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.name);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
return result;
}
/**
* Return the header value for this content disposition as defined in RFC 2183.
* @see #parse(String)
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (this.type != null) {
sb.append(this.type);
}
if (this.name != null) {
sb.append("; name=\"");
sb.append(this.name).append('\"');
}
if (this.filename != null) {
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
sb.append("; filename=\"");
sb.append(this.filename).append('\"');
}
else {
sb.append("; filename*=");
sb.append(encodeHeaderFieldParam(this.filename, this.charset));
}
}
if (this.size != null) {
sb.append("; size=");
sb.append(this.size);
}
if (this.creationDate != null) {
sb.append("; creation-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.creationDate));
sb.append('\"');
}
if (this.modificationDate != null) {
sb.append("; modification-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.modificationDate));
sb.append('\"');
}
if (this.readDate != null) {
sb.append("; read-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.readDate));
sb.append('\"');
}
return sb.toString();
}
/** /**
* Return a builder for a {@code ContentDisposition}. * Return a builder for a {@code ContentDisposition}.
* @param type the disposition type like for example {@literal inline}, * @param type the disposition type like for example {@literal inline},
...@@ -170,7 +248,6 @@ public class ContentDisposition { ...@@ -170,7 +248,6 @@ public class ContentDisposition {
/** /**
* Parse a {@literal Content-Disposition} header value as defined in RFC 2183. * Parse a {@literal Content-Disposition} header value as defined in RFC 2183.
*
* @param contentDisposition the {@literal Content-Disposition} header value * @param contentDisposition the {@literal Content-Disposition} header value
* @return the parsed content disposition * @return the parsed content disposition
* @see #toString() * @see #toString()
...@@ -286,84 +363,6 @@ public class ContentDisposition { ...@@ -286,84 +363,6 @@ public class ContentDisposition {
c == '.' || c == '^' || c == '_' || c == '`' || c == '|' || c == '~'; c == '.' || c == '^' || c == '_' || c == '`' || c == '|' || c == '~';
} }
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ContentDisposition)) {
return false;
}
ContentDisposition otherCd = (ContentDisposition) other;
return (ObjectUtils.nullSafeEquals(this.type, otherCd.type) &&
ObjectUtils.nullSafeEquals(this.name, otherCd.name) &&
ObjectUtils.nullSafeEquals(this.filename, otherCd.filename) &&
ObjectUtils.nullSafeEquals(this.charset, otherCd.charset) &&
ObjectUtils.nullSafeEquals(this.size, otherCd.size) &&
ObjectUtils.nullSafeEquals(this.creationDate, otherCd.creationDate)&&
ObjectUtils.nullSafeEquals(this.modificationDate, otherCd.modificationDate)&&
ObjectUtils.nullSafeEquals(this.readDate, otherCd.readDate));
}
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(this.type);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.name);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
return result;
}
/**
* Return the header value for this content disposition as defined in RFC 2183.
* @see #parse(String)
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (this.type != null) {
sb.append(this.type);
}
if (this.name != null) {
sb.append("; name=\"");
sb.append(this.name).append('\"');
}
if (this.filename != null) {
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
sb.append("; filename=\"");
sb.append(this.filename).append('\"');
}
else {
sb.append("; filename*=");
sb.append(encodeHeaderFieldParam(this.filename, this.charset));
}
}
if (this.size != null) {
sb.append("; size=");
sb.append(this.size);
}
if (this.creationDate != null) {
sb.append("; creation-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.creationDate));
sb.append('\"');
}
if (this.modificationDate != null) {
sb.append("; modification-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.modificationDate));
sb.append('\"');
}
if (this.readDate != null) {
sb.append("; read-date=\"");
sb.append(RFC_1123_DATE_TIME.format(this.readDate));
sb.append('\"');
}
return sb.toString();
}
/** /**
* Encode the given header field param as describe in RFC 5987. * Encode the given header field param as describe in RFC 5987.
* @param input the header field param * @param input the header field param
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册