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

@@ -14,9 +14,6 @@ package org.openhab.binding.cm11a.internal;
import static org.openhab.binding.cm11a.internal.CM11ABindingConstants.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.openhab.binding.cm11a.internal.handler.Cm11aApplianceHandler;
@@ -43,8 +40,7 @@ public class Cm11aHandlerFactory extends BaseThingHandlerFactory {
private final Logger logger = LoggerFactory.getLogger(Cm11aHandlerFactory.class);
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_SWITCH, THING_TYPE_DIMMER)));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SWITCH, THING_TYPE_DIMMER);
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {

View File

@@ -79,13 +79,13 @@ public class X10ReceivedData {
/**
* Lookup table to convert House code received from the cm11a into an X10 house code
*/
public static final char HOUSE_CODE[] = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L',
public static final char[] HOUSE_CODE = new char[] { 'M', 'E', 'C', 'K', 'O', 'G', 'A', 'I', 'N', 'F', 'D', 'L',
'P', 'H', 'B', 'J' };
/**
* Lookup table to convert Unit code received from the cm11a into an X10 unit code
*/
public static final byte UNIT_CODE[] = new byte[] { 13, 5, 3, 11, 15, 7, 1, 9, 14, 6, 4, 12, 16, 8, 2, 10 };
public static final byte[] UNIT_CODE = new byte[] { 13, 5, 3, 11, 15, 7, 1, 9, 14, 6, 4, 12, 16, 8, 2, 10 };
private String[] addr;
private X10COMMAND cmd;

View File

@@ -71,8 +71,8 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler {
desiredState = OnOffType.ON;
} else if (OnOffType.OFF.equals(command)) {
desiredState = OnOffType.OFF;
} else if (command instanceof PercentType) {
desiredState = (PercentType) command;
} else if (command instanceof PercentType percentCommand) {
desiredState = percentCommand;
} else if (command instanceof RefreshType) {
// Refresh is triggered by framework during startup.
// Force the lamp off by indicating it is currently on and we want it off
@@ -105,10 +105,10 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler {
x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_ON);
} else if (desiredState.equals(OnOffType.OFF)) {
x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_OFF);
} else if (desiredState instanceof PercentType) {
} else if (desiredState instanceof PercentType desiredStatePercent) {
// desiredState must be a PercentType if we got here.
// Calc how many bright increments we need to send (0 to 22)
int desiredPercentFullBright = ((PercentType) desiredState).intValue();
int desiredPercentFullBright = desiredStatePercent.intValue();
int dims = (desiredPercentFullBright * X10_DIM_INCREMENTS) / 100;
if (currentState.equals(OnOffType.ON)) {
// The current level isn't known because it would have gone to
@@ -120,11 +120,11 @@ public class Cm11aLampHandler extends Cm11aAbstractHandler {
// desiredState must be a PercentType if we got here. And, the light should be off
// We should just be able to send the appropriate number if dims
x10Status = x10Interface.sendFunction(houseUnitCode, X10Interface.FUNC_BRIGHT, dims);
} else if (currentState instanceof PercentType) {
} else if (currentState instanceof PercentType currentStatePercent) {
// This is the expected case
// Now currentState and desiredState are both PercentType's
// Need to calc how much to dim or brighten
int currentPercentFullBright = ((PercentType) currentState).intValue();
int currentPercentFullBright = currentStatePercent.intValue();
int percentToBrighten = desiredPercentFullBright - currentPercentFullBright;
int brightens = (percentToBrighten * X10_DIM_INCREMENTS) / 100;
if (brightens > 0) {