From cc33d3fac87e0da6444e0a428de4ae0e476a8574 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 25 Feb 2015 19:05:06 +0100 Subject: [PATCH] Polishing --- .../core/convert/TypeDescriptor.java | 13 ++++++------ .../ResourceHttpMessageConverter.java | 21 +++++++++++-------- .../resource/ResourceHttpRequestHandler.java | 18 +++++++++------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index f7176c7f1a3..ea328623627 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -117,7 +117,7 @@ public class TypeDescriptor implements Serializable { * constructor is used internally and may also be used by subclasses that support * non-Java languages with extended type systems. * @param resolvableType the resolvable type - * @param type the backing type or {@code null} if should be resolved + * @param type the backing type (or {@code null} if it should get resolved) * @param annotations the type annotations */ protected TypeDescriptor(ResolvableType resolvableType, Class type, Annotation[] annotations) { @@ -333,8 +333,8 @@ public class TypeDescriptor implements Serializable { if (this.resolvableType.isArray()) { return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations); } - if (streamAvailable && StreamHelper.isStream(this.type)) { - return StreamHelper.getStreamElementType(this); + if (streamAvailable && StreamDelegate.isStream(this.type)) { + return StreamDelegate.getStreamElementType(this); } return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric()); } @@ -691,17 +691,18 @@ public class TypeDescriptor implements Serializable { return new TypeDescriptor(type, null, source.annotations); } + /** * Inner class to avoid a hard dependency on Java 8. */ @UsesJava8 - private static class StreamHelper { + private static class StreamDelegate { - private static boolean isStream(Class type) { + public static boolean isStream(Class type) { return Stream.class.isAssignableFrom(type); } - private static TypeDescriptor getStreamElementType(TypeDescriptor source) { + public static TypeDescriptor getStreamElementType(TypeDescriptor source) { return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric()); } } diff --git a/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java index 9575b6e5cbf..4429d4d5d2c 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +44,8 @@ import org.springframework.util.StringUtils; */ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter { - private static final boolean jafPresent = - ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader()); + private static final boolean jafPresent = ClassUtils.isPresent( + "javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader()); public ResourceHttpMessageConverter() { @@ -103,7 +103,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter locations = new ArrayList(4); @@ -422,8 +423,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H getLocations() + ", resolvers=" + getResourceResolvers() + "]"; } + /** - * Inner class to avoid hard-coded JAF dependency. + * Inner class to avoid a hard-coded JAF dependency. */ private static class ActivationMediaTypeFactory { @@ -434,7 +436,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H } private static FileTypeMap loadFileTypeMapFromContextSupportModule() { - // see if we can find the extended mime.types from the context-support module + // See if we can find the extended mime.types from the context-support module... Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types"); if (mappingLocation.exists()) { InputStream inputStream = null; @@ -465,4 +467,4 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H } } - } +}