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

@@ -71,10 +71,13 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory {
if (dSSUID != null) {
return super.createThing(thingTypeUID, configuration, dSSUID, null);
} else {
logger.error("Can't generate thing UID for thing type {}"
+ ", because digitalSTROM-Server is not reachable. Please check these points:\n"
+ "Are the server address and portnumber correct?\n" + "Is the server turned on?\n"
+ "Is the network configured correctly?", thingTypeUID);
logger.error("""
Can't generate thing UID for thing type {}\
, because digitalSTROM-Server is not reachable. Please check these points:
Are the server address and portnumber correct?
Is the server turned on?
Is the network configured correctly?\
""", thingTypeUID);
return null;
}
}

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.digitalstrom.internal.discovery;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -48,7 +47,7 @@ public class BridgeMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE);
return Set.of(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE);
}
@Override

View File

@@ -108,8 +108,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService {
private void onDeviceAddedInternal(GeneralDeviceInformation device) {
boolean isSupported = false;
if (device instanceof Device) {
Device tempDevice = (Device) device;
if (device instanceof Device tempDevice) {
if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", "")))
|| (deviceType.equals(tempDevice.getHWinfo().substring(0, 2))
&& (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice())
@@ -135,18 +134,17 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService {
thingDiscovered(discoveryResult);
} else {
if (device instanceof Device) {
logger.debug("Discovered unsupported device hardware type '{}' with uid {}",
((Device) device).getHWinfo(), device.getDSUID());
if (device instanceof Device device1) {
logger.debug("Discovered unsupported device hardware type '{}' with uid {}", device1.getHWinfo(),
device.getDSUID());
}
}
} else {
if (device instanceof Device) {
logger.debug(
"Discovered device with disabled or no output mode. Device was not added to inbox. "
+ "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}",
((Device) device).getHWinfo(), device.getDSUID(), device.getName(),
((Device) device).getOutputMode());
if (device instanceof Device device1) {
logger.debug("""
Discovered device with disabled or no output mode. Device was not added to inbox. \
Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}\
""", device1.getHWinfo(), device.getDSUID(), device.getName(), device1.getOutputMode());
}
}
}
@@ -154,8 +152,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService {
private ThingUID getThingUID(GeneralDeviceInformation device) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
ThingTypeUID thingTypeUID = null;
if (device instanceof Device) {
Device tempDevice = (Device) device;
if (device instanceof Device tempDevice) {
thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2));
if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) {
thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType);
@@ -166,8 +163,7 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService {
}
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingDeviceId = device.getDSID().toString();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
return thingUID;
return new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
} else {
return null;
}

View File

@@ -96,22 +96,19 @@ public class DiscoveryServiceManager
public void unregisterDiscoveryServices(BundleContext bundleContext) {
if (discoveryServices != null) {
for (AbstractDiscoveryService service : discoveryServices.values()) {
if (service instanceof SceneDiscoveryService) {
SceneDiscoveryService sceneDisServ = (SceneDiscoveryService) service;
if (service instanceof SceneDiscoveryService sceneDisServ) {
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(bridgeUID + sceneDisServ.getID());
sceneDisServ.deactivate();
serviceReg.unregister();
discoveryServiceRegs.remove(bridgeUID + sceneDisServ.getID());
}
if (service instanceof DeviceDiscoveryService) {
DeviceDiscoveryService devDisServ = (DeviceDiscoveryService) service;
if (service instanceof DeviceDiscoveryService devDisServ) {
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(bridgeUID + devDisServ.getID());
devDisServ.deactivate();
serviceReg.unregister();
discoveryServiceRegs.remove(bridgeUID + devDisServ.getID());
}
if (service instanceof ZoneTemperatureControlDiscoveryService) {
ZoneTemperatureControlDiscoveryService devDisServ = (ZoneTemperatureControlDiscoveryService) service;
if (service instanceof ZoneTemperatureControlDiscoveryService devDisServ) {
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(bridgeUID + devDisServ.getID());
devDisServ.deactivate();
serviceReg.unregister();
@@ -130,18 +127,17 @@ public class DiscoveryServiceManager
public void registerDiscoveryServices(BundleContext bundleContext) {
if (discoveryServices != null) {
for (AbstractDiscoveryService service : discoveryServices.values()) {
if (service instanceof SceneDiscoveryService) {
this.discoveryServiceRegs.put(bridgeUID + ((SceneDiscoveryService) service).getID(), bundleContext
if (service instanceof SceneDiscoveryService discoveryService) {
this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext
.registerService(DiscoveryService.class.getName(), service, new Hashtable<>()));
}
if (service instanceof DeviceDiscoveryService) {
this.discoveryServiceRegs.put(bridgeUID + ((DeviceDiscoveryService) service).getID(), bundleContext
if (service instanceof DeviceDiscoveryService discoveryService) {
this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext
.registerService(DiscoveryService.class.getName(), service, new Hashtable<>()));
}
if (service instanceof ZoneTemperatureControlDiscoveryService) {
this.discoveryServiceRegs
.put(bridgeUID + ((ZoneTemperatureControlDiscoveryService) service).getID(), bundleContext
.registerService(DiscoveryService.class.getName(), service, new Hashtable<>()));
if (service instanceof ZoneTemperatureControlDiscoveryService discoveryService) {
this.discoveryServiceRegs.put(bridgeUID + discoveryService.getID(), bundleContext
.registerService(DiscoveryService.class.getName(), service, new Hashtable<>()));
}
}
}
@@ -178,10 +174,10 @@ public class DiscoveryServiceManager
@Override
public void onDeviceRemoved(GeneralDeviceInformation device) {
if (device instanceof Device) {
String id = ((Device) device).getHWinfo().substring(0, 2);
if (((Device) device).isSensorDevice()) {
id = ((Device) device).getHWinfo().replace("-", "");
if (device instanceof Device dev) {
String id = dev.getHWinfo().substring(0, 2);
if (dev.isSensorDevice()) {
id = dev.getHWinfo().replace("-", "");
}
if (discoveryServices.get(id) != null) {
((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceRemoved(device);
@@ -198,10 +194,10 @@ public class DiscoveryServiceManager
@Override
public void onDeviceAdded(GeneralDeviceInformation device) {
try {
if (device instanceof Device) {
String id = ((Device) device).getHWinfo().substring(0, 2);
if (((Device) device).isSensorDevice()) {
id = ((Device) device).getHWinfo();
if (device instanceof Device dev) {
String id = dev.getHWinfo().substring(0, 2);
if (dev.isSensorDevice()) {
id = dev.getHWinfo();
}
if (discoveryServices.get(id) != null) {
((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device);

View File

@@ -173,8 +173,7 @@ public class SceneDiscoveryService extends AbstractDiscoveryService {
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingSceneId = scene.getID();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingSceneId);
return thingUID;
return new ThingUID(thingTypeUID, bridgeUID, thingSceneId);
} else {
return null;
}

View File

@@ -117,8 +117,7 @@ public class ZoneTemperatureControlDiscoveryService extends AbstractDiscoverySer
ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, thingTypeID);
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingID = tempControlStatus.getZoneID().toString();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingID);
return thingUID;
return new ThingUID(thingTypeUID, bridgeUID, thingID);
} else {
return null;
}

View File

@@ -17,7 +17,6 @@ import static org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConst
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -95,7 +94,7 @@ public class BridgeHandler extends BaseBridgeHandler
/**
* Contains all supported thing types of this handler
*/
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_DSS_BRIDGE);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DSS_BRIDGE);
private static final long RECONNECT_TRACKER_INTERVAL = 15;
@@ -631,8 +630,10 @@ public class BridgeHandler extends BaseBridgeHandler
switch (reason) {
case WRONG_APP_TOKEN:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"User defined Application-Token is wrong. "
+ "Please set user name and password to generate an Application-Token or set a valid Application-Token.");
"""
User defined Application-Token is wrong. \
Please set user name and password to generate an Application-Token or set a valid Application-Token.\
""");
stopServices();
return;
case WRONG_USER_OR_PASSWORD:
@@ -655,10 +656,12 @@ public class BridgeHandler extends BaseBridgeHandler
return;
}
case HOST_NOT_FOUND:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Server not found! Please check these points:\n" + " - Is digitalSTROM-Server turned on?\n"
+ " - Is the host address correct?\n"
+ " - Is the ethernet cable connection established?");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, """
Server not found! Please check these points:
- Is digitalSTROM-Server turned on?
- Is the host address correct?
- Is the ethernet cable connection established?\
""");
break;
case UNKNOWN_HOST:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,

View File

@@ -111,8 +111,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
dssBridgeHandler = (BridgeHandler) handler;
if (handler instanceof BridgeHandler bridgeHandler) {
dssBridgeHandler = bridgeHandler;
} else {
return null;
}
@@ -179,8 +179,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList
@Override
public void onDeviceRemoved(GeneralDeviceInformation device) {
if (device instanceof Circuit) {
this.circuit = (Circuit) device;
if (device instanceof Circuit circ) {
this.circuit = circ;
if (getThing().getStatus().equals(ThingStatus.ONLINE)) {
if (!circuit.isPresent()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
@@ -197,8 +197,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList
@Override
public void onDeviceAdded(GeneralDeviceInformation device) {
if (device instanceof Circuit) {
this.circuit = (Circuit) device;
if (device instanceof Circuit circ) {
this.circuit = circ;
if (this.circuit.isPresent()) {
ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo();
updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());

View File

@@ -204,9 +204,9 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
}
} else if (!device.isShade()) {
if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
device.setOutputValue(
(short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
(short) fromPercentToValue(percentCommand.intValue(), device.getMaxOutputValue()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setIsOn(true);
@@ -219,17 +219,17 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
} else {
device.decrease();
}
} else if (command instanceof StringType) {
device.setOutputValue(Short.parseShort(((StringType) command).toString()));
} else if (command instanceof StringType stringCommand) {
device.setOutputValue(Short.parseShort(stringCommand.toString()));
}
} else {
logger.debug("Command sent to an unknown channel id: {}", channelUID);
}
} else {
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
if (command instanceof PercentType) {
if (command instanceof PercentType percentCommand) {
device.setAnglePosition(
(short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
(short) fromPercentToValue(percentCommand.intValue(), device.getMaxSlatAngle()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setAnglePosition(device.getMaxSlatAngle());
@@ -244,9 +244,9 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
}
}
} else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
if (command instanceof PercentType) {
int percent = ((PercentType) command).intValue();
if (!device.getHWinfo().equals("GR-KL200")) {
if (command instanceof PercentType percentCommand) {
int percent = percentCommand.intValue();
if (!"GR-KL200".equals(device.getHWinfo())) {
percent = 100 - percent;
}
device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
@@ -291,8 +291,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
dssBridgeHandler = (BridgeHandler) handler;
if (handler instanceof BridgeHandler bridgeHandler) {
dssBridgeHandler = bridgeHandler;
} else {
return null;
}
@@ -398,7 +398,7 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
default:
return;
}
if (!device.getHWinfo().equals("GR-KL210")) {
if (!"GR-KL210".equals(device.getHWinfo())) {
percent = 100 - percent;
}
updateState(DsChannelTypeProvider.SHADE, new PercentType(percent));
@@ -418,10 +418,10 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
@Override
public synchronized void onDeviceRemoved(GeneralDeviceInformation device) {
if (device instanceof Device) {
this.device = (Device) device;
if (device instanceof Device dev) {
this.device = dev;
if (this.getThing().getStatus().equals(ThingStatus.ONLINE)) {
if (!((Device) device).isPresent()) {
if (!dev.isPresent()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
"Device is not present in the digitalSTROM-System.");
} else {
@@ -436,8 +436,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
@Override
public synchronized void onDeviceAdded(GeneralDeviceInformation device) {
if (device instanceof Device) {
this.device = (Device) device;
if (device instanceof Device dev) {
this.device = dev;
if (this.device.isPresent()) {
ThingStatusInfo statusInfo = this.dssBridgeHandler.getThing().getStatusInfo();
updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
@@ -458,11 +458,11 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
checkOutputChannel();
} else if (this.device.isBlind()) {
// load channel for set the angle of jalousie devices
ApplicationGroup.Color color = ((Device) device).getFunctionalColorGroup() != null
? ((Device) device).getFunctionalColorGroup().getColor()
ApplicationGroup.Color color = dev.getFunctionalColorGroup() != null
? dev.getFunctionalColorGroup().getColor()
: null;
String channelTypeID = DsChannelTypeProvider.getOutputChannelTypeID(color,
((Device) device).getOutputMode(), ((Device) device).getOutputChannels());
String channelTypeID = DsChannelTypeProvider.getOutputChannelTypeID(color, dev.getOutputMode(),
dev.getOutputChannels());
loadOutputChannel(new ChannelTypeUID(BINDING_ID, channelTypeID),
DsChannelTypeProvider.getItemType(channelTypeID));
}
@@ -595,8 +595,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
if (loadedSensorChannels == null) {
loadedSensorChannels = new LinkedList<>();
}
if (!loadedSensorChannels.contains(sensorChannelType.toString())) {
return loadedSensorChannels.add(sensorChannelType.toString());
if (!loadedSensorChannels.contains(sensorChannelType)) {
return loadedSensorChannels.add(sensorChannelType);
}
return false;
}

View File

@@ -312,8 +312,8 @@ public class SceneHandler extends BaseThingHandler implements SceneStatusListene
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
this.bridgeHandler = (BridgeHandler) handler;
if (handler instanceof BridgeHandler bridgeHandler) {
this.bridgeHandler = bridgeHandler;
} else {
logger.debug("BridgeHandler cannot be found");
return null;

View File

@@ -28,6 +28,7 @@ import org.openhab.binding.digitalstrom.internal.lib.climate.constants.ControlSt
import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus;
import org.openhab.binding.digitalstrom.internal.lib.listener.TemperatureControlStatusListener;
import org.openhab.binding.digitalstrom.internal.lib.manager.StructureManager;
import org.openhab.binding.digitalstrom.internal.lib.manager.impl.TemperatureControlManager;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.ApplicationGroup;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputChannelEnum;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputModeEnum;
@@ -257,8 +258,8 @@ public class ZoneTemperatureControlHandler extends BaseThingHandler implements T
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
dssBridgeHandler = (BridgeHandler) handler;
if (handler instanceof BridgeHandler bridgeHandler) {
dssBridgeHandler = bridgeHandler;
} else {
return null;
}

View File

@@ -610,9 +610,7 @@ public class DeviceStatusManagerImpl implements DeviceStatusManager {
@Override
public boolean equals(Object object) {
return object instanceof TrashDevice
? this.device.getDSID().equals(((TrashDevice) object).getDevice().getDSID())
: false;
return object instanceof TrashDevice td ? this.device.getDSID().equals(td.getDevice().getDSID()) : false;
}
}

View File

@@ -464,7 +464,7 @@ public class SceneManagerImpl implements SceneManager {
@Override
public void scenesGenerated(char[] scenesGenerated) {
if (String.valueOf(scenesGenerated).equals("1111")) {
if ("1111".equals(String.valueOf(scenesGenerated))) {
this.scenesGenerated = true;
stateChanged(ManagerStates.RUNNING);
}

View File

@@ -79,8 +79,7 @@ public class DeviceConsumptionSensorJob implements SensorJob {
@Override
public boolean equals(Object obj) {
if (obj instanceof DeviceConsumptionSensorJob) {
DeviceConsumptionSensorJob other = (DeviceConsumptionSensorJob) obj;
if (obj instanceof DeviceConsumptionSensorJob other) {
String device = this.device.getDSID().getValue() + this.sensorType.getSensorType();
return device.equals(other.device.getDSID().getValue() + other.sensorType.getSensorType());
}

View File

@@ -85,8 +85,7 @@ public class DeviceOutputValueSensorJob implements SensorJob {
@Override
public boolean equals(Object obj) {
if (obj instanceof DeviceOutputValueSensorJob) {
DeviceOutputValueSensorJob other = (DeviceOutputValueSensorJob) obj;
if (obj instanceof DeviceOutputValueSensorJob other) {
String key = this.device.getDSID().getValue() + this.index;
return key.equals((other.device.getDSID().getValue() + other.index));
}

View File

@@ -62,8 +62,7 @@ public class SceneConfigReadingJob implements SensorJob {
@Override
public boolean equals(Object obj) {
if (obj instanceof SceneConfigReadingJob) {
SceneConfigReadingJob other = (SceneConfigReadingJob) obj;
if (obj instanceof SceneConfigReadingJob other) {
String str = other.device.getDSID().getValue() + "-" + other.sceneID;
return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str);
}

View File

@@ -65,8 +65,7 @@ public class SceneOutputValueReadingJob implements SensorJob {
@Override
public boolean equals(Object obj) {
if (obj instanceof SceneOutputValueReadingJob) {
SceneOutputValueReadingJob other = (SceneOutputValueReadingJob) obj;
if (obj instanceof SceneOutputValueReadingJob other) {
String str = other.device.getDSID().getValue() + "-" + other.sceneID;
return (this.device.getDSID().getValue() + "-" + this.sceneID).equals(str);
}

View File

@@ -931,8 +931,9 @@ public class DsAPIImpl implements DsAPI {
.addRequestClass(ClassKeys.ZONE).addFunction(FunctionKeys.SET_TEMEPERATURE_CONTROL_VALUE)
.addDefaultZoneParameter(sessionToken, zoneID, zoneName);
for (Object[] objAry : controlValues) {
if (objAry.length == 2 && objAry[0] instanceof String && objAry[1] instanceof Integer) {
builder.addParameter((String) objAry[0], SimpleRequestBuilder.objectToString(objAry[1]));
if (objAry.length == 2 && objAry[0] instanceof String stringValue
&& objAry[1] instanceof Integer) {
builder.addParameter(stringValue, SimpleRequestBuilder.objectToString(objAry[1]));
} else {
builder.buildRequestString();
throw new IllegalArgumentException(

View File

@@ -61,7 +61,7 @@ public class JSONResponseHandler {
* @return jsonObject
*/
public static JsonObject toJsonObject(String jsonResponse) {
if (jsonResponse != null && !jsonResponse.trim().equals("")) {
if (jsonResponse != null && !"".equals(jsonResponse.trim())) {
try {
return (JsonObject) JsonParser.parseString(jsonResponse);
} catch (JsonParseException e) {

View File

@@ -283,11 +283,11 @@ public class SimpleRequestBuilder {
if (obj == null) {
return null;
}
if (obj instanceof DSID) {
return ((DSID) obj).getValue();
if (obj instanceof DSID id) {
return id.getValue();
}
if (obj instanceof Number) {
return ((Number) obj).intValue() > -1 ? obj.toString() : null;
if (obj instanceof Number number) {
return number.intValue() > -1 ? obj.toString() : null;
}
return obj.toString();
}

View File

@@ -54,8 +54,8 @@ public class DSID {
@Override
public boolean equals(Object obj) {
if (obj instanceof DSID) {
return ((DSID) obj).getValue().equals(this.getValue());
if (obj instanceof DSID id) {
return id.getValue().equals(this.getValue());
}
return false;
}

View File

@@ -47,8 +47,8 @@ public class DSUID {
@Override
public boolean equals(Object obj) {
if (obj instanceof DSUID) {
return ((DSUID) obj).getValue().equals(this.getValue());
if (obj instanceof DSUID id) {
return id.getValue().equals(this.getValue());
}
return false;
}

View File

@@ -85,8 +85,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate {
if (value instanceof Short) {
return ((Short) value).intValue();
}
if (value instanceof String) {
return Integer.parseInt((String) value);
if (value instanceof String string) {
return Integer.parseInt(string);
}
} catch (Exception e) {
throw new ClassCastException();
@@ -105,8 +105,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate {
if (value instanceof Short) {
return ((Short) value).toString();
}
if (value instanceof String) {
return (String) value;
if (value instanceof String string) {
return string;
}
throw new ClassCastException();
}
@@ -128,8 +128,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate {
if (value instanceof Short) {
return (Short) value;
}
if (value instanceof String) {
return Short.parseShort((String) value);
if (value instanceof String string) {
return Short.parseShort(string);
}
} catch (Exception e) {
throw new ClassCastException();
@@ -149,8 +149,8 @@ public class DeviceStateUpdateImpl implements DeviceStateUpdate {
if (value instanceof Short) {
return ((Short) value).floatValue();
}
if (value instanceof String) {
return Float.parseFloat((String) value);
if (value instanceof String string) {
return Float.parseFloat(string);
}
} catch (Exception e) {
throw new ClassCastException();

View File

@@ -952,8 +952,7 @@ public class DeviceImpl extends AbstractGeneralDeviceInformations implements Dev
@Override
public boolean equals(Object obj) {
if (obj instanceof Device) {
Device device = (Device) obj;
if (obj instanceof Device device) {
return device.getDSID().equals(this.getDSID());
}
return false;
@@ -1781,7 +1780,7 @@ public class DeviceImpl extends AbstractGeneralDeviceInformations implements Dev
String[] scenes = propertries.split("\n");
for (int i = 0; i < scenes.length; i++) {
logger.debug("Find saved scene configuration for device with dSID {} and sceneID {}", dsid, i);
String[] sceneIdToConfig = scenes[i].replaceAll(" ", "").split("=");
String[] sceneIdToConfig = scenes[i].replace(" ", "").split("=");
String[] sceneParm = sceneIdToConfig[1].split(",");
JSONDeviceSceneSpecImpl sceneSpecNew = null;
int sceneValue = -1;

View File

@@ -75,8 +75,7 @@ public class JSONDetailedGroupInfoImpl implements DetailedGroupInfo {
@Override
public boolean equals(Object obj) {
if (obj instanceof DetailedGroupInfo) {
DetailedGroupInfo group = (DetailedGroupInfo) obj;
if (obj instanceof DetailedGroupInfo group) {
return group.getGroupID() == this.getGroupID();
}
return false;

View File

@@ -129,8 +129,7 @@ public class JSONZoneImpl implements Zone {
@Override
public boolean equals(Object obj) {
if (obj instanceof Zone) {
Zone other = (Zone) obj;
if (obj instanceof Zone other) {
return (other.getZoneId() == this.getZoneId());
}
return false;

View File

@@ -62,7 +62,7 @@ public class DsDeviceThingTypeProvider extends BaseDsI18n implements ThingTypePr
* @author Michael Ochel - Initial contribution
* @author Matthias Siegele - Initial contribution
*/
public static enum SupportedThingTypes {
public enum SupportedThingTypes {
// ThingType, responsible ThingHanlder, Device config-description with power-sensors
GE(DeviceHandler.class.getSimpleName(), true),
GR(DeviceHandler.class.getSimpleName(), false),