Skip to content

Commit 259dd3d

Browse files
committed
Polishing
1 parent 918ffac commit 259dd3d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

spring-context-indexer/src/main/java/org/springframework/context/index/processor/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)