Remove org.apache.common (#14434)
Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
c12715bda7
commit
46a73befae
@ -32,10 +32,6 @@ import javax.measure.Unit;
|
|||||||
import javax.measure.UnitConverter;
|
import javax.measure.UnitConverter;
|
||||||
import javax.measure.quantity.Temperature;
|
import javax.measure.quantity.Temperature;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.sensibo.internal.CallbackChannelsTypeProvider;
|
import org.openhab.binding.sensibo.internal.CallbackChannelsTypeProvider;
|
||||||
@ -44,6 +40,7 @@ import org.openhab.binding.sensibo.internal.config.SensiboSkyConfiguration;
|
|||||||
import org.openhab.binding.sensibo.internal.dto.poddetails.TemperatureDTO;
|
import org.openhab.binding.sensibo.internal.dto.poddetails.TemperatureDTO;
|
||||||
import org.openhab.binding.sensibo.internal.model.SensiboModel;
|
import org.openhab.binding.sensibo.internal.model.SensiboModel;
|
||||||
import org.openhab.binding.sensibo.internal.model.SensiboSky;
|
import org.openhab.binding.sensibo.internal.model.SensiboSky;
|
||||||
|
import org.openhab.binding.sensibo.internal.util.StringUtils;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
import org.openhab.core.library.types.DecimalType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
@ -99,17 +96,17 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
|
|||||||
|
|
||||||
private static String beautify(final String camelCaseWording) {
|
private static String beautify(final String camelCaseWording) {
|
||||||
final StringBuilder b = new StringBuilder();
|
final StringBuilder b = new StringBuilder();
|
||||||
for (final String s : StringUtils.splitByCharacterTypeCamelCase(camelCaseWording)) {
|
for (final String s : StringUtils.splitByCharacterType(camelCaseWording)) {
|
||||||
b.append(" ");
|
b.append(" ");
|
||||||
b.append(s);
|
b.append(s);
|
||||||
}
|
}
|
||||||
final StringBuilder bs = new StringBuilder();
|
final StringBuilder bs = new StringBuilder();
|
||||||
for (final String t : StringUtils.splitByWholeSeparator(b.toString(), " _")) {
|
for (final String t : b.toString().split("[ ][_]")) {
|
||||||
bs.append(" ");
|
bs.append(" ");
|
||||||
bs.append(t);
|
bs.append(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
return WordUtils.capitalizeFully(bs.toString()).trim();
|
return StringUtils.capitalizeFully(bs.toString()).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMacAddress() {
|
private String getMacAddress() {
|
||||||
@ -429,24 +426,22 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
|
|||||||
if (!validTemperatures.validValues.contains(rawValue.intValue())) {
|
if (!validTemperatures.validValues.contains(rawValue.intValue())) {
|
||||||
stateChange.addError(String.format(
|
stateChange.addError(String.format(
|
||||||
"Cannot change targetTemperature to '%d', valid targetTemperatures are one of %s",
|
"Cannot change targetTemperature to '%d', valid targetTemperatures are one of %s",
|
||||||
rawValue.intValue(), ToStringBuilder.reflectionToString(
|
rawValue.intValue(),
|
||||||
validTemperatures.validValues.toArray(), ToStringStyle.SIMPLE_STYLE)));
|
String.join(",", validTemperatures.validValues.stream().map(Object::toString)
|
||||||
|
.collect(Collectors.toUnmodifiableList()).toArray(new String[0]))));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MODE_PROPERTY:
|
case MODE_PROPERTY:
|
||||||
if (!sensiboSky.getRemoteCapabilities().containsKey(newPropertyValue)) {
|
if (!sensiboSky.getRemoteCapabilities().containsKey(newPropertyValue)) {
|
||||||
stateChange.addError(
|
stateChange.addError(String.format("Cannot change mode to %s, valid modes are %s",
|
||||||
String.format("Cannot change mode to %s, valid modes are %s", newPropertyValue,
|
newPropertyValue, String.join(",", sensiboSky.getRemoteCapabilities().keySet())));
|
||||||
ToStringBuilder.reflectionToString(
|
|
||||||
sensiboSky.getRemoteCapabilities().keySet().toArray(),
|
|
||||||
ToStringStyle.SIMPLE_STYLE)));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FAN_LEVEL_PROPERTY:
|
case FAN_LEVEL_PROPERTY:
|
||||||
if (!currentModeCapabilities.fanLevels.contains(newPropertyValue)) {
|
if (!currentModeCapabilities.fanLevels.contains(newPropertyValue)) {
|
||||||
stateChange.addError(String.format("Cannot change fanLevel to %s, valid fanLevels are %s",
|
stateChange.addError(
|
||||||
newPropertyValue, ToStringBuilder.reflectionToString(
|
String.format("Cannot change fanLevel to %s, valid fanLevels are %s", newPropertyValue,
|
||||||
currentModeCapabilities.fanLevels.toArray(), ToStringStyle.SIMPLE_STYLE)));
|
String.join(",", currentModeCapabilities.fanLevels.toArray(new String[0]))));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MASTER_SWITCH_PROPERTY:
|
case MASTER_SWITCH_PROPERTY:
|
||||||
@ -454,9 +449,9 @@ public class SensiboSkyHandler extends SensiboBaseThingHandler implements Channe
|
|||||||
break;
|
break;
|
||||||
case SWING_PROPERTY:
|
case SWING_PROPERTY:
|
||||||
if (!currentModeCapabilities.swingModes.contains(newPropertyValue)) {
|
if (!currentModeCapabilities.swingModes.contains(newPropertyValue)) {
|
||||||
stateChange.addError(String.format("Cannot change swing to %s, valid swings are %s",
|
stateChange.addError(
|
||||||
newPropertyValue, ToStringBuilder.reflectionToString(
|
String.format("Cannot change swing to %s, valid swings are %s", newPropertyValue,
|
||||||
currentModeCapabilities.swingModes.toArray(), ToStringStyle.SIMPLE_STYLE)));
|
String.join(",", currentModeCapabilities.swingModes.toArray(new String[0]))));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.sensibo.internal.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link StringUtils} class defines some static string utility methods
|
||||||
|
*
|
||||||
|
* @author Leo Siepel - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class StringUtils {
|
||||||
|
|
||||||
|
public static String capitalizeFully(String input) {
|
||||||
|
final String delimiter = "_";
|
||||||
|
String capitalizedFully = "";
|
||||||
|
for (String str : input.split(delimiter)) {
|
||||||
|
String properlyCapitalized = "";
|
||||||
|
if (str.length() > 0) {
|
||||||
|
properlyCapitalized = str.substring(0, 1).toUpperCase();
|
||||||
|
}
|
||||||
|
if (str.length() > 1) {
|
||||||
|
properlyCapitalized = str.substring(1).toLowerCase();
|
||||||
|
}
|
||||||
|
capitalizedFully = capitalizedFully + properlyCapitalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
return capitalizedFully;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] splitByCharacterType(@Nullable String input) {
|
||||||
|
if (input == null) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
if (input.isBlank()) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
List<String> cache = new ArrayList<>();
|
||||||
|
char[] inputAsCharArray = input.toCharArray();
|
||||||
|
int prevType = Character.getType(inputAsCharArray[0]);
|
||||||
|
int prevTypeStart = 0;
|
||||||
|
for (int i = prevTypeStart + 1; i < inputAsCharArray.length; i++) {
|
||||||
|
int curType = Character.getType(inputAsCharArray[i]);
|
||||||
|
if (prevType == curType) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (curType == Character.LOWERCASE_LETTER && prevType == Character.UPPERCASE_LETTER) {
|
||||||
|
int tmpStart = i - 1;
|
||||||
|
if (tmpStart != prevTypeStart) {
|
||||||
|
cache.add(new String(inputAsCharArray, prevTypeStart, tmpStart - prevTypeStart));
|
||||||
|
prevTypeStart = tmpStart;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cache.add(new String(inputAsCharArray, prevTypeStart, i - prevTypeStart));
|
||||||
|
prevTypeStart = i;
|
||||||
|
}
|
||||||
|
prevType = curType;
|
||||||
|
}
|
||||||
|
cache.add(new String(inputAsCharArray, prevTypeStart, inputAsCharArray.length - prevTypeStart));
|
||||||
|
return cache.toArray(String[]::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.openhab.binding.sensibo.internal.util;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link StringUtils} class defines some static string utility methods
|
||||||
|
*
|
||||||
|
* @author Leo Siepel - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class StringUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void splitByCharacterType() {
|
||||||
|
assertArrayEquals(new String[0], StringUtils.splitByCharacterType(null));
|
||||||
|
assertArrayEquals(new String[0], StringUtils.splitByCharacterType(""));
|
||||||
|
assertArrayEquals(new String[] { "ab", " ", "de", " ", "fg" }, StringUtils.splitByCharacterType("ab de fg"));
|
||||||
|
assertArrayEquals(new String[] { "ab", " ", "de", " ", "fg" },
|
||||||
|
StringUtils.splitByCharacterType("ab de fg"));
|
||||||
|
assertArrayEquals(new String[] { "ab", ":", "cd", ":", "ef" }, StringUtils.splitByCharacterType("ab:cd:ef"));
|
||||||
|
assertArrayEquals(new String[] { "number", "5" }, StringUtils.splitByCharacterType("number5"));
|
||||||
|
assertArrayEquals(new String[] { "foo", "Bar" }, StringUtils.splitByCharacterType("fooBar"));
|
||||||
|
assertArrayEquals(new String[] { "foo", "200", "Bar" }, StringUtils.splitByCharacterType("foo200Bar"));
|
||||||
|
assertArrayEquals(new String[] { "ASF", "Rules" }, StringUtils.splitByCharacterType("ASFRules"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user