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

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.action;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.Item;
import org.openhab.core.items.events.ItemCommandEvent;
@@ -42,7 +41,8 @@ public class SetModeAction extends Action {
if (device.getType() != DeviceType.THERMOSTAT) {
return false;
}
return StringUtils.isNotBlank(device.getLinks().get("curmode"));
String curmode = device.getLinks().get("curmode");
return curmode != null && !curmode.isBlank();
}
@Override

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.action;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.items.Item;
import org.openhab.core.items.events.ItemCommandEvent;
@@ -39,7 +38,8 @@ public class StopShutterAction extends Action {
@Override
public boolean supports(AbstractDevice device, Item item) {
return device.getType() == DeviceType.SHUTTER && StringUtils.isNotBlank(device.getLinks().get("stopper"));
String stopper = device.getLinks().get("stopper");
return device.getType() == DeviceType.SHUTTER && stopper != null && !stopper.isBlank();
}
@Override

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.model.device;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.State;
@@ -49,7 +48,7 @@ public class ElectricityDevice extends AbstractNumericValueDevice {
public void stateUpdated(Item item, State newState) {
super.stateUpdated(item, newState);
DecimalType value = (DecimalType) item.getStateAs(DecimalType.class);
DecimalType value = item.getStateAs(DecimalType.class);
if (getLinks().containsKey(LINK_WATTS) || getUnit().equalsIgnoreCase(LINK_KWH)) {
addParam(new NumericValueParam(ParamType.KWH, getUnit(), value));
@@ -93,7 +92,8 @@ public class ElectricityDevice extends AbstractNumericValueDevice {
}
NumericValueParam wattsParam = new NumericValueParam(ParamType.WATTS, valueParam.getUnit(), null);
if (StringUtils.isEmpty(wattsParam.getUnit())) {
String unit = wattsParam.getUnit();
if (unit == null || unit.isEmpty()) {
wattsParam.setUnit("W");
}
wattsParam.setValue(valueParam.getValue());
@@ -108,7 +108,8 @@ public class ElectricityDevice extends AbstractNumericValueDevice {
}
NumericValueParam kwhParam = new NumericValueParam(ParamType.KWH, valueParam.getUnit(), null);
if (StringUtils.isEmpty(kwhParam.getUnit())) {
String unit = kwhParam.getUnit();
if (unit == null || unit.isEmpty()) {
kwhParam.setUnit("KWh");
}
kwhParam.setValue(valueParam.getValue());

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.model.device;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.State;
@@ -54,7 +53,8 @@ public class RainDevice extends AbstractNumericValueDevice {
}
NumericValueParam accumParam = new NumericValueParam(ParamType.ACCUMULATION, valueParam.getUnit(), null);
if (StringUtils.isEmpty(accumParam.getUnit())) {
String unit = accumParam.getUnit();
if (unit == null || unit.isBlank()) {
accumParam.setUnit("mm");
}
@@ -67,7 +67,7 @@ public class RainDevice extends AbstractNumericValueDevice {
public void stateUpdated(Item item, State newState) {
super.stateUpdated(item, newState);
DecimalType value = (DecimalType) item.getStateAs(DecimalType.class);
DecimalType value = item.getStateAs(DecimalType.class);
addParam(new NumericValueParam(ParamType.RAIN_VALUE, getUnit(), value));
}
}

View File

@@ -14,7 +14,7 @@ package org.openhab.io.imperihome.internal.model.device;
import java.math.BigDecimal;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.PercentType;

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.model.device;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
@@ -44,17 +43,17 @@ public class TrippableDevice extends AbstractDevice {
boolean tripped = false;
if (item.getStateAs(OpenClosedType.class) != null) {
OpenClosedType state = (OpenClosedType) item.getStateAs(OpenClosedType.class);
OpenClosedType state = item.getStateAs(OpenClosedType.class);
tripped = state == OpenClosedType.CLOSED;
} else if (item.getStateAs(OnOffType.class) != null) {
OnOffType state = (OnOffType) item.getStateAs(OnOffType.class);
OnOffType state = item.getStateAs(OnOffType.class);
tripped = state == OnOffType.ON;
} else if (item.getStateAs(DecimalType.class) != null) {
DecimalType state = (DecimalType) item.getStateAs(DecimalType.class);
tripped = state.intValue() != 0;
DecimalType state = item.getStateAs(DecimalType.class);
tripped = state != null && state.intValue() != 0;
} else if (item.getStateAs(StringType.class) != null) {
StringType state = (StringType) item.getStateAs(StringType.class);
tripped = StringUtils.isNotBlank(state.toString()) && !state.toString().trim().equals("ok");
StringType state = item.getStateAs(StringType.class);
tripped = state != null && !state.toString().isBlank() && !state.toString().trim().equals("ok");
} else {
logger.debug("Can't interpret state {} as tripped status", item.getState());
}

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.io.imperihome.internal.model.device;
import org.apache.commons.lang.StringUtils;
import org.openhab.core.items.Item;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.types.State;
@@ -54,7 +53,8 @@ public class WindDevice extends AbstractNumericValueDevice {
}
NumericValueParam dirParam = new NumericValueParam(ParamType.DIRECTION, valueParam.getUnit(), null);
if (StringUtils.isEmpty(dirParam.getUnit())) {
String unit = dirParam.getUnit();
if (unit == null || unit.isEmpty()) {
dirParam.setUnit("Degrees");
}
@@ -67,7 +67,7 @@ public class WindDevice extends AbstractNumericValueDevice {
public void stateUpdated(Item item, State newState) {
super.stateUpdated(item, newState);
DecimalType value = (DecimalType) item.getStateAs(DecimalType.class);
DecimalType value = item.getStateAs(DecimalType.class);
addParam(new NumericValueParam(ParamType.SPEED, getUnit(), value));
}
}

View File

@@ -20,8 +20,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.ItemRegistryChangeListener;
@@ -144,11 +143,12 @@ public class ItemProcessor implements ItemRegistryChangeListener {
String icon = issTags.get(TagType.ICON).get(0);
if (!icon.toLowerCase().startsWith("http")) {
if (StringUtils.isEmpty(config.getRootUrl())) {
String rootUrl = config.getRootUrl();
if (rootUrl == null || rootUrl.isEmpty()) {
logger.error("Can't set icon; 'openhab.rootUrl' not set in configuration");
return;
}
icon = config.getRootUrl() + "icon/" + icon;
icon = rootUrl + "icon/" + icon;
}
device.addParam(new DeviceParam(ParamType.DEFAULT_ICON, icon));
@@ -214,8 +214,9 @@ public class ItemProcessor implements ItemRegistryChangeListener {
return issTags.get(TagType.LABEL).get(0);
}
if (StringUtils.isNotBlank(item.getLabel())) {
String label = item.getLabel().trim();
String label = item.getLabel();
if (label != null && !label.isBlank()) {
label = label.trim();
if (label.matches("\\[.*\\]$")) {
label = label.substring(0, label.indexOf('['));
}