Java 17 features (T-Z) (#15576)
- 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:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.wifiled.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -32,7 +31,7 @@ public class WiFiLEDBindingConstants {
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_WIFILED = new ThingTypeUID(BINDING_ID, "wifiled");
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_WIFILED);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_WIFILED);
|
||||
|
||||
// List of all Channel IDs
|
||||
public static final String CHANNEL_POWER = "power";
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.wifiled.internal;
|
||||
|
||||
import static org.openhab.binding.wifiled.internal.WiFiLEDBindingConstants.THING_TYPE_WIFILED;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.openhab.binding.wifiled.internal.handler.WiFiLEDHandler;
|
||||
@@ -34,7 +33,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.wifiled")
|
||||
public class WiFiLEDHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_WIFILED);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_WIFILED);
|
||||
|
||||
@Override
|
||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||
|
||||
@@ -124,8 +124,8 @@ public class WiFiLEDHandler extends BaseThingHandler {
|
||||
} else if (channelUID.getId().equals(WiFiLEDBindingConstants.CHANNEL_WHITE2)) {
|
||||
handleWhite2Command(command);
|
||||
} else if (channelUID.getId().equals(WiFiLEDBindingConstants.CHANNEL_PROGRAM)
|
||||
&& (command instanceof StringType)) {
|
||||
driver.setProgram((StringType) command);
|
||||
&& (command instanceof StringType stringCommand)) {
|
||||
driver.setProgram(stringCommand);
|
||||
} else if (channelUID.getId().equals(WiFiLEDBindingConstants.CHANNEL_PROGRAM_SPEED)) {
|
||||
handleProgramSpeedCommand(command);
|
||||
}
|
||||
@@ -135,14 +135,13 @@ public class WiFiLEDHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void handleColorCommand(Command command) throws IOException {
|
||||
if (command instanceof HSBType) {
|
||||
driver.setColor((HSBType) command);
|
||||
} else if (command instanceof PercentType) {
|
||||
driver.setBrightness((PercentType) command);
|
||||
} else if (command instanceof OnOffType) {
|
||||
driver.setPower((OnOffType) command);
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
IncreaseDecreaseType increaseDecreaseType = (IncreaseDecreaseType) command;
|
||||
if (command instanceof HSBType hsbCommand) {
|
||||
driver.setColor(hsbCommand);
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
driver.setBrightness(percentCommand);
|
||||
} else if (command instanceof OnOffType onOffCommand) {
|
||||
driver.setPower(onOffCommand);
|
||||
} else if (command instanceof IncreaseDecreaseType increaseDecreaseType) {
|
||||
if (increaseDecreaseType.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
driver.incBrightness(INC_DEC_STEP);
|
||||
} else {
|
||||
@@ -152,18 +151,16 @@ public class WiFiLEDHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void handleWhiteCommand(Command command) throws IOException {
|
||||
if (command instanceof PercentType) {
|
||||
driver.setWhite((PercentType) command);
|
||||
} else if (command instanceof OnOffType) {
|
||||
OnOffType onOffCommand = (OnOffType) command;
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
driver.setWhite(percentCommand);
|
||||
} else if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand.equals(OnOffType.ON)) {
|
||||
driver.setWhite(PercentType.HUNDRED);
|
||||
} else {
|
||||
driver.setWhite(PercentType.ZERO);
|
||||
}
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
IncreaseDecreaseType increaseDecreaseType = (IncreaseDecreaseType) command;
|
||||
if (increaseDecreaseType.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||
if (increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
driver.incWhite(INC_DEC_STEP);
|
||||
} else {
|
||||
driver.decWhite(INC_DEC_STEP);
|
||||
@@ -172,18 +169,16 @@ public class WiFiLEDHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void handleWhite2Command(Command command) throws IOException {
|
||||
if (command instanceof PercentType) {
|
||||
driver.setWhite2((PercentType) command);
|
||||
} else if (command instanceof OnOffType) {
|
||||
OnOffType onOffCommand = (OnOffType) command;
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
driver.setWhite2(percentCommand);
|
||||
} else if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand.equals(OnOffType.ON)) {
|
||||
driver.setWhite2(PercentType.HUNDRED);
|
||||
} else {
|
||||
driver.setWhite2(PercentType.ZERO);
|
||||
}
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
IncreaseDecreaseType increaseDecreaseType = (IncreaseDecreaseType) command;
|
||||
if (increaseDecreaseType.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||
if (increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
driver.incWhite2(INC_DEC_STEP);
|
||||
} else {
|
||||
driver.decWhite2(INC_DEC_STEP);
|
||||
@@ -192,18 +187,16 @@ public class WiFiLEDHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void handleProgramSpeedCommand(Command command) throws IOException {
|
||||
if (command instanceof PercentType) {
|
||||
driver.setProgramSpeed((PercentType) command);
|
||||
} else if (command instanceof OnOffType) {
|
||||
OnOffType onOffCommand = (OnOffType) command;
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
driver.setProgramSpeed(percentCommand);
|
||||
} else if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand.equals(OnOffType.ON)) {
|
||||
driver.setProgramSpeed(PercentType.HUNDRED);
|
||||
} else {
|
||||
driver.setProgramSpeed(PercentType.ZERO);
|
||||
}
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
IncreaseDecreaseType increaseDecreaseType = (IncreaseDecreaseType) command;
|
||||
if (increaseDecreaseType.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
|
||||
if (increaseDecreaseCommand.equals(IncreaseDecreaseType.INCREASE)) {
|
||||
driver.incProgramSpeed(INC_DEC_STEP);
|
||||
} else {
|
||||
driver.decProgramSpeed(INC_DEC_STEP);
|
||||
|
||||
Reference in New Issue
Block a user