*/
package org.openhab.binding.satel.internal.command;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.satel.internal.protocol.SatelMessage;
+import org.openhab.binding.satel.internal.util.StringUtils;
/**
* Base class for all commands that return result code in the response.
super(commandCode, payload);
}
+ /**
+ * Creates new command class instance.
+ *
+ * @param commandCode command code
+ * @param payload command bytes
+ * @param userCode user code
+ */
+ public ControlCommand(byte commandCode, byte[] payload, String userCode) {
+ super(commandCode, appendUserCode(payload, userCode));
+ }
+
@Override
protected boolean isResponseValid(SatelMessage response) {
return true;
}
+ protected static byte[] appendUserCode(byte[] payload, String userCode) {
+ byte[] userCodeBytes = userCodeToBytes(userCode);
+ byte[] result = new byte[userCodeBytes.length + payload.length];
+ System.arraycopy(userCodeBytes, 0, result, 0, userCodeBytes.length);
+ System.arraycopy(payload, 0, result, userCodeBytes.length, payload.length);
+ return result;
+ }
+
protected static byte[] userCodeToBytes(String userCode) {
if (StringUtils.isEmpty(userCode)) {
throw new IllegalArgumentException("User code is empty");
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.satel.internal.event.EventDispatcher;
import org.openhab.binding.satel.internal.event.NewStatesEvent;
*/
public ControlObjectCommand(ControlType controlType, byte[] objects, String userCode,
ScheduledExecutorService scheduler) {
- super(controlType.getControlCommand(), ArrayUtils.addAll(userCodeToBytes(userCode), objects));
+ super(controlType.getControlCommand(), objects, userCode);
this.controlType = controlType;
this.scheduler = scheduler;
}
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
-import org.apache.commons.lang.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* @param userCode code of the user on behalf the control is made
*/
public SetClockCommand(LocalDateTime dateTime, String userCode) {
- super(COMMAND_CODE, ArrayUtils.addAll(userCodeToBytes(userCode), getDateTimeBytes(dateTime)));
+ super(COMMAND_CODE, getDateTimeBytes(dateTime), userCode);
}
private static byte[] getDateTimeBytes(LocalDateTime dateTime) {
import java.util.Collections;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.satel.internal.config.Ethm1Config;
import org.openhab.binding.satel.internal.protocol.Ethm1Module;
import org.openhab.binding.satel.internal.protocol.SatelModule;
+import org.openhab.binding.satel.internal.util.StringUtils;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingStatus;
import java.util.Collections;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.satel.internal.config.IntRSConfig;
import org.openhab.binding.satel.internal.protocol.IntRSModule;
import org.openhab.binding.satel.internal.protocol.SatelModule;
+import org.openhab.binding.satel.internal.util.StringUtils;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.io.transport.serial.SerialPortManager;
import org.openhab.core.thing.Bridge;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.satel.internal.command.NewStatesCommand;
import org.openhab.binding.satel.internal.event.SatelEventListener;
import org.openhab.binding.satel.internal.protocol.SatelModule;
import org.openhab.binding.satel.internal.types.IntegraType;
+import org.openhab.binding.satel.internal.util.StringUtils;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.ThingStatus;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.satel.internal.command.IntegraStateCommand;
import org.openhab.binding.satel.internal.event.IntegraStateEvent;
import org.openhab.binding.satel.internal.event.NewStatesEvent;
import org.openhab.binding.satel.internal.types.StateType;
+import org.openhab.binding.satel.internal.util.StringUtils;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import java.net.SocketTimeoutException;
import java.util.Random;
-import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.satel.internal.util.StringUtils;
import org.openhab.core.util.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
--- /dev/null
+/**
+ * Copyright (c) 2010-2021 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.satel.internal.util;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * Replacement class for Apache's StringUtils.
+ *
+ * @author Krzysztof Goworek - Initial contribution
+ *
+ */
+@NonNullByDefault
+public class StringUtils {
+
+ /**
+ * Checks if a string is empty or null.
+ *
+ * @param str the string to check
+ * @return <code>true</code> if given string is empty or null
+ */
+ public static boolean isEmpty(@Nullable String str) {
+ return str == null || str.isEmpty();
+ }
+
+ /**
+ * Checks if a string is not empty and not null.
+ *
+ * @param str the string to check
+ * @return <code>true</code> if given string is not empty and not null
+ */
+ public static boolean isNotEmpty(@Nullable String str) {
+ return !isEmpty(str);
+ }
+
+ /**
+ * Checks if a string is null or empty or all characters are whitespace.
+ *
+ * @param str the string to check
+ * @return <code>true</code> if given string is blank
+ */
+ public static boolean isBlank(@Nullable String str) {
+ return str == null || str.isBlank();
+ }
+
+ /**
+ * Checks if a string is not null, not empty and contains at least one non-whitespace character.
+ *
+ * @param str the string to check
+ * @return <code>true</code> if given string is not blank
+ */
+ public static boolean isNotBlank(@Nullable String str) {
+ return !isBlank(str);
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2010-2021 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.satel.internal.util;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author Krzysztof Goworek - Initial contribution
+ */
+public class StringUtilsTest {
+
+ @Test
+ public void testIsEmpty() {
+ assertFalse(StringUtils.isEmpty("foobar"));
+ assertFalse(StringUtils.isEmpty(" "));
+ assertTrue(StringUtils.isEmpty(""));
+ assertTrue(StringUtils.isEmpty(null));
+ }
+
+ @Test
+ public void testIsNotEmpty() {
+ assertTrue(StringUtils.isNotEmpty("foobar"));
+ assertTrue(StringUtils.isNotEmpty(" "));
+ assertFalse(StringUtils.isNotEmpty(""));
+ assertFalse(StringUtils.isNotEmpty(null));
+ }
+
+ @Test
+ public void testIsBlank() {
+ assertFalse(StringUtils.isBlank("foobar"));
+ assertTrue(StringUtils.isBlank(" "));
+ assertTrue(StringUtils.isBlank(""));
+ assertTrue(StringUtils.isBlank(null));
+ }
+
+ @Test
+ public void testIsNotBlank() {
+ assertTrue(StringUtils.isNotBlank("foobar"));
+ assertFalse(StringUtils.isNotBlank(" "));
+ assertFalse(StringUtils.isNotBlank(""));
+ assertFalse(StringUtils.isNotBlank(null));
+ }
+}