Rework more commons-lang usages (#10314)

* Reworks many commons-lang usages to use standard Java
* Updates all remaining commons.lang imports to commons.lang3

Related to openhab/openhab-addons#7722

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2021-03-16 12:38:16 +01:00
committed by GitHub
parent 16fba31556
commit f3503430b4
257 changed files with 906 additions and 1125 deletions

View File

@@ -18,7 +18,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.discovery.DiscoveryServiceManager;
import org.openhab.binding.digitalstrom.internal.handler.BridgeHandler;
import org.openhab.binding.digitalstrom.internal.handler.CircuitHandler;
@@ -139,8 +138,9 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory {
private ThingUID getDeviceUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration,
ThingUID bridgeUID) {
if (thingUID == null && StringUtils.isNotBlank((String) configuration.get(DEVICE_DSID))) {
return new ThingUID(thingTypeUID, bridgeUID, configuration.get(DEVICE_DSID).toString());
String id = (String) configuration.get(DEVICE_DSID);
if (thingUID == null && id != null && !id.isBlank()) {
return new ThingUID(thingTypeUID, bridgeUID, id);
}
return thingUID;
}
@@ -208,7 +208,8 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory {
return thingUID;
}
String dSID;
if (StringUtils.isBlank((String) configuration.get(DS_ID))) {
String configValue = (String) configuration.get(DS_ID);
if (configValue == null || configValue.isBlank()) {
dSID = getDSSid(configuration);
if (dSID != null) {
configuration.put(DS_ID, dSID);
@@ -225,13 +226,15 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory {
private String getDSSid(Configuration configuration) {
String dSID = null;
if (StringUtils.isNotBlank((String) configuration.get(HOST))) {
String host = configuration.get(HOST).toString();
String hostConfigValue = (String) configuration.get(HOST);
if (hostConfigValue != null && !hostConfigValue.isBlank()) {
String host = hostConfigValue;
String applicationToken = null;
String user = null;
String pw = null;
if (StringUtils.isNotBlank((String) configuration.get(APPLICATION_TOKEN))) {
String atConfigValue = (String) configuration.get(APPLICATION_TOKEN);
if (atConfigValue != null && !atConfigValue.isBlank()) {
applicationToken = configuration.get(APPLICATION_TOKEN).toString();
}
@@ -249,8 +252,9 @@ public class DigitalSTROMHandlerFactory extends BaseThingHandlerFactory {
}
private boolean checkUserPassword(Configuration configuration) {
return StringUtils.isNotBlank((String) configuration.get(USER_NAME))
&& StringUtils.isNotBlank((String) configuration.get(PASSWORD));
String userName = (String) configuration.get(USER_NAME);
String password = (String) configuration.get(PASSWORD);
return userName != null && !userName.isBlank() && password != null && !password.isBlank();
}
@Override

View File

@@ -21,16 +21,17 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.handler.BridgeHandler;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Circuit;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.GeneralDeviceInformation;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.OutputModeEnum;
import org.openhab.binding.digitalstrom.internal.providers.DsDeviceThingTypeProvider;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.slf4j.Logger;
@@ -126,10 +127,8 @@ public class DeviceDiscoveryService extends AbstractDiscoveryService {
if (thingUID != null) {
Map<String, Object> properties = new HashMap<>(1);
properties.put(DigitalSTROMBindingConstants.DEVICE_DSID, device.getDSID().getValue());
String deviceName = null;
if (StringUtils.isNotBlank(device.getName())) {
deviceName = device.getName();
} else {
String deviceName = device.getName();
if (deviceName == null || deviceName.isBlank()) {
// if no name is set, the dSID will be used as name
deviceName = device.getDSID().getValue();
}

View File

@@ -20,9 +20,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.handler.BridgeHandler;
import org.openhab.binding.digitalstrom.internal.handler.ZoneTemperatureControlHandler;
import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
@@ -103,7 +103,7 @@ public class ZoneTemperatureControlDiscoveryService extends AbstractDiscoverySer
Map<String, Object> properties = new HashMap<>();
properties.put(DigitalSTROMBindingConstants.ZONE_ID, tempControlStatus.getZoneID());
String zoneName = tempControlStatus.getZoneName();
if (StringUtils.isBlank(zoneName)) {
if (zoneName == null || zoneName.isBlank()) {
zoneName = tempControlStatus.getZoneID().toString();
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)

View File

@@ -25,7 +25,6 @@ import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.TemperatureControlStatus;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
@@ -198,9 +197,10 @@ public class BridgeHandler extends BaseBridgeHandler
if (versions != null) {
properties.putAll(versions);
}
if (StringUtils.isBlank(getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT))
&& StringUtils.isNotBlank(config.getCert())) {
properties.put(DigitalSTROMBindingConstants.SERVER_CERT, config.getCert());
String certProperty = getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT);
String certConfig = config.getCert();
if ((certProperty == null || certProperty.isBlank()) && (certConfig != null && !certConfig.isBlank())) {
properties.put(DigitalSTROMBindingConstants.SERVER_CERT, certConfig);
}
logger.debug("update properties");
updateProperties(properties);
@@ -235,8 +235,12 @@ public class BridgeHandler extends BaseBridgeHandler
}
private boolean checkLoginConfig(Config config) {
if ((StringUtils.isNotBlank(config.getUserName()) && StringUtils.isNotBlank(config.getPassword()))
|| StringUtils.isNotBlank(config.getAppToken())) {
String userName = config.getUserName();
String password = config.getPassword();
String appToken = config.getAppToken();
if (((userName != null && !userName.isBlank()) && (password != null && !password.isBlank()))
|| (appToken != null && !appToken.isBlank())) {
return true;
}
onConnectionStateChange(CONNECTION_LOST, NO_USER_PASSWORD);
@@ -296,8 +300,9 @@ public class BridgeHandler extends BaseBridgeHandler
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, excText + " have to be a number.");
return null;
}
if (StringUtils.isNotBlank(getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT))) {
config.setCert(getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT));
String servertCert = getThing().getProperties().get(DigitalSTROMBindingConstants.SERVER_CERT);
if (servertCert != null && !servertCert.isBlank()) {
config.setCert(servertCert);
}
return config;
}
@@ -307,8 +312,9 @@ public class BridgeHandler extends BaseBridgeHandler
this.config = new Config();
}
// load and check connection and authorization data
if (StringUtils.isNotBlank((String) thingConfig.get(HOST))) {
config.setHost(thingConfig.get(HOST).toString());
String host = (String) thingConfig.get(HOST);
if (host != null && !host.isBlank()) {
config.setHost(host);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"The connection to the digitalSTROM-Server can't established, because the host address is missing. Please set the host address.");

View File

@@ -16,7 +16,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.lib.listener.DeviceStatusListener;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Circuit;
@@ -77,8 +76,8 @@ public class CircuitHandler extends BaseThingHandler implements DeviceStatusList
@Override
public void initialize() {
logger.debug("Initializing CircuitHandler.");
if (StringUtils.isNotBlank((String) getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID))) {
dSID = getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID).toString();
dSID = (String) getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID);
if (dSID != null && !dSID.isBlank()) {
final Bridge bridge = getBridge();
if (bridge != null) {
bridgeStatusChanged(bridge.getStatusInfo());

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.lib.GeneralLibConstance;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
@@ -108,8 +107,8 @@ public class DeviceHandler extends BaseThingHandler implements DeviceStatusListe
@Override
public void initialize() {
logger.debug("Initializing DeviceHandler.");
if (StringUtils.isNotBlank((String) getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID))) {
dSID = getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID).toString();
dSID = (String) getConfig().get(DigitalSTROMBindingConstants.DEVICE_DSID);
if (dSID != null && !dSID.isBlank()) {
final Bridge bridge = getBridge();
if (bridge != null) {
bridgeStatusChanged(bridge.getStatusInfo());

View File

@@ -14,7 +14,6 @@ package org.openhab.binding.digitalstrom.internal.lib.manager.impl;
import java.net.HttpURLConnection;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
import org.openhab.binding.digitalstrom.internal.lib.listener.ConnectionListener;
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
@@ -286,8 +285,9 @@ public class ConnectionManagerImpl implements ConnectionManager {
@Override
public String getNewSessionToken() {
if (this.genAppToken) {
if (StringUtils.isNotBlank(config.getAppToken())) {
sessionToken = this.digitalSTROMClient.loginApplication(config.getAppToken());
String token = config.getAppToken();
if (token != null && !token.isBlank()) {
sessionToken = this.digitalSTROMClient.loginApplication(token);
} else if (codeIsAuthentificationFaild()) {
onNotAuthenticated();
}
@@ -379,8 +379,9 @@ public class ConnectionManagerImpl implements ConnectionManager {
private void onNotAuthenticated() {
String applicationToken = null;
boolean isAuthenticated = false;
if (StringUtils.isNotBlank(config.getAppToken())) {
sessionToken = digitalSTROMClient.loginApplication(config.getAppToken());
String token = config.getAppToken();
if (token != null && !token.isBlank()) {
sessionToken = digitalSTROMClient.loginApplication(token);
if (sessionToken != null) {
isAuthenticated = true;
} else {
@@ -425,7 +426,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
logger.debug(
"no application-token for application {} found, generate a application-token {}",
config.getApplicationName(), applicationToken);
if (StringUtils.isNotBlank(applicationToken)) {
if (applicationToken != null && !applicationToken.isBlank()) {
// enable applicationToken
if (!digitalSTROMClient.enableApplicationToken(applicationToken,
digitalSTROMClient.login(config.getUserName(), config.getPassword()))) {
@@ -464,10 +465,9 @@ public class ConnectionManagerImpl implements ConnectionManager {
}
private boolean checkUserPassword() {
if (StringUtils.isNotBlank(config.getUserName()) && StringUtils.isNotBlank(config.getPassword())) {
return true;
}
return false;
String userName = config.getUserName();
String password = config.getPassword();
return userName != null && !userName.isBlank() && password != null && !password.isBlank();
}
/**
@@ -509,8 +509,9 @@ public class ConnectionManagerImpl implements ConnectionManager {
@Override
public boolean removeApplicationToken() {
if (StringUtils.isNotBlank(config.getAppToken())) {
return digitalSTROMClient.revokeToken(config.getAppToken(), null);
String token = config.getAppToken();
if (token != null && !token.isBlank()) {
return digitalSTROMClient.revokeToken(token, null);
}
return true;
}

View File

@@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.lib.GeneralLibConstance;
import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseSensorValues;
import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl.AssignedSensors;
@@ -134,12 +133,13 @@ public class DsAPIImpl implements DsAPI {
}
private boolean checkRequiredZone(Integer zoneID, String zoneName) {
return zoneID != null && zoneID > -1 || StringUtils.isNotBlank(zoneName);
return zoneID != null && zoneID > -1 || (zoneName != null && !zoneName.isBlank());
}
private boolean checkRequiredDevice(DSID dsid, String dSUID, String name) {
return StringUtils.isNotBlank(SimpleRequestBuilder.objectToString(dsid)) || StringUtils.isNotBlank(name)
|| StringUtils.isNotBlank(dSUID);
String objectString = SimpleRequestBuilder.objectToString(dsid);
return (objectString != null && !objectString.isBlank()) || (name != null && !name.isBlank())
|| (dSUID != null && !dSUID.isBlank());
}
@Override
@@ -411,7 +411,7 @@ public class DsAPIImpl implements DsAPI {
@Override
public boolean subscribeEvent(String token, String name, Integer subscriptionID, int connectionTimeout,
int readTimeout) {
if (StringUtils.isNotBlank(name) && SimpleRequestBuilder.objectToString(subscriptionID) != null) {
if ((name != null && !name.isBlank()) && SimpleRequestBuilder.objectToString(subscriptionID) != null) {
String response;
response = transport.execute(
SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.EVENT).addFunction(FunctionKeys.SUBSCRIBE)
@@ -428,7 +428,7 @@ public class DsAPIImpl implements DsAPI {
@Override
public boolean unsubscribeEvent(String token, String name, Integer subscriptionID, int connectionTimeout,
int readTimeout) {
if (StringUtils.isNotBlank(name) && SimpleRequestBuilder.objectToString(subscriptionID) != null) {
if (name != null && !name.isBlank() && SimpleRequestBuilder.objectToString(subscriptionID) != null) {
String response;
response = transport.execute(
SimpleRequestBuilder.buildNewJsonRequest(ClassKeys.EVENT).addFunction(FunctionKeys.UNSUBSCRIBE)
@@ -586,7 +586,7 @@ public class DsAPIImpl implements DsAPI {
@Override
public String loginApplication(String loginToken) {
if (StringUtils.isNotBlank(loginToken)) {
if (loginToken != null && !loginToken.isBlank()) {
String response = transport.execute(SimpleRequestBuilder.buildNewRequest(InterfaceKeys.JSON)
.addRequestClass(ClassKeys.SYSTEM).addFunction(FunctionKeys.LOGIN_APPLICATION)
.addParameter(ParameterKeys.LOGIN_TOKEN, loginToken).buildRequestString());

View File

@@ -43,7 +43,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
@@ -194,13 +194,14 @@ public class HttpTransportImpl implements HttpTransport {
if (config != null) {
cert = config.getCert();
logger.debug("generate SSLcontext from config cert");
if (StringUtils.isNotBlank(cert)) {
if (cert != null && !cert.isBlank()) {
sslSocketFactory = generateSSLContextFromPEMCertString(cert);
} else {
if (StringUtils.isNotBlank(config.getTrustCertPath())) {
String trustCertPath = config.getTrustCertPath();
if (trustCertPath != null && !trustCertPath.isBlank()) {
logger.debug("generate SSLcontext from config cert path");
cert = readPEMCertificateStringFromFile(config.getTrustCertPath());
if (StringUtils.isNotBlank(cert)) {
cert = readPEMCertificateStringFromFile(trustCertPath);
if (cert != null && !cert.isBlank()) {
sslSocketFactory = generateSSLContextFromPEMCertString(cert);
}
} else {
@@ -355,7 +356,7 @@ public class HttpTransportImpl implements HttpTransport {
private HttpsURLConnection getConnection(String request, int connectTimeout, int readTimeout) throws IOException {
String correctedRequest = request;
if (StringUtils.isNotBlank(correctedRequest)) {
if (correctedRequest != null && !correctedRequest.isBlank()) {
correctedRequest = fixRequest(correctedRequest);
URL url = new URL(this.uri + correctedRequest);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
@@ -415,7 +416,7 @@ public class HttpTransportImpl implements HttpTransport {
}
private String readPEMCertificateStringFromFile(String path) {
if (StringUtils.isBlank(path)) {
if (path == null || path.isBlank()) {
logger.error("Path is empty.");
} else {
File dssCert = new File(path);
@@ -446,9 +447,9 @@ public class HttpTransportImpl implements HttpTransport {
@Override
public String writePEMCertFile(String path) {
String correctedPath = StringUtils.trimToEmpty(path);
String correctedPath = path == null ? "" : path.trim();
File certFilePath;
if (StringUtils.isNotBlank(correctedPath)) {
if (!correctedPath.isBlank()) {
certFilePath = new File(correctedPath);
boolean pathExists = certFilePath.exists();
if (!pathExists) {
@@ -485,7 +486,7 @@ public class HttpTransportImpl implements HttpTransport {
}
private SSLSocketFactory generateSSLContextFromPEMCertString(String pemCert) {
if (StringUtils.isNotBlank(pemCert) && pemCert.startsWith(BEGIN_CERT)) {
if (pemCert != null && !pemCert.isBlank() && pemCert.startsWith(BEGIN_CERT)) {
try {
InputStream certInputStream = IOUtils.toInputStream(pemCert);
final X509Certificate trustedCert = (X509Certificate) CertificateFactory.getInstance("X.509")

View File

@@ -15,7 +15,6 @@ package org.openhab.binding.digitalstrom.internal.lib.serverconnection.simpledsr
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.lang.NullArgumentException;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.simpledsrequestbuilder.constants.ExeptionConstants;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.simpledsrequestbuilder.constants.InterfaceKeys;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.simpledsrequestbuilder.constants.ParameterKeys;
@@ -61,7 +60,7 @@ public class SimpleRequestBuilder {
* @return simpleRequestBuilder with chosen interface
* @throws NullArgumentException if the interfaceKey is null
*/
public static SimpleRequestBuilder buildNewRequest(String interfaceKey) throws NullArgumentException {
public static SimpleRequestBuilder buildNewRequest(String interfaceKey) throws IllegalArgumentException {
if (builder == null) {
builder = new SimpleRequestBuilder();
}
@@ -78,14 +77,13 @@ public class SimpleRequestBuilder {
* @throws IllegalArgumentException if a requestClass is already chosen
* @throws NullArgumentException if the requestClassKey is null
*/
public static SimpleRequestBuilder buildNewJsonRequest(String requestClassKey)
throws NullArgumentException, IllegalArgumentException {
public static SimpleRequestBuilder buildNewJsonRequest(String requestClassKey) throws IllegalArgumentException {
return buildNewRequest(InterfaceKeys.JSON).addRequestClass(requestClassKey);
}
private SimpleRequestBuilder buildNewRequestInt(String interfaceKey) {
if (interfaceKey == null) {
throw new NullArgumentException("interfaceKey");
throw new IllegalArgumentException("interfaceKey is null");
}
request = "/" + interfaceKey + "/";
classIsChosen = false;
@@ -102,8 +100,7 @@ public class SimpleRequestBuilder {
* @throws IllegalArgumentException if a requestClass is already chosen
* @throws NullArgumentException if the requestClassKey is null
*/
public SimpleRequestBuilder addRequestClass(String requestClassKey)
throws IllegalArgumentException, NullArgumentException {
public SimpleRequestBuilder addRequestClass(String requestClassKey) throws IllegalArgumentException {
return builder.addRequestClassInt(requestClassKey);
}
@@ -115,7 +112,7 @@ public class SimpleRequestBuilder {
if (!classIsChosen) {
throw new IllegalArgumentException(ExeptionConstants.CLASS_ALREADY_ADDED);
} else {
throw new NullArgumentException("requestClassKey");
throw new IllegalArgumentException("requestClassKey is null");
}
}
return this;
@@ -129,7 +126,7 @@ public class SimpleRequestBuilder {
* @throws IllegalArgumentException if a function is already chosen
* @throws NullArgumentException if the functionKey is null
*/
public SimpleRequestBuilder addFunction(String functionKey) throws IllegalArgumentException, NullArgumentException {
public SimpleRequestBuilder addFunction(String functionKey) throws IllegalArgumentException {
return builder.addFunctionInt(functionKey);
}
@@ -142,7 +139,7 @@ public class SimpleRequestBuilder {
functionIsChosen = true;
request = request + functionKey;
} else {
throw new NullArgumentException("functionKey");
throw new IllegalArgumentException("functionKey is null");
}
} else {
throw new IllegalArgumentException(ExeptionConstants.FUNCTION_ALLREADY_ADDED);
@@ -160,7 +157,7 @@ public class SimpleRequestBuilder {
* @throws NullArgumentException if the parameterKey is null
*/
public SimpleRequestBuilder addParameter(String parameterKey, String parameterValue)
throws IllegalArgumentException, NullArgumentException {
throws IllegalArgumentException {
return builder.addParameterInt(parameterKey, parameterValue);
}
@@ -175,7 +172,7 @@ public class SimpleRequestBuilder {
* @throws NullArgumentException if the parameterKey is null
*/
public SimpleRequestBuilder addDefaultZoneParameter(String sessionToken, Integer zoneID, String zoneName)
throws IllegalArgumentException, NullArgumentException {
throws IllegalArgumentException {
return addParameter(ParameterKeys.TOKEN, sessionToken).addParameter(ParameterKeys.ID, objectToString(zoneID))
.addParameter(ParameterKeys.NAME, zoneName);
}
@@ -191,7 +188,7 @@ public class SimpleRequestBuilder {
* @throws NullArgumentException if the parameterKey is null
*/
public SimpleRequestBuilder addDefaultGroupParameter(String sessionToken, Short groupID, String groupName)
throws IllegalArgumentException, NullArgumentException {
throws IllegalArgumentException {
return addParameter(ParameterKeys.TOKEN, sessionToken)
.addParameter(ParameterKeys.GROUP_ID, objectToString(groupID))
.addParameter(ParameterKeys.GROUP_NAME, groupName);
@@ -210,7 +207,7 @@ public class SimpleRequestBuilder {
* @throws NullArgumentException if the parameterKey is null
*/
public SimpleRequestBuilder addDefaultZoneGroupParameter(String sessionToken, Integer zoneID, String zoneName,
Short groupID, String groupName) throws IllegalArgumentException, NullArgumentException {
Short groupID, String groupName) throws IllegalArgumentException {
return addDefaultZoneParameter(sessionToken, zoneID, zoneName)
.addParameter(ParameterKeys.GROUP_ID, objectToString(groupID))
.addParameter(ParameterKeys.GROUP_NAME, groupName);
@@ -228,7 +225,7 @@ public class SimpleRequestBuilder {
* @throws NullArgumentException if the parameterKey is null
*/
public SimpleRequestBuilder addDefaultDeviceParameter(String sessionToken, DSID dsid, String dSUID, String name)
throws IllegalArgumentException, NullArgumentException {
throws IllegalArgumentException {
return addParameter(ParameterKeys.TOKEN, sessionToken).addParameter(ParameterKeys.DSID, objectToString(dsid))
.addParameter(ParameterKeys.DSUID, dSUID).addParameter(ParameterKeys.NAME, name);
}
@@ -236,7 +233,7 @@ public class SimpleRequestBuilder {
private SimpleRequestBuilder addParameterInt(String parameterKey, String parameterValue) {
if (allRight()) {
if (parameterKey == null) {
throw new NullArgumentException("parameterKey");
throw new IllegalArgumentException("parameterKey is null");
}
if (parameterValue != null) {
if (!parameterIsAdded) {

View File

@@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.DigitalSTROMBindingConstants;
import org.openhab.binding.digitalstrom.internal.lib.GeneralLibConstance;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
@@ -1695,7 +1694,7 @@ public class DeviceImpl extends AbstractGeneralDeviceInformations implements Dev
short sceneID = Short.parseShort((String) key
.subSequence(DigitalSTROMBindingConstants.DEVICE_SCENE.length(), key.length()));
sceneSave = propertries.get(key);
if (StringUtils.isNotBlank(sceneSave)) {
if (sceneSave != null && !sceneSave.isBlank()) {
logger.debug("Find saved scene configuration for device with dSID {} and sceneID {}", dsid,
key);
String[] sceneParm = sceneSave.replace(" ", "").split(",");

View File

@@ -16,7 +16,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.openhab.binding.digitalstrom.internal.lib.listener.SceneStatusListener;
import org.openhab.binding.digitalstrom.internal.lib.structure.devices.Device;
import org.openhab.binding.digitalstrom.internal.lib.structure.scene.constants.SceneTypes;
@@ -71,7 +70,7 @@ public class InternalScene {
this.zoneID = zoneID;
}
this.internalSceneID = this.zoneID + "-" + this.groupID + "-" + this.sceneID;
if (StringUtils.isBlank(sceneName)) {
if (sceneName == null || sceneName.isBlank()) {
this.sceneName = this.internalSceneID;
} else {
this.sceneName = sceneName;

View File

@@ -13,8 +13,9 @@
package org.openhab.binding.digitalstrom.internal.providers;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.i18n.TranslationProvider;
import org.osgi.framework.Bundle;
import org.osgi.service.component.ComponentContext;
@@ -132,6 +133,9 @@ public abstract class BaseDsI18n {
* @return key
*/
public static String buildIdentifier(Object... parts) {
return StringUtils.join(parts, SEPERATOR).toLowerCase();
return Stream.of(parts) //
.map(Object::toString) //
.map(String::toLowerCase) //
.collect(Collectors.joining(SEPERATOR));
}
}