From 918ffacdf81d27f1027a1ad6dc25f2f823e37928 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Jun 2019 13:29:35 +0200 Subject: [PATCH] Polishing --- .../core/CollectionFactory.java | 7 +------ .../core/SortedProperties.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java index 084037c1e61..17d3ade7d40 100644 --- a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java @@ -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. * *

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. - * *

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. - * *

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. - * *

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 diff --git a/spring-core/src/main/java/org/springframework/core/SortedProperties.java b/spring-core/src/main/java/org/springframework/core/SortedProperties.java index 1ce05bb7c7e..21982621ec9 100644 --- a/spring-core/src/main/java/org/springframework/core/SortedProperties.java +++ b/spring-core/src/main/java/org/springframework/core/SortedProperties.java @@ -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 keyComparator = // - (key1, key2) -> String.valueOf(key1).compareTo(String.valueOf(key2)); + private static final Comparator keyComparator = Comparator.comparing(String::valueOf); + + private static final Comparator> entryComparator = Entry.comparingByKey(keyComparator); - private static final Comparator> 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. - * *

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); }