Skip to content

Commit ecea82d

Browse files
committed
Polishing
1 parent f31069a commit ecea82d

File tree

3 files changed

+85
-85
lines changed

3 files changed

+85
-85
lines changed

spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -156,7 +156,7 @@ public boolean hasAnnotatedMethods(String annotationName) {
156156
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
157157
try {
158158
Method[] methods = getIntrospectedClass().getDeclaredMethods();
159-
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>();
159+
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4);
160160
for (Method method : methods) {
161161
if (!method.isBridge() && method.getAnnotations().length > 0 &&
162162
AnnotatedElementUtils.isAnnotated(method, annotationName)) {

spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ public MethodMetadataReadingVisitor(String methodName, int access, String declar
7979

8080
@Override
8181
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
82-
String className = Type.getType(desc).getClassName();
8382
this.methodMetadataSet.add(this);
83+
String className = Type.getType(desc).getClassName();
8484
return new AnnotationAttributesReadingVisitor(
8585
className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
8686
}
8787

88+
8889
@Override
8990
public String getMethodName() {
9091
return this.methodName;

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import org.springframework.util.ObjectUtils;
2828
import org.springframework.util.StringUtils;
2929

30-
import static java.nio.charset.StandardCharsets.ISO_8859_1;
31-
import static java.nio.charset.StandardCharsets.UTF_8;
32-
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
30+
import static java.nio.charset.StandardCharsets.*;
31+
import static java.time.format.DateTimeFormatter.*;
3332

3433
/**
3534
* Represent the Content-Disposition type and parameters as defined in RFC 2183.
@@ -151,6 +150,85 @@ public ZonedDateTime getReadDate() {
151150
}
152151

153152

153+
@Override
154+
public boolean equals(Object other) {
155+
if (this == other) {
156+
return true;
157+
}
158+
if (!(other instanceof ContentDisposition)) {
159+
return false;
160+
}
161+
ContentDisposition otherCd = (ContentDisposition) other;
162+
return (ObjectUtils.nullSafeEquals(this.type, otherCd.type) &&
163+
ObjectUtils.nullSafeEquals(this.name, otherCd.name) &&
164+
ObjectUtils.nullSafeEquals(this.filename, otherCd.filename) &&
165+
ObjectUtils.nullSafeEquals(this.charset, otherCd.charset) &&
166+
ObjectUtils.nullSafeEquals(this.size, otherCd.size) &&
167+
ObjectUtils.nullSafeEquals(this.creationDate, otherCd.creationDate)&&
168+
ObjectUtils.nullSafeEquals(this.modificationDate, otherCd.modificationDate)&&
169+
ObjectUtils.nullSafeEquals(this.readDate, otherCd.readDate));
170+
}
171+
172+
@Override
173+
public int hashCode() {
174+
int result = ObjectUtils.nullSafeHashCode(this.type);
175+
result = 31 * result + ObjectUtils.nullSafeHashCode(this.name);
176+
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
177+
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
178+
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
179+
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
180+
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
181+
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
182+
return result;
183+
}
184+
185+
/**
186+
* Return the header value for this content disposition as defined in RFC 2183.
187+
* @see #parse(String)
188+
*/
189+
@Override
190+
public String toString() {
191+
StringBuilder sb = new StringBuilder();
192+
if (this.type != null) {
193+
sb.append(this.type);
194+
}
195+
if (this.name != null) {
196+
sb.append("; name=\"");
197+
sb.append(this.name).append('\"');
198+
}
199+
if (this.filename != null) {
200+
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
201+
sb.append("; filename=\"");
202+
sb.append(this.filename).append('\"');
203+
}
204+
else {
205+
sb.append("; filename*=");
206+
sb.append(encodeHeaderFieldParam(this.filename, this.charset));
207+
}
208+
}
209+
if (this.size != null) {
210+
sb.append("; size=");
211+
sb.append(this.size);
212+
}
213+
if (this.creationDate != null) {
214+
sb.append("; creation-date=\"");
215+
sb.append(RFC_1123_DATE_TIME.format(this.creationDate));
216+
sb.append('\"');
217+
}
218+
if (this.modificationDate != null) {
219+
sb.append("; modification-date=\"");
220+
sb.append(RFC_1123_DATE_TIME.format(this.modificationDate));
221+
sb.append('\"');
222+
}
223+
if (this.readDate != null) {
224+
sb.append("; read-date=\"");
225+
sb.append(RFC_1123_DATE_TIME.format(this.readDate));
226+
sb.append('\"');
227+
}
228+
return sb.toString();
229+
}
230+
231+
154232
/**
155233
* Return a builder for a {@code ContentDisposition}.
156234
* @param type the disposition type like for example {@literal inline},
@@ -170,7 +248,6 @@ public static ContentDisposition empty() {
170248

171249
/**
172250
* Parse a {@literal Content-Disposition} header value as defined in RFC 2183.
173-
*
174251
* @param contentDisposition the {@literal Content-Disposition} header value
175252
* @return the parsed content disposition
176253
* @see #toString()
@@ -286,84 +363,6 @@ private static boolean isRFC5987AttrChar(byte c) {
286363
c == '.' || c == '^' || c == '_' || c == '`' || c == '|' || c == '~';
287364
}
288365

289-
@Override
290-
public boolean equals(Object other) {
291-
if (this == other) {
292-
return true;
293-
}
294-
if (!(other instanceof ContentDisposition)) {
295-
return false;
296-
}
297-
ContentDisposition otherCd = (ContentDisposition) other;
298-
return (ObjectUtils.nullSafeEquals(this.type, otherCd.type) &&
299-
ObjectUtils.nullSafeEquals(this.name, otherCd.name) &&
300-
ObjectUtils.nullSafeEquals(this.filename, otherCd.filename) &&
301-
ObjectUtils.nullSafeEquals(this.charset, otherCd.charset) &&
302-
ObjectUtils.nullSafeEquals(this.size, otherCd.size) &&
303-
ObjectUtils.nullSafeEquals(this.creationDate, otherCd.creationDate)&&
304-
ObjectUtils.nullSafeEquals(this.modificationDate, otherCd.modificationDate)&&
305-
ObjectUtils.nullSafeEquals(this.readDate, otherCd.readDate));
306-
}
307-
308-
@Override
309-
public int hashCode() {
310-
int result = ObjectUtils.nullSafeHashCode(this.type);
311-
result = 31 * result + ObjectUtils.nullSafeHashCode(this.name);
312-
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
313-
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
314-
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
315-
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
316-
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
317-
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
318-
return result;
319-
}
320-
321-
/**
322-
* Return the header value for this content disposition as defined in RFC 2183.
323-
* @see #parse(String)
324-
*/
325-
@Override
326-
public String toString() {
327-
StringBuilder sb = new StringBuilder();
328-
if (this.type != null) {
329-
sb.append(this.type);
330-
}
331-
if (this.name != null) {
332-
sb.append("; name=\"");
333-
sb.append(this.name).append('\"');
334-
}
335-
if (this.filename != null) {
336-
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
337-
sb.append("; filename=\"");
338-
sb.append(this.filename).append('\"');
339-
}
340-
else {
341-
sb.append("; filename*=");
342-
sb.append(encodeHeaderFieldParam(this.filename, this.charset));
343-
}
344-
}
345-
if (this.size != null) {
346-
sb.append("; size=");
347-
sb.append(this.size);
348-
}
349-
if (this.creationDate != null) {
350-
sb.append("; creation-date=\"");
351-
sb.append(RFC_1123_DATE_TIME.format(this.creationDate));
352-
sb.append('\"');
353-
}
354-
if (this.modificationDate != null) {
355-
sb.append("; modification-date=\"");
356-
sb.append(RFC_1123_DATE_TIME.format(this.modificationDate));
357-
sb.append('\"');
358-
}
359-
if (this.readDate != null) {
360-
sb.append("; read-date=\"");
361-
sb.append(RFC_1123_DATE_TIME.format(this.readDate));
362-
sb.append('\"');
363-
}
364-
return sb.toString();
365-
}
366-
367366
/**
368367
* Encode the given header field param as describe in RFC 5987.
369368
* @param input the header field param

0 commit comments

Comments
 (0)