Skip to content

Commit 56273a8

Browse files
committed
Polishing
1 parent 3d2bde7 commit 56273a8

File tree

4 files changed

+48
-55
lines changed

4 files changed

+48
-55
lines changed

spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void testGetBeanNamesForTypeWithOverride() throws Exception {
128128
public void testNoBeansOfType() {
129129
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
130130
lbf.addBean("foo", new Object());
131-
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
131+
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
132132
assertTrue(beans.isEmpty());
133133
}
134134

@@ -231,7 +231,7 @@ public void testHierarchicalResolutionWithOverride() throws Exception {
231231
Object test3 = this.listableBeanFactory.getBean("test3");
232232
Object test = this.listableBeanFactory.getBean("test");
233233

234-
Map<?, ?> beans =
234+
Map<String, ?> beans =
235235
BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, false);
236236
assertEquals(2, beans.size());
237237
assertEquals(test3, beans.get("test3"));

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ public static ResolvableType forClassWithGenerics(Class<?> sourceClass, Class<?>
11521152
* @return a {@link ResolvableType} for the specific class and generics
11531153
* @see #forClassWithGenerics(Class, Class...)
11541154
*/
1155-
public static ResolvableType forClassWithGenerics(final Class<?> sourceClass, final ResolvableType... generics) {
1155+
public static ResolvableType forClassWithGenerics(Class<?> sourceClass, ResolvableType... generics) {
11561156
Assert.notNull(sourceClass, "Source class must not be null");
11571157
Assert.notNull(generics, "Generics must not be null");
11581158
TypeVariable<?>[] variables = sourceClass.getTypeParameters();

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

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
* Represents an HTTP (byte) range for use with the HTTP {@code "Range"} header.
3131
*
3232
* @author Arjen Poutsma
33+
* @author Juergen Hoeller
34+
* @since 4.2
3335
* @see <a href="http://tools.ietf.org/html/rfc7233">HTTP/1.1: Range Requests</a>
3436
* @see HttpHeaders#setRange(List)
3537
* @see HttpHeaders#getRange()
36-
* @since 4.2
3738
*/
3839
public abstract class HttpRange {
3940

@@ -111,7 +112,7 @@ public static List<HttpRange> parseRanges(String ranges) {
111112
}
112113

113114
private static HttpRange parseRange(String range) {
114-
Assert.notNull(range);
115+
Assert.hasLength(range, "Range String must not be empty");
115116
int dashIdx = range.indexOf('-');
116117
if (dashIdx > 0) {
117118
long firstPos = Long.parseLong(range.substring(0, dashIdx));
@@ -139,27 +140,18 @@ else if (dashIdx == 0) {
139140
* @return the string representation
140141
*/
141142
public static String toString(Collection<HttpRange> ranges) {
142-
Assert.notNull(ranges);
143+
Assert.notEmpty(ranges, "Ranges Collection must not be empty");
143144
StringBuilder builder = new StringBuilder(BYTE_RANGE_PREFIX);
144145
for (Iterator<HttpRange> iterator = ranges.iterator(); iterator.hasNext(); ) {
145146
HttpRange range = iterator.next();
146-
range.appendTo(builder);
147+
builder.append(range);
147148
if (iterator.hasNext()) {
148149
builder.append(", ");
149150
}
150151
}
151152
return builder.toString();
152153
}
153154

154-
@Override
155-
public String toString() {
156-
StringBuilder builder = new StringBuilder();
157-
appendTo(builder);
158-
return builder.toString();
159-
}
160-
161-
abstract void appendTo(StringBuilder builder);
162-
163155

164156
/**
165157
* Represents an HTTP/1.1 byte range, with a first and optional last position.
@@ -173,19 +165,18 @@ private static class ByteRange extends HttpRange {
173165

174166
private final Long lastPos;
175167

176-
177-
private ByteRange(long firstPos, Long lastPos) {
168+
public ByteRange(long firstPos, Long lastPos) {
178169
assertPositions(firstPos, lastPos);
179170
this.firstPos = firstPos;
180171
this.lastPos = lastPos;
181172
}
182173

183174
private void assertPositions(long firstBytePos, Long lastBytePos) {
184175
if (firstBytePos < 0) {
185-
throw new IllegalArgumentException("Invalid firstPos=" + firstBytePos);
176+
throw new IllegalArgumentException("Invalid first byte position: " + firstBytePos);
186177
}
187178
if (lastBytePos != null && lastBytePos < firstBytePos) {
188-
throw new IllegalArgumentException("firstPost= " + firstBytePos +
179+
throw new IllegalArgumentException("firstBytePosition=" + firstBytePos +
189180
" should be less then or equal to lastBytePosition=" + lastBytePos);
190181
}
191182
}
@@ -206,34 +197,37 @@ public long getRangeEnd(long length) {
206197
}
207198

208199
@Override
209-
void appendTo(StringBuilder builder) {
210-
builder.append(this.firstPos);
211-
builder.append('-');
212-
if (this.lastPos != null) {
213-
builder.append(this.lastPos);
214-
}
215-
}
216-
217-
@Override
218-
public boolean equals(Object o) {
219-
if (this == o) {
200+
public boolean equals(Object other) {
201+
if (this == other) {
220202
return true;
221203
}
222-
if (!(o instanceof ByteRange)) {
204+
if (!(other instanceof ByteRange)) {
223205
return false;
224206
}
225-
ByteRange other = (ByteRange) o;
226-
return this.firstPos == other.firstPos && ObjectUtils.nullSafeEquals(this.lastPos, other.lastPos);
207+
ByteRange otherRange = (ByteRange) other;
208+
return (this.firstPos == otherRange.firstPos &&
209+
ObjectUtils.nullSafeEquals(this.lastPos, otherRange.lastPos));
227210
}
228211

229212
@Override
230213
public int hashCode() {
231-
int hashCode = ObjectUtils.nullSafeHashCode(this.firstPos);
232-
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.lastPos);
233-
return hashCode;
214+
return (ObjectUtils.nullSafeHashCode(this.firstPos) * 31 +
215+
ObjectUtils.nullSafeHashCode(this.lastPos));
216+
}
217+
218+
@Override
219+
public String toString() {
220+
StringBuilder builder = new StringBuilder();
221+
builder.append(this.firstPos);
222+
builder.append('-');
223+
if (this.lastPos != null) {
224+
builder.append(this.lastPos);
225+
}
226+
return builder.toString();
234227
}
235228
}
236229

230+
237231
/**
238232
* Represents an HTTP/1.1 suffix byte range, with a number of suffix bytes.
239233
* @see <a href="http://tools.ietf.org/html/rfc7233#section-2.1">Byte Ranges</a>
@@ -243,10 +237,9 @@ private static class SuffixByteRange extends HttpRange {
243237

244238
private final long suffixLength;
245239

246-
247-
private SuffixByteRange(long suffixLength) {
240+
public SuffixByteRange(long suffixLength) {
248241
if (suffixLength < 0) {
249-
throw new IllegalArgumentException("Invalid suffixLength=" + suffixLength);
242+
throw new IllegalArgumentException("Invalid suffix length: " + suffixLength);
250243
}
251244
this.suffixLength = suffixLength;
252245
}
@@ -268,26 +261,26 @@ public long getRangeEnd(long length) {
268261
}
269262

270263
@Override
271-
void appendTo(StringBuilder builder) {
272-
builder.append('-');
273-
builder.append(this.suffixLength);
274-
}
275-
276-
@Override
277-
public boolean equals(Object o) {
278-
if (this == o) {
264+
public boolean equals(Object other) {
265+
if (this == other) {
279266
return true;
280267
}
281-
if (!(o instanceof SuffixByteRange)) {
268+
if (!(other instanceof SuffixByteRange)) {
282269
return false;
283270
}
284-
SuffixByteRange other = (SuffixByteRange) o;
285-
return this.suffixLength == other.suffixLength;
271+
SuffixByteRange otherRange = (SuffixByteRange) other;
272+
return (this.suffixLength == otherRange.suffixLength);
286273
}
287274

288275
@Override
289276
public int hashCode() {
290277
return ObjectUtils.hashCode(this.suffixLength);
291278
}
279+
280+
@Override
281+
public String toString() {
282+
return "-" + this.suffixLength;
283+
}
292284
}
285+
293286
}

spring-web/src/test/java/org/springframework/http/HttpRangeTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*/
1616
package org.springframework.http;
1717

18-
import static org.junit.Assert.*;
19-
2018
import java.util.ArrayList;
2119
import java.util.List;
2220

2321
import org.junit.Test;
2422

23+
import static org.junit.Assert.*;
24+
2525
/**
26-
* Unit tests for {@link org.springframework.http.HttpRange}.
26+
* Unit tests for {@link HttpRange}.
27+
*
2728
* @author Rossen Stoyanchev
2829
*/
2930
public class HttpRangeTests {
3031

31-
3232
@Test(expected = IllegalArgumentException.class)
3333
public void invalidFirstPosition() throws Exception {
3434
HttpRange.createByteRange(-1);

0 commit comments

Comments
 (0)