Polishing

This commit is contained in:
Juergen Hoeller
2018-03-03 17:18:44 +01:00
parent 6e8a3fb4db
commit bc043245cc
4 changed files with 447 additions and 412 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -40,7 +40,7 @@ public interface ObjectFactory<T> {
/**
* Return an instance (possibly shared or independent)
* of the object managed by this factory.
* @return an instance of the bean (should never be {@code null})
* @return the resulting instance
* @throws BeansException in case of creation errors
*/
T getObject() throws BeansException;

View File

@@ -29,15 +29,15 @@ import java.util.Map;
import java.util.TreeSet;
/**
* Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in
* other Internet protocols including HTTP.
* Represents a MIME Type, as originally defined in RFC 2046 and subsequently
* used in other Internet protocols including HTTP.
*
* <p>This class, however, does not contain support for the q-parameters used
* in HTTP content negotiation. Those can be found in the sub-class
* in HTTP content negotiation. Those can be found in the subclass
* {@code org.springframework.http.MediaType} in the {@code spring-web} module.
*
* <p>Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}.
* Also has functionality to parse media types from a string using
* Also has functionality to parse MIME Type values from a {@code String} using
* {@link #valueOf(String)}. For more parsing options see {@link MimeTypeUtils}.
*
* @author Arjen Poutsma
@@ -137,7 +137,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
/**
* Copy-constructor that copies the type, subtype, parameters of the given {@code MimeType},
* and allows to set the specified character set.
* @param other the other media type
* @param other the other MimeType
* @param charset the character set
* @throws IllegalArgumentException if any of the parameters contains illegal characters
* @since 4.3
@@ -149,8 +149,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
/**
* Copy-constructor that copies the type and subtype of the given {@code MimeType},
* and allows for different parameter.
* @param other the other media type
* @param parameters the parameters, may be {@code null}
* @param other the other MimeType
* @param parameters the parameters (may be {@code null})
* @throws IllegalArgumentException if any of the parameters contains illegal characters
*/
public MimeType(MimeType other, Map<String, String> parameters) {
@@ -161,7 +161,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
* Create a new {@code MimeType} for the given type, subtype, and parameters.
* @param type the primary type
* @param subtype the subtype
* @param parameters the parameters, may be {@code null}
* @param parameters the parameters (may be {@code null})
* @throws IllegalArgumentException if any of the parameters contains illegal characters
*/
public MimeType(String type, String subtype, Map<String, String> parameters) {
@@ -227,7 +227,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
if (s == null) {
return null;
}
return isQuotedString(s) ? s.substring(1, s.length() - 1) : s;
return (isQuotedString(s) ? s.substring(1, s.length() - 1) : s);
}
/**
@@ -249,9 +249,9 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
/**
* Indicates whether this media type is concrete, i.e. whether neither the type
* Indicates whether this MIME Type is concrete, i.e. whether neither the type
* nor the subtype is a wildcard character <code>&#42;</code>.
* @return whether this media type is concrete
* @return whether this MIME Type is concrete
*/
public boolean isConcrete() {
return !isWildcardType() && !isWildcardSubtype();
@@ -310,12 +310,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
/**
* Indicate whether this {@code MediaType} includes the given media type.
* Indicate whether this MIME Type includes the given MIME Type.
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html},
* and {@code application/*+xml} includes {@code application/soap+xml}, etc. This
* method is <b>not</b> symmetric.
* @param other the reference media type with which to compare
* @return {@code true} if this media type includes the given media type;
* and {@code application/*+xml} includes {@code application/soap+xml}, etc.
* This method is <b>not</b> symmetric.
* @param other the reference MIME Type with which to compare
* @return {@code true} if this MIME Type includes the given MIME Type;
* {@code false} otherwise
*/
public boolean includes(MimeType other) {
@@ -331,8 +331,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
return true;
}
if (isWildcardSubtype()) {
// wildcard with suffix, e.g. application/*+xml
int thisPlusIdx = getSubtype().indexOf('+');
// Wildcard with suffix, e.g. application/*+xml
int thisPlusIdx = getSubtype().lastIndexOf('+');
if (thisPlusIdx == -1) {
return true;
}
@@ -354,12 +354,12 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
/**
* Indicate whether this {@code MediaType} is compatible with the given media type.
* Indicate whether this MIME Type is compatible with the given MIME Type.
* <p>For instance, {@code text/*} is compatible with {@code text/plain},
* {@code text/html}, and vice versa. In effect, this method is similar to
* {@link #includes}, except that it <b>is</b> symmetric.
* @param other the reference media type with which to compare
* @return {@code true} if this media type is compatible with the given media type;
* @param other the reference MIME Type with which to compare
* @return {@code true} if this MIME Type is compatible with the given MIME Type;
* {@code false} otherwise
*/
public boolean isCompatibleWith(MimeType other) {
@@ -470,8 +470,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
}
/**
* Compares this {@code MediaType} to another alphabetically.
* @param other media type to compare to
* Compares this MIME Type to another alphabetically.
* @param other the MIME Type to compare to
* @see MimeTypeUtils#sortBySpecificity(List)
*/
@Override

View File

@@ -35,8 +35,8 @@ import org.springframework.util.StringUtils;
import org.springframework.util.comparator.CompoundComparator;
/**
* A sub-class of {@link MimeType} that adds support for quality parameters as defined
* in the HTTP specification.
* A subclass of {@link MimeType} that adds support for quality parameters
* as defined in the HTTP specification.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
@@ -367,18 +367,49 @@ public class MediaType extends MimeType implements Serializable {
}
/**
* Return the quality value, as indicated by a {@code q} parameter, if any.
* Return the quality factor, as indicated by a {@code q} parameter, if any.
* Defaults to {@code 1.0}.
* @return the quality factory
* @return the quality factor as double value
*/
public double getQualityValue() {
String qualityFactory = getParameter(PARAM_QUALITY_FACTOR);
return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D);
String qualityFactor = getParameter(PARAM_QUALITY_FACTOR);
return (qualityFactor != null ? Double.parseDouble(unquote(qualityFactor)) : 1D);
}
/**
* Return a replica of this instance with the quality value of the given MediaType.
* @return the same instance if the given MediaType doesn't have a quality value, or a new one otherwise
* Indicate whether this {@code MediaType} includes the given media type.
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html},
* and {@code application/*+xml} includes {@code application/soap+xml}, etc.
* This method is <b>not</b> symmetric.
* <p>Simply calls {@link #includes(MimeType)} but declared with a
* {@code MediaType} parameter for binary backwards compatibility.
* @param other the reference media type with which to compare
* @return {@code true} if this media type includes the given media type;
* {@code false} otherwise
*/
public boolean includes(MediaType other) {
return super.includes(other);
}
/**
* Indicate whether this {@code MediaType} is compatible with the given media type.
* <p>For instance, {@code text/*} is compatible with {@code text/plain},
* {@code text/html}, and vice versa. In effect, this method is similar to
* {@link #includes}, except that it <b>is</b> symmetric.
* <p>Simply calls {@link #isCompatibleWith(MimeType)} but declared with a
* {@code MediaType} parameter for binary backwards compatibility.
* @param other the reference media type with which to compare
* @return {@code true} if this media type is compatible with the given media type;
* {@code false} otherwise
*/
public boolean isCompatibleWith(MediaType other) {
return super.isCompatibleWith(other);
}
/**
* Return a replica of this instance with the quality value of the given {@code MediaType}.
* @return the same instance if the given MediaType doesn't have a quality value,
* or a new one otherwise
*/
public MediaType copyQualityValue(MediaType mediaType) {
if (!mediaType.getParameters().containsKey(PARAM_QUALITY_FACTOR)) {
@@ -391,7 +422,8 @@ public class MediaType extends MimeType implements Serializable {
/**
* Return a replica of this instance with its quality value removed.
* @return the same instance if the media type doesn't contain a quality value, or a new one otherwise
* @return the same instance if the media type doesn't contain a quality value,
* or a new one otherwise
*/
public MediaType removeQualityValue() {
if (!getParameters().containsKey(PARAM_QUALITY_FACTOR)) {