Java 17 features (N-S) (#15565)

- 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-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.sensibo.internal.discovery;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -39,8 +38,8 @@ import org.slf4j.LoggerFactory;
*/
@NonNullByDefault
public class SensiboDiscoveryService extends AbstractDiscoveryService {
public static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections
.singleton(SensiboBindingConstants.THING_TYPE_SENSIBOSKY);
public static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Set
.of(SensiboBindingConstants.THING_TYPE_SENSIBOSKY);
private static final long REFRESH_INTERVAL_MINUTES = 60;
private final Logger logger = LoggerFactory.getLogger(SensiboDiscoveryService.class);
private final SensiboAccountHandler accountHandler;
@@ -67,7 +66,7 @@ public class SensiboDiscoveryService extends AbstractDiscoveryService {
final SensiboModel model = accountHandler.getModel();
for (final SensiboSky pod : model.getPods()) {
final ThingUID podUID = new ThingUID(SensiboBindingConstants.THING_TYPE_SENSIBOSKY, accountUID,
String.valueOf(pod.getMacAddress()));
pod.getMacAddress());
Map<String, String> properties = pod.getThingProperties();
// DiscoveryResult result uses Map<String,Object> as properties while ThingBuilder uses

View File

@@ -16,7 +16,6 @@ import static org.openhab.binding.sensibo.internal.SensiboBindingConstants.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -190,8 +189,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else if (command instanceof DecimalType) {
final DecimalType newValue = (DecimalType) command;
} else if (command instanceof DecimalType newValue) {
updateTimer(newValue.intValue());
} else {
updateTimer(null);
@@ -205,8 +203,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else if (command instanceof StringType) {
final StringType newValue = (StringType) command;
} else if (command instanceof StringType newValue) {
updateAcState(sensiboSky, FAN_LEVEL_PROPERTY, newValue.toString());
}
}
@@ -218,8 +215,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else if (command instanceof StringType) {
final StringType newValue = (StringType) command;
} else if (command instanceof StringType newValue) {
updateAcState(sensiboSky, SWING_PROPERTY, newValue.toString());
}
}
@@ -231,8 +227,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else if (command instanceof StringType) {
final StringType newValue = (StringType) command;
} else if (command instanceof StringType newValue) {
updateAcState(sensiboSky, MODE_PROPERTY, newValue.toString());
addDynamicChannelsAndProperties(sensiboSky);
}
@@ -249,11 +244,10 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
updateState(channelUID, UnDefType.UNDEF);
}
});
if (!sensiboSky.getAcState().isPresent()) {
if (sensiboSky.getAcState().isEmpty()) {
updateState(channelUID, UnDefType.UNDEF);
}
} else if (command instanceof QuantityType<?>) {
QuantityType<?> newValue = (QuantityType<?>) command;
} else if (command instanceof QuantityType<?> newValue) {
if (!Objects.equals(sensiboSky.getTemperatureUnit(), newValue.getUnit())) {
// If quantity is given in celsius when fahrenheit is used or opposite
try {
@@ -296,7 +290,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(CallbackChannelsTypeProvider.class);
return Set.of(CallbackChannelsTypeProvider.class);
}
@Override
@@ -379,7 +373,7 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
final ChannelTypeUID channelTypeUID = new ChannelTypeUID(SensiboBindingConstants.BINDING_ID,
channelTypePrefix + getThing().getUID().getId());
final List<StateOption> stateOptions = options.stream()
.map(e -> new StateOption(e.toString(), e instanceof String ? beautify((String) e) : e.toString()))
.map(e -> new StateOption(e.toString(), e instanceof String s ? beautify(s) : e.toString()))
.collect(Collectors.toList());
StateDescriptionFragmentBuilder stateDescription = StateDescriptionFragmentBuilder.create().withReadOnly(false)