Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[imperihome] Remove org.apache.common #14441

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

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;
import org.openhab.core.types.State;
import org.openhab.io.imperihome.internal.model.param.DeviceParam;
import org.openhab.io.imperihome.internal.model.param.ParamType;
import org.openhab.io.imperihome.internal.util.StringUtils;

/**
* RGB light device.
Expand Down Expand Up @@ -80,7 +80,7 @@ public void stateUpdated(Item item, State newState) {

private String toHex(int value) {
String hex = Integer.toHexString(value);
return StringUtils.leftPad(hex, 2, '0');
return StringUtils.padLeft(hex, 2, "0");
}

private int convertPercentToByte(PercentType percent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.BooleanUtils;
import org.openhab.core.items.Item;
import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.ItemRegistryChangeListener;
Expand Down Expand Up @@ -58,6 +57,7 @@
import org.openhab.io.imperihome.internal.model.param.DeviceParam;
import org.openhab.io.imperihome.internal.model.param.ParamType;
import org.openhab.io.imperihome.internal.util.DigestUtil;
import org.openhab.io.imperihome.internal.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -227,7 +227,7 @@ private String getLabel(Item item, Map<TagType, List<String>> issTags) {
}

private boolean isInverted(Map<TagType, List<String>> issTags) {
return issTags.containsKey(TagType.INVERT) && BooleanUtils.toBoolean(issTags.get(TagType.INVERT).get(0));
return issTags.containsKey(TagType.INVERT) && StringUtils.toBoolean(issTags.get(TagType.INVERT).get(0));
}

private void setDeviceRoom(AbstractDevice device, Map<TagType, List<String>> issTags) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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.io.imperihome.internal.util;

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 {

/**
* Simple method to create boolean from string.
* 'true', 'on', 'y', 't' or 'yes' (case insensitive) will return true. Otherwise, false is returned.
*/
public static boolean toBoolean(@Nullable String input) {
if (input != null) {
input = input.toLowerCase();
}
return "true".equals(input) || "on".equals(input) || "y".equals(input) || "t".equals(input)
|| "yes".equals(input);
}

public static String padLeft(@Nullable String input, int minSize, String padString) {
if (input == null) {
input = "";
}
return String.format("%" + minSize + "s", input).replace(" ", padString);
}
}