Polishing
This commit is contained in:
parent
98a49b46b7
commit
918ffacdf8
|
@ -43,7 +43,7 @@ import org.springframework.util.MultiValueMap;
|
|||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Factory for collections that is aware of Java 5, Java 6, and Spring collection types.
|
||||
* Factory for collections that is aware of common Java and Spring collection types.
|
||||
*
|
||||
* <p>Mainly for internal use within the framework.
|
||||
*
|
||||
|
@ -353,12 +353,10 @@ public final class CollectionFactory {
|
|||
/**
|
||||
* Create a variant of {@link java.util.Properties} that sorts properties
|
||||
* alphanumerically based on their keys.
|
||||
*
|
||||
* <p>This can be useful when storing the {@link Properties} instance in a
|
||||
* properties file, since it allows such files to be generated in a repeatable
|
||||
* manner with consistent ordering of properties. Comments in generated
|
||||
* properties files can also be optionally omitted.
|
||||
*
|
||||
* @param omitComments {@code true} if comments should be omitted when
|
||||
* storing properties in a file
|
||||
* @return a new {@code Properties} instance
|
||||
|
@ -373,16 +371,13 @@ public final class CollectionFactory {
|
|||
/**
|
||||
* Create a variant of {@link java.util.Properties} that sorts properties
|
||||
* alphanumerically based on their keys.
|
||||
*
|
||||
* <p>This can be useful when storing the {@code Properties} instance in a
|
||||
* properties file, since it allows such files to be generated in a repeatable
|
||||
* manner with consistent ordering of properties. Comments in generated
|
||||
* properties files can also be optionally omitted.
|
||||
*
|
||||
* <p>The returned {@code Properties} instance will be populated with
|
||||
* properties from the supplied {@code properties} object, but default
|
||||
* properties from the supplied {@code properties} object will not be copied.
|
||||
*
|
||||
* @param properties the {@code Properties} object from which to copy the
|
||||
* initial properties
|
||||
* @param omitComments {@code true} if comments should be omitted when
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Specialization of {@link Properties} that sorts properties alphanumerically
|
||||
* based on their keys.
|
||||
|
@ -49,11 +51,10 @@ class SortedProperties extends Properties {
|
|||
|
||||
static final String EOL = System.lineSeparator();
|
||||
|
||||
private static final Comparator<Object> keyComparator = //
|
||||
(key1, key2) -> String.valueOf(key1).compareTo(String.valueOf(key2));
|
||||
private static final Comparator<Object> keyComparator = Comparator.comparing(String::valueOf);
|
||||
|
||||
private static final Comparator<Entry<Object, Object>> entryComparator = Entry.comparingByKey(keyComparator);
|
||||
|
||||
private static final Comparator<Entry<Object, Object>> entryComparator = //
|
||||
Entry.comparingByKey(keyComparator);
|
||||
|
||||
private final boolean omitComments;
|
||||
|
||||
|
@ -61,7 +62,6 @@ class SortedProperties extends Properties {
|
|||
/**
|
||||
* Construct a new {@code SortedProperties} instance that honors the supplied
|
||||
* {@code omitComments} flag.
|
||||
*
|
||||
* @param omitComments {@code true} if comments should be omitted when
|
||||
* storing properties in a file
|
||||
*/
|
||||
|
@ -73,10 +73,8 @@ class SortedProperties extends Properties {
|
|||
* Construct a new {@code SortedProperties} instance with properties populated
|
||||
* from the supplied {@link Properties} object and honoring the supplied
|
||||
* {@code omitComments} flag.
|
||||
*
|
||||
* <p>Default properties from the supplied {@code Properties} object will
|
||||
* not be copied.
|
||||
*
|
||||
* @param properties the {@code Properties} object from which to copy the
|
||||
* initial properties
|
||||
* @param omitComments {@code true} if comments should be omitted when
|
||||
|
@ -87,8 +85,9 @@ class SortedProperties extends Properties {
|
|||
putAll(properties);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void store(OutputStream out, String comments) throws IOException {
|
||||
public void store(OutputStream out, @Nullable String comments) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
super.store(baos, (this.omitComments ? null : comments));
|
||||
String contents = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
|
||||
|
@ -100,7 +99,7 @@ class SortedProperties extends Properties {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void store(Writer writer, String comments) throws IOException {
|
||||
public void store(Writer writer, @Nullable String comments) throws IOException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
super.store(stringWriter, (this.omitComments ? null : comments));
|
||||
String contents = stringWriter.toString();
|
||||
|
@ -112,12 +111,12 @@ class SortedProperties extends Properties {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void storeToXML(OutputStream out, String comments) throws IOException {
|
||||
public void storeToXML(OutputStream out, @Nullable String comments) throws IOException {
|
||||
super.storeToXML(out, (this.omitComments ? null : comments));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeToXML(OutputStream out, String comments, String encoding) throws IOException {
|
||||
public void storeToXML(OutputStream out, @Nullable String comments, String encoding) throws IOException {
|
||||
super.storeToXML(out, (this.omitComments ? null : comments), encoding);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue