Java 17 features (H-M) (#15520)

- 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
- remove null check before instanceof

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-08 14:36:59 +02:00
committed by GitHub
parent 3751fd0646
commit edaf17b345
519 changed files with 2703 additions and 2660 deletions

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.icalendar.internal;
import static org.openhab.binding.icalendar.internal.ICalendarBindingConstants.*;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -52,8 +51,8 @@ import org.slf4j.LoggerFactory;
public class ICalendarHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
.of(Collections.singleton(THING_TYPE_CALENDAR), Collections.singleton(THING_TYPE_FILTERED_EVENTS))
.flatMap(Set::stream).collect(Collectors.toSet());
.of(Set.of(THING_TYPE_CALENDAR), Set.of(THING_TYPE_FILTERED_EVENTS)).flatMap(Set::stream)
.collect(Collectors.toSet());
private final Logger logger = LoggerFactory.getLogger(ICalendarHandlerFactory.class);
private final HttpClient sharedHttpClient;
@@ -81,8 +80,8 @@ public class ICalendarHandlerFactory extends BaseThingHandlerFactory {
return null;
}
if (thingTypeUID.equals(THING_TYPE_CALENDAR)) {
if (thing instanceof Bridge) {
return new ICalendarHandler((Bridge) thing, sharedHttpClient, eventPublisher, tzProvider);
if (thing instanceof Bridge bridge) {
return new ICalendarHandler(bridge, sharedHttpClient, eventPublisher, tzProvider);
} else {
logger.warn(
"The API of iCalendar has changed. You have to recreate the calendar according to the docs.");

View File

@@ -232,18 +232,19 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda
thingBuilder.withoutChannel(toDelete.getUID());
});
resultChannels.stream().filter((ResultChannelSet current) -> {
return (getThing().getChannelsOfGroup(current.resultGroup.toString()).size() == 0);
}).forEach((ResultChannelSet current) -> {
for (ChannelBuilder builder : handlerCallback.createChannelBuilders(current.resultGroup,
GROUP_TYPE_UID)) {
Channel currentChannel = builder.build();
Channel existingChannel = getThing().getChannel(currentChannel.getUID());
if (existingChannel == null) {
thingBuilder.withChannel(currentChannel);
}
}
});
resultChannels
.stream().filter((ResultChannelSet current) -> (getThing()
.getChannelsOfGroup(current.resultGroup.toString()).isEmpty()))
.forEach((ResultChannelSet current) -> {
for (ChannelBuilder builder : handlerCallback.createChannelBuilders(current.resultGroup,
GROUP_TYPE_UID)) {
Channel currentChannel = builder.build();
Channel existingChannel = getThing().getChannel(currentChannel.getUID());
if (existingChannel == null) {
thingBuilder.withChannel(currentChannel);
}
}
});
}
updateThing(thingBuilder.build());
}

View File

@@ -451,10 +451,10 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
* @param childHandler the handler to be updated
*/
private void updateChild(@Nullable ThingHandler childHandler) {
if (childHandler instanceof CalendarUpdateListener) {
if (childHandler instanceof CalendarUpdateListener updateListener) {
logger.trace("Notifying {} about fresh calendar.", childHandler.getThing().getUID());
try {
((CalendarUpdateListener) childHandler).onCalendarUpdated();
updateListener.onCalendarUpdated();
} catch (Exception e) {
logger.trace("The update of a child handler failed. Ignoring.", e);
}

View File

@@ -21,12 +21,12 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
*/
@NonNullByDefault
public class EventTextFilter {
public static enum Type {
public enum Type {
TEXT,
REGEX
}
public static enum Field {
public enum Field {
SUMMARY,
DESCRIPTION,
COMMENT,