Skip to content

Commit

Permalink
Replaced org.apache.commons.* dependency, see openhab#7722
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
  • Loading branch information
GerdZanker committed Mar 24, 2023
1 parent 1205492 commit deab5be
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
package org.openhab.binding.boschshc.internal.discovery;

import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
Expand Down Expand Up @@ -217,17 +215,29 @@ protected void addDevice(Device device, String roomName) {
}

private String getNiceName(String name, String roomName) {
// remove "-" from "-IntrusionDetectionSystem-"
String niceName = name.replace("-", "");
// convert "IntrusionDetectionSystem" into "Intrusion Detection System"
// by splitting the CamelCase string into strings and joining the non-empty parts again.
niceName = Arrays.stream(StringUtils.splitByCharacterTypeCamelCase(niceName)).filter(p -> !p.trim().isEmpty())
.collect(Collectors.joining(" "));
// append roomName for "Room Climate Control", because it appears for each thermostat in each room
if (niceName.startsWith("Room Climate Control") && !roomName.isEmpty()) {
niceName = niceName + " " + roomName;
if (!name.startsWith("-"))
return name;

// convert "-IntrusionDetectionSystem-" into "Intrusion Detection System"
// convert "-RoomClimateControl-" into "Room Climate Control myRoomName"
final char[] chars = name.toCharArray();
StringBuilder niceNameBuilder = new StringBuilder(32);
for (int pos = 0; pos < chars.length; pos++) {
// skip "-"
if (chars[pos] == '-') {
continue;
}
// convert "CamelCase" into "Camel Case", skipping the first Uppercase after the "-"
if (pos > 1 && Character.getType(chars[pos]) == Character.UPPERCASE_LETTER) {
niceNameBuilder.append(" ");
}
niceNameBuilder.append(chars[pos]);
}
// append roomName for "Room Climate Control", because it appears for each room with a thermostat
if (!roomName.isEmpty() && niceNameBuilder.toString().startsWith("Room Climate Control")) {
niceNameBuilder.append(" ").append(roomName);
}
return niceName;
return niceNameBuilder.toString();
}

protected @Nullable ThingTypeUID getThingTypeUID(Device device) {
Expand Down

0 comments on commit deab5be

Please sign in to comment.