Java 17 features (A-G) (#15516)

- add missing @override
- Java style array syntax
- remove redundant modifiers
- always move String constants to left side in comparisons
- simplify lambda expressions and return statements
- use replace instead of replaceAll w/o regex
- instanceof matching and multiline strings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -17,7 +17,6 @@ import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.function.BiConsumer;
@@ -236,9 +235,9 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
private static List<String> listFromEventStatus(final @Nullable EventStatus value) {
if (value == null) {
return Collections.emptyList();
return List.of();
} else {
return Collections.singletonList(value.value());
return List.of(value.value());
}
}
@@ -247,14 +246,14 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
}
private static List<String> nullToEmptyList(@Nullable final List<String> value) {
return value == null ? Collections.emptyList() : value;
return value == null ? List.of() : value;
}
/**
* Returns a list containing only the given value or empty list if value is <code>null</code>.
*/
private static List<String> singletonList(@Nullable String value) {
return value == null ? Collections.emptyList() : Collections.singletonList(value);
return value == null ? List.of() : List.of(value);
}
private static OnOffType parseHidden(@Nullable Integer value) {
@@ -262,9 +261,7 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
}
private static Function<Event, @Nullable Date> getDate(final Function<Event, @Nullable String> getValue) {
return (final Event event) -> {
return parseDate(getValue.apply(event));
};
return (final Event event) -> parseDate(getValue.apply(event));
}
private static BiConsumer<Event, Date> setDate(final BiConsumer<Event, String> setter) {
@@ -331,7 +328,7 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
*/
private static List<String> mapMessagesToList(final @Nullable List<Message> messages) {
if (messages == null || messages.isEmpty()) {
return Collections.emptyList();
return List.of();
} else {
return messages //
.stream()//
@@ -360,18 +357,18 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
private static List<String> mapIntegerToStringList(@Nullable Integer value) {
if (value == null) {
return Collections.emptyList();
return List.of();
} else {
return Collections.singletonList(String.valueOf(value));
return List.of(String.valueOf(value));
}
}
private static List<String> mapDateToStringList(@Nullable Date value) {
if (value == null) {
return Collections.emptyList();
return List.of();
} else {
synchronized (DATETIME_FORMAT) {
return Collections.singletonList(DATETIME_FORMAT.format(value));
return List.of(DATETIME_FORMAT.format(value));
}
}
}

View File

@@ -121,7 +121,7 @@ public final class TripLabelAttribute<VALUE_TYPE, STATE_TYPE extends State> exte
if (value == null) {
return Collections.emptyList();
} else {
return Collections.singletonList(value.value());
return List.of(value.value());
}
}
@@ -129,7 +129,7 @@ public final class TripLabelAttribute<VALUE_TYPE, STATE_TYPE extends State> exte
* Returns a list containing only the given value or empty list if value is <code>null</code>.
*/
private static List<String> singletonList(@Nullable String value) {
return value == null ? Collections.emptyList() : Collections.singletonList(value);
return value == null ? Collections.emptyList() : List.of(value);
}
/**