Skip to content

Commit

Permalink
fix spotbugs warning and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Nov 25, 2023
1 parent bb5425c commit 9074258
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions utility/src/main/java/com/dua3/utility/text/TextAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,10 @@ public static TextAttributes of(Iterable<Pair<String, ?>> entries) {
* @return TextAttributes instance
*/
public static TextAttributes of(Map<String, Object> map) {
Set<Entry<String, Object>> entries = map.entrySet();
SortedSet<Map.Entry<String, Object>> sortedEntries;
if (entries instanceof SortedSet<Entry<String, Object>> ss) {
sortedEntries = ss;
} else {
sortedEntries = new TreeSet<>(Map.Entry.comparingByKey());
// do not use addAll() due to DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS
entries.stream().map(Map.Entry::copyOf).forEach(sortedEntries::add);
}
return new TextAttributes(sortedEntries);
SortedSet<Map.Entry<String, Object>> entries = new TreeSet<>(Map.Entry.comparingByKey());
// do not use addAll() due to DMI_ENTRY_SETS_MAY_REUSE_ENTRY_OBJECTS
map.entrySet().stream().map(Map.Entry::copyOf).forEach(entries::add);
return new TextAttributes(entries);
}

/**
Expand Down

0 comments on commit 9074258

Please sign in to comment.