Skip to content

Commit 918ffac

Browse files
committed
Polishing
1 parent 98a49b4 commit 918ffac

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.springframework.util.ReflectionUtils;
4444

4545
/**
46-
* Factory for collections that is aware of Java 5, Java 6, and Spring collection types.
46+
* Factory for collections that is aware of common Java and Spring collection types.
4747
*
4848
* <p>Mainly for internal use within the framework.
4949
*
@@ -353,12 +353,10 @@ public String getProperty(String key) {
353353
/**
354354
* Create a variant of {@link java.util.Properties} that sorts properties
355355
* alphanumerically based on their keys.
356-
*
357356
* <p>This can be useful when storing the {@link Properties} instance in a
358357
* properties file, since it allows such files to be generated in a repeatable
359358
* manner with consistent ordering of properties. Comments in generated
360359
* properties files can also be optionally omitted.
361-
*
362360
* @param omitComments {@code true} if comments should be omitted when
363361
* storing properties in a file
364362
* @return a new {@code Properties} instance
@@ -373,16 +371,13 @@ public static Properties createSortedProperties(boolean omitComments) {
373371
/**
374372
* Create a variant of {@link java.util.Properties} that sorts properties
375373
* alphanumerically based on their keys.
376-
*
377374
* <p>This can be useful when storing the {@code Properties} instance in a
378375
* properties file, since it allows such files to be generated in a repeatable
379376
* manner with consistent ordering of properties. Comments in generated
380377
* properties files can also be optionally omitted.
381-
*
382378
* <p>The returned {@code Properties} instance will be populated with
383379
* properties from the supplied {@code properties} object, but default
384380
* properties from the supplied {@code properties} object will not be copied.
385-
*
386381
* @param properties the {@code Properties} object from which to copy the
387382
* initial properties
388383
* @param omitComments {@code true} if comments should be omitted when

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Set;
3131
import java.util.TreeSet;
3232

33+
import org.springframework.lang.Nullable;
34+
3335
/**
3436
* Specialization of {@link Properties} that sorts properties alphanumerically
3537
* based on their keys.
@@ -49,19 +51,17 @@ class SortedProperties extends Properties {
4951

5052
static final String EOL = System.lineSeparator();
5153

52-
private static final Comparator<Object> keyComparator = //
53-
(key1, key2) -> String.valueOf(key1).compareTo(String.valueOf(key2));
54+
private static final Comparator<Object> keyComparator = Comparator.comparing(String::valueOf);
55+
56+
private static final Comparator<Entry<Object, Object>> entryComparator = Entry.comparingByKey(keyComparator);
5457

55-
private static final Comparator<Entry<Object, Object>> entryComparator = //
56-
Entry.comparingByKey(keyComparator);
5758

5859
private final boolean omitComments;
5960

6061

6162
/**
6263
* Construct a new {@code SortedProperties} instance that honors the supplied
6364
* {@code omitComments} flag.
64-
*
6565
* @param omitComments {@code true} if comments should be omitted when
6666
* storing properties in a file
6767
*/
@@ -73,10 +73,8 @@ class SortedProperties extends Properties {
7373
* Construct a new {@code SortedProperties} instance with properties populated
7474
* from the supplied {@link Properties} object and honoring the supplied
7575
* {@code omitComments} flag.
76-
*
7776
* <p>Default properties from the supplied {@code Properties} object will
7877
* not be copied.
79-
*
8078
* @param properties the {@code Properties} object from which to copy the
8179
* initial properties
8280
* @param omitComments {@code true} if comments should be omitted when
@@ -87,8 +85,9 @@ class SortedProperties extends Properties {
8785
putAll(properties);
8886
}
8987

88+
9089
@Override
91-
public void store(OutputStream out, String comments) throws IOException {
90+
public void store(OutputStream out, @Nullable String comments) throws IOException {
9291
ByteArrayOutputStream baos = new ByteArrayOutputStream();
9392
super.store(baos, (this.omitComments ? null : comments));
9493
String contents = new String(baos.toByteArray(), StandardCharsets.ISO_8859_1);
@@ -100,7 +99,7 @@ public void store(OutputStream out, String comments) throws IOException {
10099
}
101100

102101
@Override
103-
public void store(Writer writer, String comments) throws IOException {
102+
public void store(Writer writer, @Nullable String comments) throws IOException {
104103
StringWriter stringWriter = new StringWriter();
105104
super.store(stringWriter, (this.omitComments ? null : comments));
106105
String contents = stringWriter.toString();
@@ -112,12 +111,12 @@ public void store(Writer writer, String comments) throws IOException {
112111
}
113112

114113
@Override
115-
public void storeToXML(OutputStream out, String comments) throws IOException {
114+
public void storeToXML(OutputStream out, @Nullable String comments) throws IOException {
116115
super.storeToXML(out, (this.omitComments ? null : comments));
117116
}
118117

119118
@Override
120-
public void storeToXML(OutputStream out, String comments, String encoding) throws IOException {
119+
public void storeToXML(OutputStream out, @Nullable String comments, String encoding) throws IOException {
121120
super.storeToXML(out, (this.omitComments ? null : comments), encoding);
122121
}
123122

0 commit comments

Comments
 (0)