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

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.bluetooth.am43.internal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -42,7 +41,7 @@ public class AM43DiscoveryParticipant implements BluetoothDiscoveryParticipant {
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(AM43BindingConstants.THING_TYPE_AM43);
return Set.of(AM43BindingConstants.THING_TYPE_AM43);
}
@Override

View File

@@ -235,27 +235,28 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
}
switch (channelUID.getId()) {
case AM43BindingConstants.CHANNEL_ID_POSITION:
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
MotorSettings settings = motorSettings;
if (settings == null) {
logger.warn("Cannot set position before settings have been received.");
return;
}
if (!settings.isTopLimitSet() || !settings.isBottomLimitSet()) {
logger.warn("Cannot set position of blinds. Top or bottom limits have not been set. "
+ "Please configure manually.");
logger.warn("""
Cannot set position of blinds. Top or bottom limits have not been set. \
Please configure manually.\
""");
return;
}
PercentType percent = (PercentType) command;
int value = percent.intValue();
int value = percentCommand.intValue();
if (getAM43Config().invertPosition) {
value = 100 - value;
}
submitCommand(new SetPositionCommand(value));
return;
}
if (command instanceof StopMoveType) {
switch ((StopMoveType) command) {
if (command instanceof StopMoveType stopMoveCommand) {
switch (stopMoveCommand) {
case STOP:
submitCommand(new ControlCommand(ControlAction.STOP));
return;
@@ -264,8 +265,8 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
return;
}
}
if (command instanceof UpDownType) {
switch ((UpDownType) command) {
if (command instanceof UpDownType upDownCommand) {
switch (upDownCommand) {
case UP:
submitCommand(new ControlCommand(ControlAction.OPEN));
return;
@@ -276,11 +277,10 @@ public class AM43Handler extends ConnectedBluetoothHandler implements ResponseLi
}
return;
case AM43BindingConstants.CHANNEL_ID_SPEED:
if (command instanceof DecimalType) {
if (command instanceof DecimalType decimalCommand) {
MotorSettings settings = motorSettings;
if (settings != null) {
DecimalType speedType = (DecimalType) command;
settings.setSpeed(speedType.intValue());
settings.setSpeed(decimalCommand.intValue());
submitCommand(new SetSettingsCommand(settings));
} else {
logger.warn("Cannot set Speed before setting have been received");

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.bluetooth.am43.internal;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -33,8 +32,7 @@ import org.osgi.service.component.annotations.Component;
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.am43")
public class AM43HandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.singleton(AM43BindingConstants.THING_TYPE_AM43);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(AM43BindingConstants.THING_TYPE_AM43);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {